1
Lab6-3:
//Yourname Lab6-3.cpp
//Assignment: nested if...else
// Preprocessor directives:
#include <iostream>
using namespace std;
// Named constant definitions (and function declarations):
// Main program:
int main()
{
// Variable declarations:
float percent;
// Function body:
cout << "Enter the percent grade." << endl;
cin >> percent;
cout << endl;
// Add the appropriate if's, elses, and/or else if statements to print
// the appropriate print statements below, given the percent input by the user.
cout << "Your grade is an A." << endl;
cout << "Your grade is a B." << endl;
cout << "Your grade is a C." << endl;
cout << "Your grade is a D." << endl;
cout << "Your grade is an F." << endl;
cout << endl;
return 0;
} // end function main
Lab6-4:
//Assignment: if with Boolean and
// Preprocessor directives:
#include <iostream>
#include <string>
using namespace std;
// Named constant definitions (and function declarations):
// Main program:
int main()
{
// Variable declarations:
int days;
float avg;
string fname;
// Function body:
system ("cls");
cout << "What is the student's first name? ";
cin >> fname;
cout << "How many days did " << fname << " miss this term? ";
cin >> days;
cout << "What is " << fname << "'s current average? ";
cin >> avg;
cout << endl << endl;
// Place appropriate if and else statements to appropriately print
// the following lines. A student will be exempt if they miss 2 or less
// days and have an A average.
cout << fname << " is exempt from the Comprehensive Exam.";
cout << fname << " is not exempt from the Comprehensive Exam.";
return 0;
} // end function main
Lab6-5:
//Yourname Lab6-5.cpp
//Assignment: using if statements and case structure
// Preprocessor directives:
#include <iostream>
using namespace std;
// Named constant definitions (and function declarations):
// Main program:
int main()
{
// Variable declarations:
float length;
float perim, area;
int ans;
// Function body:
system("cls");
cout << "Box Information Calculator /n(Assume that all sides are of equal size)" << endl << endl;
cout << "Would you like to calculate: " << endl;
cout << " 1. Area of one side of the box" << endl;
cout << " 2. Perimeter of one side" << endl;
cout << " 3. Surface area of the box" << endl;
cout << " 4. Volume of the box" << endl << endl;
cin >> ans;
if (ans != 1 && ans != 2 && ans !=3 && ans !=4)
{
// Place an appropriate output statement here
return 0;
}
cout << "What is the length of one side? ";
cin >> length;
// Write if statements to confirm the user’s input from the menu, do the appropriate
// calculation, and print the answer – with an appropriate label.
// case 1: calculate and print the area of one side of the box
// case 2: calculate and print the perimeter of one side of the box
// case 3: calculate and print the surface area of the entire box
// case 4: calculate and print the volume of the box
}
return 0;
} // end function main