COSC 1436 Lab 4 Instructions

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 8

DownloadCOSC 1436 Lab 4 Instructions
Open PDF In BrowserView PDF
COSC 1436 Lab 4 | A. Berrached

Programming Fundamentals I
COSC1436--Fall 2015

Lab 4. Conditional Statements

Objectives:
1. To work with relational and logical operators
2. To work with conditional statements (if. if-else, if-else-if, nested if-else, and switch statements)
3. To practice creating flow charts of conditional statements
4. To practice analyzing code by hand tracing code and/or its flow chart
5. To learn to generate a test data set from problem specifications
6. To practice using flow charts in designing and verifying algorithms with conditional statements.
Make sure to demo your work to your instructor for each task to get credit. You also need to
submit the test data set and flowchart for each task.

Task 1: Working with Conditional Statements--Analysis
Exercise 1.
sheet):

Create a flow chart for the following program (use the back of this page or staple a separate

// This program displays course grade based on the average score
// using the standard grading formula:
// average ≥ 90  A; 80 ≤ average < 90  B; 70 ≤ average < 80  C ;
// 60 ≤ average < 70  D; average < 60  F
// PLACE YOUR NAME HERE
#include 
using namespace std;
int main()
{
float avgScore; // holds the grade average
char grade;
// holds a letter grade
cout << "Input your average:" << endl;
cin >> avgScore;
if (avgScore
grade
if (avgScore
grade
if (avgScore
grade
if (avgScore
grade
else
grade

>=90)
='A';
>= 80)
= 'B';
>= 70)
= 'C';
>= 60)
= 'D';
= 'F';

cout << "Your grade is: " << grade << endl;
system("pause");
return 0;
}

1/8

COSC 1436 Lab 4 | A. Berrached

Exercise 2.
Manually trace your flow chart and/or the code to predict the program output for each of
the following inputs:

Input
55

Expected output

65
75
95

Exercise 3.
Based on your analysis of the above program, list the range of average score values for
each letter grade. Does the program meet its specifications as stated in the documentation (see first
comments lines above program code)?
Grade

Average score range

Exercise 4.
Create a new C++ project in Visual Studio, add a new C++ file and copy the above
program code into it.
Exercise 5.

Test your program and verify your answers to exercises 3 and 4.

Demo your answers to exercise 3 & 4 to your instructor. Submit your flowchart to D2L
Dropbox.

2/8

COSC 1436 Lab 4 | A. Berrached

Task 2: Working with Conditional Statements—Design
In this task you’re to fix the program of the previous task.
Exercise 1.
Based on the program description in its documentation (see few comment lines at begin
of program), create a test data set for verification and testing purposes.

Exercise 2.
Create a flow chart based on the program description. Verify your flowchart with the test
data set.
Exercise 3.
Create a new project (or modify the old one from Task1) and write the code for the
flowchart. Test your program using your test data set.
Demo your answers to exercise 3. Submit your test data set and flowchart to D2L dropbox

3/8

COSC 1436 Lab 4 | A. Berrached

Task 3: If-else-if statements and Logical Operators--Analysis
Exercise 1.

Consider the following program:

// This program illustrates the use of logical operators
// PLACE YOUR NAME HERE
#include 
using namespace std;
int main()
{
char employmentStatus;
float performanceScore, salaryRaise;
cout << "What’s your employment status?" << endl;
cout << "Enter 1 (full-time), 2 (part-time), or 3 (temporary)"
<< endl << endl;
cin >> employmentStatus;
cout << "Now enter your performance score" << endl;
cin >> performanceScore;
if (performanceScore >= 8.0 && employmentStatus == '1')
salaryRaise = 1000.0;
else if (employmentStatus != '1'|| performanceScore >= 6.0)
salaryRaise = 150.0;
else if (employmentStatus == '3')
salaryRaise = 0;
cout << "Your salary raise is: $" << salaryRaise<
using namespace std;
int main()
{
const double ADULT = 40.0, CHILD = 30.0, SENIOR = 15.0; // Club membership monthly costs
int months;
// length of membership
int choice;
cout << "Please select one of the membership options below: " << endl;
cout << '\t'<< "1. Adult Membership"<> choice;
switch( choice ) // This is where the switch statement begins
{
case 1: cout << "\n For how many months? "<< endl;
cin >> months;
cout <<"Your total membership cost is: $"<< months * ADULT << endl;
break;
case 2: cout << "\n For how many months? "<< endl;
cin >> months;
cout <<"Your total membership cost is: $"<< months * CHILD << endl;
break;
case 3: cout << "\n For how many months? "<< endl;
cin >> months;
cout <<"Your total membership cost is: $"<< months * SENIOR <<
endl;
break;
case 4: cout << "No membership was selected....";
cout <<"Good bye!"<
using namespace std;
int main() {
float testScore1, testScore2, testScore3;
cout <<"Enter score for test 1: " << endl;
cin >> testScore1;
cout << "Enter score for test 2: " << endl;
cin >> testScore2;
cout <<"Enter score for test 3: " << endl;
cin >> testScore3;
/*

To BE FILLED

*/

return 0;
}

Exercise 2.
List the possible case scenarios that should be considered and create a test data set.
Example of cases to be considered: test score 1 is the largest; test score 2 is largest, etc. You should
also consider the cases when scores are equal.

Exercise 3.
Write an algorithm using conditional statements to find the largest of three values. Draw a
flowchart of your algorithm and verify it with your test data from previous exercise.
Exercise 4.
Create a project in Visual Studio and fill in the missing code in the program above based
on your algorithm of the previous exercise. Test your program using your test data.

Submit your flowchart and test data set to D2L dropbox. Demo your program. Make sure to
have your test data set ready for the demo.

8/8



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Title                           : COSC 1436 Lab 4
Author                          : A. Berrached
Creator                         : Microsoft® Word 2013
Create Date                     : 2015:09:28 16:40:30-05:00
Modify Date                     : 2015:09:28 16:40:30-05:00
Producer                        : Microsoft® Word 2013
Page Count                      : 8
Language                        : en-US
Tagged PDF                      : Yes
EXIF Metadata provided by EXIF.tools

Navigation menu