Message
Message
// =======================================
// Insert more header files when necessary
// =======================================
#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;
void showInfo()
{
// Fill in your personal particulars below
cout << "Name : Lam Chun Kit\n";
cout << "Student ID: 22178833A\n";
cout << "Class : 205\n";
}
void Q1()
{
// =====================================
// Insert your codes for Question 1 here
// No need main() and return 0
// =====================================
char mr;
int nop, nosd, nomd, nold;
double disc, alldish;
cin >> nop >> mr >> nosd >> nomd >> nold;
cout << setprecision(2);
switch (mr) {
case 'G': if (nop > 4)
{
nop = nop - 1;
}
alldish = (nop * 4.5) + (nosd * 15) + (nomd * 19) + (nold * 23);
if (nop > 5)
{
disc = alldish * 0.12;
}
else
{
disc = alldish * 0.08;
}
cout << fixed;
cout << (alldish * 1.1) - disc;
break;
case 'B': alldish = (nop * 4.5) + (nosd * 15) + (nomd * 19) + (nold * 23);
if (nop > 8)
{
disc = alldish * 0.08;
}
else
{
disc = 0;
}
cout << fixed;
cout << (alldish * 1.1) - disc;
break;
case 'N': alldish = (nop * 4.5) + (nosd * 15) + (nomd * 19) + (nold * 23);
cout << fixed;
cout << alldish * 1.1;
break;
}
}
void Q2()
{
// =====================================
// Insert your codes for Question 2 here
// No need main() and return 0
// =====================================
char secret = 'O', guess = 'A', head = 'A', end = 'Z';
int i = 0;
do {
if (isupper(guess))
{
if (int(guess) > int(secret))
{
if (int(end) > int(guess))
{
end = guess;
}
cout << head << " - " << end << ": ";
cin >> guess;
i = i + 1;
}
else if (int(guess) < int(secret))
{
if (int(end) > int(guess))
{
head = guess;
}
cout << head << " - " << end << ": ";
cin >> guess;
i = i + 1;
}
else if (int(guess) == int(secret))
{
i = i + 1;
}
}
else
{
cout << head << " - " << end << ": ";
cin >> guess;
i = i + 1;
}
} while (secret != guess);
cout << i;
}
void Q3()
{
// =====================================
// Insert your codes for Question 3 here
// No need main() and return 0
// =====================================
int x, onerowstarscount = 0, allstars, row, column, spaceinput, starcount =
0, spaceneeded = 1;
cin >> x;
allstars = x * 2;
spaceneeded = x;
}
if (starcount == allstars)
{
cout << endl;
starcount = 0;
spaceneeded--;
}
onerowstarscount = 0;
starcount = 0;
for (row = 1; row <= x;row++) {
for (column = 1; column <= allstars;column++) {
cout << "*";
starcount++;
if (starcount == allstars)
{
cout << endl;
starcount = 0;
}
}
}
onerowstarscount = 0;
starcount = 0;
spaceneeded = 1;
}
if (starcount == allstars)
{
cout << endl;
starcount = 0;
spaceneeded++;
}
do {
cout << "\n\n";
cout << "Program Selection Menu" << endl;
cout << "---------------------------------------" << endl;
cout << "Enter question number ('q' to quit): ";
cin >> prog_choice;
cout << "\n\n";
switch (prog_choice) {
case '0': showInfo(); break;
case '1': Q1(); break;
case '2': Q2(); break;
case '3': Q3(); break;
case 'q': break;
default:
cout << "No such question " << prog_choice << endl;
break;
}
} while (prog_choice != 'q');