1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
/** Function declaration section**/
void displayMenu();
void greetUser(string userName);
int luckyNumber(int height, int weight, int birthMonth);
double squareRoot(double number);
int main()
{
int choice;
do
{
displayMenu();
cout << "Enter your choice (1-4): \n";
cin >> choice;
if (choice != 4)
{
//Switch-Case statements follow
switch (choice)
{
case 1:
{
string name;
cout << "What's your name: ";
cin >> name;
greetUser(name);
}
break;
case 2:
{
int height, weight, birthMonth;
cout << "Enter your height (in cms), weight (in lbs) and your birthMonth (1-12), each followed by a space: \n";
cin >> height >> weight >> birthMonth;
luckyNumber(height,weight,birthMonth);
}
break;
case 3:
{
double number;
cout << "Enter a floating point number whose square-root you would like to know: ";
cin >> number;
double numberSquareRoot;
numberSquareRoot= squareRoot(number);
cout << fixed << showpoint << setprecision(3);
cout << "\nSquare root of " << number << " is: " << numberSquareRoot << endl;
}
break;
}
}
} while (choice != 4);
return 0;
}
void displayMenu()
{
cout << "*************-Lab7-*************\n";
cout << "1. Display User Greeting\n";
cout << "2. Compute Lucky Number\n";
cout << "3. Compute Square Root\n";
cout << "4. Quit\n\n";
}
void greetUser(string userName)
{
cout << "Welcome, "<< userName<<endl;
}
int luckyNumber(int height, int weight, int birthMonth)
{
int lucky, num1;
double interrim;
interrim = ((pow(birthMonth,2)/8)+(pow(weight,6)/(height*2.2)));
num1 = int (interrim);
lucky = ((num1%366)%10)+1;
cout<< "Your lucky number is "<<lucky<<".\n";
return lucky;
}
double squareRoot(double number)
{
double numberSquareRoot;
numberSquareRoot= sqrt(number);
return numberSquareRoot;
}
|