In this lab, you will be using control structures (if - else, switch)
to complete the following programs so they do what we require of them. Much
of the programs are written - you just need to add code for the decision
structures (aka selection structures).
You will also need to draw and turn in flowcharts for the decision
statements for each program.
If you like, you can number the statements of your code so you can
refer to them in the flowchart by number.
Print out and turn in the source code of each of your completed programs,
along with their corresponding flowcharts.
#include <iostream>
using namespace std;
int main()
{
int year; // store year entered by the user
bool isLeapYear; // set to true if year is a leap year, else set to false
// Prompt user for a year, and store it
cout << "Please enter a year: ";
cin >> year;
// check if the year is a leap year and set boolean variable
// isLeapYear accordingly:
// check value of isLeapYear and output message stating if the year
// is a leap year or not:
return 0;
}
switch
statement to set the flag, and an if
statement to output the appropriate message.
#include <iostream>
using namespace std;
int main()
{
char inputChar; // store character input by user
bool isVowel=false; // set to true if inputChar is a vowel,
// else set to false
// Prompt user to enter an uppercase character and read input character
cout << "Please enter a character (A-Z): ";
cin >> inputChar;
// If inputChar is a vowel, set isVowel to true, else set it to false:
// Output message stating whether inputChar is a vowel or not:
cout << "Character is a vowel." << endl;
cout << "Character is not a vowel." << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int userAge; // used to store user's age
// Prompt user for age and read the value
cout << "Please enter your age : ";
cin >> userAge;
// Check if user is or is not a teenager and print appropriate message.
// If they are not a teenager, print message indicating whether user
// is too young or old to be a teenager
return 0;
}