Assessment for programming c++

profileomaralekhmimi
firstname_lastname_cpsc120_seclab6.doc

CPSC 120

Spring 2014

Lab 6

Name _____________________________

Practice Objectives of this Lab:

1. The switch Statement

2. Enumerated Data Types

3. Menu-Driven Programs

4. Validating User Input

Grading:

1. 6.1-6.4 25 points each,

100 points totally

2. Your final complete solution report is due before your lab next week.

To begin

· Log on to your system and create a folder named Lab6 in your work space.

· Start the C++ IDE (Visual Studio) and create a project named Lab6.

Part I (50 points)

LAB 6.1 (25 points) – Using a switch Statement

Step 1: Make a copy of the final, revised color.cpp program in LAB 5.3 and name it switch.cpp. add the switch.cpp program to the project.

Step 2: Replace the if/else if statement that begins on line 20 with a switch statement. Include a final default section to perform the same function the final trailing else does in the if/else if statement. Don’t forget the needed break statements.

Step 3: Compile your program and then test it by running it 5 times, using the same 5 test cases you used in LAB 5.3. You should get the same correct results.

Run Menu choice Current output New output

1 1 ___________________ ___________________

2 2 ___________________ ___________________

3 3 ___________________ ___________________

4 0 ___________________ ___________________

5 99 ___________________ ___________________

Step 4: Copy your final source code and paste here.

Step 5: Recompile the program and run it 5 more times, using the same 5 menu choices shown above. For each run, make a screenshot and paste here.

LAB 6.2 (25 points) – Complete Program: practice foe the switch Statement and Enumerated Data Types

Step 1: Remove switch.cpp from the project and add the areas.cpp program in your Lab6 folder to the project. This file contains just a program shell in which you will write all the programming statements needed to complete the program described below. Here is a copy of the current contents of areas.cpp.

1 // Lab 6 areas.cpp 2 // WRITE A COMMENT BRIEFLY DESCRIBING THE PROGRAM. 3 // PUT YOUR NAME HERE. 4 // INCLUDE ANY NEEDED FILES HERE. 5 using namespace std; 6 7 int main() 8 { 9 // DEFINE THE NAMED CONSTANT PI HERE AND SET ITS VALUE TO 3.14159 10 11 // DECLARE ALL NEEDED VARIABLES HERE. GIVE EACH ONE A DESCRIPTIVE 12 // NAME AND AN APPROPRIATE DATA TYPE. 13 14 // WRITE STATEMENTS HERE TO DISPLAY THE 4 MENU CHOICES. 15 16 // WRITE A STATEMENT HERE TO INPUT THE USER'S MENU CHOICE. 17 18 // USE AN IF/ELSE IF STATEMENT TO OBTAIN ANY NEEDED INPUT INFORMATION 19 // AND COMPUTE AND DISPLAY THE AREA FOR EACH VALID MENU CHOICE. 20 // IF AN INVALID MENU CHOICE WAS ENTERED, AN ERROR MESSAGE SHOULD 21 // BE DISPLAYED. 22 23 return 0; 24 }

Step 2: Design and implement the areas.cpp program so that it correctly meets the program specifications given below.

Specifications:

Create a menu-driven program that finds and displays areas of 3 different objects.

The menu should have the following 4 choices:

1 -- square

2 -- circle

3 -- right triangle

4 -- quit

· If the user selects choice 1, the program should find the area of a square.

· If the user selects choice 2, the program should find the area of a circle.

· If the user selects choice 3, the program should find the area of a right triangle.

· If the user selects choice 4, the program should quit without doing anything.

· If the user selects anything else (i.e., an invalid choice) an appropriate error message should be printed.

Sample Run

Program to calculate areas of objects

1 -- square

2 -- circle

3 -- right triangle

4 -- quit

2

Radius of the circle: 3.0

Area = 28.2743

Step 3: Once you have your program working, run it 4 times, each time testing a different valid menu choice. Then run it a fifth time using an invalid menu choice (such as 0 or 5). Make sure your program works correctly for all cases.

Make 5 screenshots for the five testing cases and paste here.

Step 4: Copy your final source code and paste here.

Part II (50 points)

Please do Programming Challenges in the following way.

1) Pseudocode of your program (20% grading);

2) Your C++ source code (include your name, section number, CSUF email, lab number and date (60% grading);

3) The results gotten (3 Screen Shots) using any 3 testing cases that are reasonable

(20% grading)

LAB 6.3 (25 points) –Programming Challenges of Chapter 4 # 16 The speed of Sound (Page 239)

image1.png

LAB 6.4 (25 points) –Programming Challenges of Chapter 4 # 19 Long-Distance Calls (Page 240)

image2.png

6