Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- //Assignment 1
- void assignemnt1()
- {
- double number, power, results;
- cout << "Please enter a number: ";
- cin >> number;
- cout << "Please enter a power: ";
- cin >> power;
- results = pow(number, power);
- cout << number << " raised to the " << power << "th power = " << results;
- return;
- }
- //Assignment 2
- void forLoopExample()
- {
- string usernameEntered, passwordEntered, username, password;
- username = "admin";
- password = "farmingdale";
- for (int counter = 0; counter < 3; counter++)
- {
- cout << "Enter username: ";
- cin >> usernameEntered;
- cout << "Enter password: ";
- cin >> passwordEntered;
- if (usernameEntered == username && passwordEntered == password)
- {
- cout << "Welcome\n";
- break;
- }
- else
- {
- cout << "Username or password was incorrect, try again.\n";
- }
- }
- }
- //Assignment 2
- void whileLoopExample()
- {
- int counter = 0;
- string usernameEntered, passwordEntered, username, password;
- username = "admin";
- password = "farmingdale";
- while (counter < 3)
- {
- cout << "Enter username: ";
- cin >> usernameEntered;
- cout << "Enter password: ";
- cin >> passwordEntered;
- if (usernameEntered == username && passwordEntered == password)
- {
- cout << "Welcome\n";
- break;
- }
- else
- {
- cout << "Username or password was incorrect, try again.\n";
- counter++;
- }
- }
- }
- //Assignment 2
- void doWhileLoopExample()
- {
- int counter = 0;
- string usernameEntered, passwordEntered, username, password;
- username = "admin";
- password = "farmingdale";
- do
- {
- cout << "Enter username: ";
- cin >> usernameEntered;
- cout << "Enter password: ";
- cin >> passwordEntered;
- if (usernameEntered == username && passwordEntered == password)
- {
- cout << "Welcome\n";
- break;
- }
- else
- {
- cout << "Username or password was incorrect, try again.\n";
- counter++;
- }
- } while (counter < 3);
- }
- //Assignment 2
- void assignment2()
- {
- char selection;
- system("cls");
- do
- {
- cout << " Password Menu\n";
- cout << " ====================================\n";
- cout << " 1. for Loop\n";
- cout << " 2. while Loop\n";
- cout << " 3. doWhile Loop\n";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- system("cls");
- forLoopExample();
- cout << "\n";
- break;
- case '2':
- system("cls");
- whileLoopExample();
- cout << "\n";
- break;
- case '3':
- system("cls");
- doWhileLoopExample();
- cout << "\n";
- break;
- case 'x':
- case 'X':
- _getch();
- return;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- }
- //Assignment 3
- int addNumbers(int x, int y)
- {
- return x + y;
- }
- //Assignment 3
- int subtractNumbers(int x, int y)
- {
- return x - y;
- }
- //Assignment 3
- int multiplyNumbers(int x, int y)
- {
- return x * y;
- }
- //Assignment 3
- int divideNumbers(int x, int y)
- {
- return x / y;
- }
- //Assignment 3
- void calculator(string operation)
- {
- system("cls");
- int x,
- y,
- result;
- cout << "Enter the first number:";
- cin >> x;
- cout << "Enter the second number:";
- cin >> y;
- if (operation == "+")
- {
- result = addNumbers(x, y);
- }
- else if (operation == "-")
- {
- result = subtractNumbers(x, y);
- }
- else if (operation == "x")
- {
- result = multiplyNumbers(x, y);
- }
- else if (operation == "/")
- {
- result = divideNumbers(x, y);
- }
- cout << x << operation << y << "=" << result << endl;
- system("pause");
- }
- //Assignment 3
- void showMenu()
- {
- char selection;
- system("cls");
- do
- {
- cout << " Calculator Menu\n";
- cout << " ====================================\n";
- cout << " 1. Add\n";
- cout << " 2. Subtract\n";
- cout << " 3. Multiple\n";
- cout << " 4. Divide";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- calculator("+");
- system("cls");
- break;
- case '2':
- calculator("-");
- system("cls");
- break;
- case '3':
- calculator("x");
- system("cls");
- break;
- case '4':
- calculator("/");
- system("cls");
- break;
- case 'x':
- case 'X':
- _getch();
- return;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- }
- //Assignment 3
- void assignment3()
- {
- showMenu();
- }
- //Assignment 4
- void assignment4()
- {
- char cont;
- do
- {
- int number;
- bool isPrime = true;
- cout << "Enter a positive integer: ";
- cin >> number;
- for (int i = 2; i <= number / 2; ++i)
- {
- if (number % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- cout << "This is a prime number \n";
- else
- cout << "This is not a prime number \n";
- cout << "Would you like to continue? Y/N \n";
- cin >> cont;
- } while (cont == 'y' || cont == 'Y');
- }
- //Assignment 5
- void assignment5()
- {
- const int limit = 100;
- string File[limit];
- char selection;
- char cont;
- string userEntered;
- cout << "Would you like to: \n\t\t1.Write to a file\n\t\t2.Read from the file";
- cin >> selection;
- cout << "\n";
- do
- {
- if (selection == '2') {
- ifstream myfile("Input.TXT");
- if (myfile.is_open())
- {
- while (!myfile.eof())
- {
- for (int x = 0; x < limit; x++)
- {
- myfile >> File[x];
- cout << File[x] << " ";
- }
- }
- }
- myfile.close();
- }
- if (selection == '1') {
- cout << "\nPlease enter sring to append to file:";
- cin >> userEntered;
- ofstream myfile("Input.TXT", ios::app);
- if (myfile.is_open())
- {
- myfile << userEntered;
- }
- myfile.close();
- }
- cout << "Would you like to continue?";
- cin >> cont;
- } while (cont == 'y' || cont == 'Y');
- }
- //Lab 1
- void lab1()
- {
- string name;
- system("cls");
- cout << "Please enter your name: ";
- cin >> name;
- cout << "Hello " << name;
- return;
- }
- //Lab 2
- void lab2()
- {
- const double KILOS_TO_MILES_RATE = 0.6213712;
- double kilos, miles;
- cout << "Please enter distance traveled in kilos: ";
- cin >> kilos;
- miles = kilos * KILOS_TO_MILES_RATE;
- cout << "You have traveled: \n" << kilos << " kilos \n" << miles << " miles";
- return;
- }
- //Lab 3
- void lab3()
- {
- double gpa, grade;
- string letterGrade;
- cout << "Your grade should be between 0 - 100\n";
- cout << "Please enter your grade:";
- cin >> grade;
- while (grade < 0 || grade > 100)
- {
- cout << "Please enter a valid grade between 0 - 100";
- cin >> grade;
- }
- if (grade >= 93 && grade <= 100)
- {
- letterGrade = "A";
- gpa = 4.0;
- }
- else if (grade >= 90)
- {
- letterGrade = "A-";
- gpa = 3.67;
- }
- else if (grade >= 87)
- {
- letterGrade = "B+";
- gpa = 3.33;
- }
- else if (grade >= 83)
- {
- letterGrade = "B";
- gpa = 3.0;
- }
- else if (grade >= 80)
- {
- letterGrade = "B-";
- gpa = 2.67;
- }
- else if (grade >= 77)
- {
- letterGrade = "C+";
- gpa = 2.33;
- }
- else if (grade >= 73)
- {
- letterGrade = "C";
- gpa = 2.00;
- }
- else if (grade >= 70)
- {
- letterGrade = "C-";
- gpa = 1.67;
- }
- else if (grade >= 67)
- {
- letterGrade = "D+";
- gpa = 1.33;
- }
- else if (grade >= 60)
- {
- letterGrade = "D";
- gpa = 1.00;
- }
- else if (grade < 60)
- {
- letterGrade = "F";
- grade = 0;
- }
- cout << "Your letter grade is a " << letterGrade << " and your gpa is " << gpa << endl;
- if (letterGrade == "A")
- {
- cout << "Good job";
- }
- else if (letterGrade == "F")
- {
- cout << "Need to study";
- }
- else
- cout << "You passed";
- return;
- }
- //Assignment Menu
- void assignments()
- {
- char selection;
- system("cls");
- do
- {
- cout << " Assignment Menu\n";
- cout << " ====================================\n";
- cout << " 1. Assingment 1 - Rasing a number to a power\n";
- cout << " 2. Assignment 2 - Login loop examples (doWhile, for, while)\n";
- cout << " 3. Assignment 3 - Addition, Subtraction, Multiplication, Division Calculator\n";
- cout << " 4. Assignment 4 - Checking if a number is prime or not\n";
- cout << " 5. Assignment 5 - Read and Write to a file\n";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- system("cls");
- assignemnt1();
- cout << "\n";
- break;
- case '2':
- system("cls");
- assignment2();
- cout << "\n";
- break;
- case '3':
- system("cls");
- assignment3();
- cout << "\n";
- break;
- case '4':
- system("cls");
- assignment4();
- cout << "\n";
- break;
- case '5':
- system("cls");
- assignment5();
- cout << "\n";
- break;
- case 'x':
- case 'X':
- _getch();
- return;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- }
- //Lab Menu
- void labs()
- {
- char selection;
- system("cls");
- do
- {
- cout << " Lab Menu\n";
- cout << " ====================================\n";
- cout << " 1. Lab 1 - Hello World by asking user for their name\n";
- cout << " 2. Lab 2 - Kilos to miles converter\n";
- cout << " 3. Lab 3 - Grade converter\n";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- system("cls");
- lab1();
- cout << "\n";
- break;
- case '2':
- system("cls");
- lab2();
- cout << "\n";
- break;
- case '3':
- system("cls");
- lab3();
- cout << "\n";
- break;
- case 'x':
- case 'X':
- _getch();
- return;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- }
- //Main Menu
- int main()
- {
- char selection;
- do
- {
- cout << " Main Menu\n";
- cout << " ====================================\n";
- cout << " 1. Assingments\n";
- cout << " 2. Labs\n";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- assignments();
- system("cls");
- break;
- case '2':
- labs();
- system("cls");
- break;
- case 'x':
- case 'X':
- cout << "Goodbye.\n";
- _getch();
- return 0;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- return 0;
- }
Add Comment
Please, Sign In to add comment