C++ Lab: 3A

Mon Sep 15 2025
Updated: Tue Sep 16 2025
Facebook share linkTwitter/X share linkLinkedIn share linkReddit share linkReddit share link

Introduction

In this lab you will practice prompting the user for multiple values, reading the values from the user/keyboard into variables, using if...else statements to compare the values entered by the user and write out the larger of the two. You will then repeat the procedure for two strings. Be sure to read this lab thoroughly, especially the Hand-in Procedure.


Lab

Write a complete program that:

  1. Prompts the user to enter a floating point number then reads a floating point number from the keyboard as a double.

  2. Prompts the user to enter a second floating point number then reads a second floating point number from the keyboard as a double.

  3. Uses an if statement to compare the numbers from (1) and (2) and write out to the display which is bigger.

  4. Prompts the user to enter a string then reads a string from the keyboard.

  5. Prompts the user to enter a second string then reads a second string from the keyboard.

  6. Uses an if statement to compare the strings from (4) and (5) and write out to the display which is bigger.

See the example interactions for prompts and formatting.


Example Program Interaction

An example of an interaction with your program is shown below. When interacted with, your program must produce the exact same results.

Alexs-iMac:lab3a alex$ g++ -Wall -pedantic -Werror main.cpp Alexs-iMac:lab3a alex$ ./a.out Enter a floating point number **7.23 Enter another floating point number **7.22999 You entered 7.23 and 7.22999 The largest is 7.23 Enter a string **abc Enter a second string **abcd You entered "abc" and "abcd" The largest is "abcd"
Alexs-iMac:lab3a alex$ ./a.out Enter a floating point number **8 Enter another floating point number **57 You entered 8 and 57 The largest is 57 Enter a string **Teddy Enter a second string **James You entered "Teddy" and "James" The largest is "Teddy"
Alexs-iMac:lab3a alex$ ./a.out Enter a floating point number **10 Enter another floating point number **10 You entered 10 and 10 The largest is 10 Enter a string **Hello Enter a second string **Hello You entered "Hello" and "Hello" The largest is "Hello"

Submission Instructions

Save: Save your code as main.cpp. Do not ignore this step or save your file(s) with different names.

Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.