JamesDamico

BCS 120 - Final Project

Oct 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. //Assignment 1
  9. void assignemnt1()
  10. {
  11. double number, power, results;
  12. cout << "Please enter a number: ";
  13. cin >> number;
  14.  
  15. cout << "Please enter a power: ";
  16. cin >> power;
  17.  
  18. results = pow(number, power);
  19.  
  20. cout << number << " raised to the " << power << "th power = " << results;
  21.  
  22. return;
  23. }
  24.  
  25. //Assignment 2
  26. void forLoopExample()
  27. {
  28. string usernameEntered, passwordEntered, username, password;
  29. username = "admin";
  30. password = "farmingdale";
  31.  
  32. for (int counter = 0; counter < 3; counter++)
  33. {
  34. cout << "Enter username: ";
  35. cin >> usernameEntered;
  36.  
  37. cout << "Enter password: ";
  38. cin >> passwordEntered;
  39.  
  40. if (usernameEntered == username && passwordEntered == password)
  41. {
  42. cout << "Welcome\n";
  43. break;
  44. }
  45. else
  46. {
  47. cout << "Username or password was incorrect, try again.\n";
  48. }
  49. }
  50. }
  51.  
  52. //Assignment 2
  53. void whileLoopExample()
  54. {
  55. int counter = 0;
  56. string usernameEntered, passwordEntered, username, password;
  57.  
  58. username = "admin";
  59. password = "farmingdale";
  60.  
  61. while (counter < 3)
  62. {
  63. cout << "Enter username: ";
  64. cin >> usernameEntered;
  65.  
  66. cout << "Enter password: ";
  67. cin >> passwordEntered;
  68.  
  69. if (usernameEntered == username && passwordEntered == password)
  70. {
  71. cout << "Welcome\n";
  72. break;
  73. }
  74. else
  75. {
  76. cout << "Username or password was incorrect, try again.\n";
  77. counter++;
  78. }
  79. }
  80. }
  81.  
  82. //Assignment 2
  83. void doWhileLoopExample()
  84. {
  85. int counter = 0;
  86. string usernameEntered, passwordEntered, username, password;
  87.  
  88. username = "admin";
  89. password = "farmingdale";
  90.  
  91. do
  92. {
  93. cout << "Enter username: ";
  94. cin >> usernameEntered;
  95.  
  96. cout << "Enter password: ";
  97. cin >> passwordEntered;
  98.  
  99. if (usernameEntered == username && passwordEntered == password)
  100. {
  101. cout << "Welcome\n";
  102. break;
  103. }
  104. else
  105. {
  106. cout << "Username or password was incorrect, try again.\n";
  107. counter++;
  108. }
  109. } while (counter < 3);
  110. }
  111.  
  112. //Assignment 2
  113. void assignment2()
  114. {
  115. char selection;
  116. system("cls");
  117.  
  118. do
  119. {
  120. cout << " Password Menu\n";
  121. cout << " ====================================\n";
  122. cout << " 1. for Loop\n";
  123. cout << " 2. while Loop\n";
  124. cout << " 3. doWhile Loop\n";
  125. cout << "\n";
  126. cout << " X. Exit\n";
  127. cout << " ====================================\n";
  128. cout << " Enter your selection: ";
  129. cin >> selection;
  130. cout << endl;
  131.  
  132. switch (selection)
  133. {
  134. case '1':
  135. system("cls");
  136. forLoopExample();
  137. cout << "\n";
  138. break;
  139. case '2':
  140. system("cls");
  141. whileLoopExample();
  142. cout << "\n";
  143. break;
  144. case '3':
  145. system("cls");
  146. doWhileLoopExample();
  147. cout << "\n";
  148. break;
  149. case 'x':
  150. case 'X':
  151. _getch();
  152. return;
  153. default: cout << selection << " is not a valid menu item.\n";
  154.  
  155. cout << endl;
  156. }
  157.  
  158. } while (selection != 'x' || selection != 'X');
  159. }
  160.  
  161. //Assignment 3
  162. int addNumbers(int x, int y)
  163. {
  164. return x + y;
  165. }
  166.  
  167. //Assignment 3
  168. int subtractNumbers(int x, int y)
  169. {
  170. return x - y;
  171. }
  172.  
  173. //Assignment 3
  174. int multiplyNumbers(int x, int y)
  175. {
  176. return x * y;
  177. }
  178.  
  179. //Assignment 3
  180. int divideNumbers(int x, int y)
  181. {
  182. return x / y;
  183. }
  184.  
  185. //Assignment 3
  186. void calculator(string operation)
  187. {
  188. system("cls");
  189. int x,
  190. y,
  191. result;
  192.  
  193. cout << "Enter the first number:";
  194. cin >> x;
  195.  
  196. cout << "Enter the second number:";
  197. cin >> y;
  198.  
  199. if (operation == "+")
  200. {
  201. result = addNumbers(x, y);
  202. }
  203. else if (operation == "-")
  204. {
  205. result = subtractNumbers(x, y);
  206. }
  207. else if (operation == "x")
  208. {
  209. result = multiplyNumbers(x, y);
  210. }
  211. else if (operation == "/")
  212. {
  213. result = divideNumbers(x, y);
  214. }
  215.  
  216. cout << x << operation << y << "=" << result << endl;
  217. system("pause");
  218. }
  219.  
  220. //Assignment 3
  221. void showMenu()
  222. {
  223.  
  224. char selection;
  225. system("cls");
  226.  
  227. do
  228. {
  229. cout << " Calculator Menu\n";
  230. cout << " ====================================\n";
  231. cout << " 1. Add\n";
  232. cout << " 2. Subtract\n";
  233. cout << " 3. Multiple\n";
  234. cout << " 4. Divide";
  235. cout << "\n";
  236. cout << " X. Exit\n";
  237. cout << " ====================================\n";
  238. cout << " Enter your selection: ";
  239. cin >> selection;
  240. cout << endl;
  241.  
  242. switch (selection)
  243. {
  244. case '1':
  245. calculator("+");
  246. system("cls");
  247. break;
  248. case '2':
  249. calculator("-");
  250. system("cls");
  251. break;
  252. case '3':
  253. calculator("x");
  254. system("cls");
  255. break;
  256. case '4':
  257. calculator("/");
  258. system("cls");
  259. break;
  260.  
  261. case 'x':
  262. case 'X':
  263. _getch();
  264. return;
  265. default: cout << selection << " is not a valid menu item.\n";
  266.  
  267. cout << endl;
  268. }
  269. } while (selection != 'x' || selection != 'X');
  270. }
  271.  
  272. //Assignment 3
  273. void assignment3()
  274. {
  275. showMenu();
  276. }
  277.  
  278.  
  279. //Assignment 4
  280. void assignment4()
  281. {
  282. char cont;
  283.  
  284. do
  285. {
  286. int number;
  287. bool isPrime = true;
  288.  
  289. cout << "Enter a positive integer: ";
  290. cin >> number;
  291.  
  292. for (int i = 2; i <= number / 2; ++i)
  293. {
  294. if (number % i == 0)
  295. {
  296. isPrime = false;
  297. break;
  298. }
  299. }
  300. if (isPrime)
  301. cout << "This is a prime number \n";
  302. else
  303. cout << "This is not a prime number \n";
  304.  
  305. cout << "Would you like to continue? Y/N \n";
  306. cin >> cont;
  307.  
  308. } while (cont == 'y' || cont == 'Y');
  309. }
  310.  
  311.  
  312. //Assignment 5
  313. void assignment5()
  314. {
  315. const int limit = 100;
  316.  
  317. string File[limit];
  318.  
  319. char selection;
  320. char cont;
  321.  
  322. string userEntered;
  323.  
  324. cout << "Would you like to: \n\t\t1.Write to a file\n\t\t2.Read from the file";
  325.  
  326. cin >> selection;
  327.  
  328. cout << "\n";
  329.  
  330. do
  331. {
  332. if (selection == '2') {
  333.  
  334. ifstream myfile("Input.TXT");
  335.  
  336. if (myfile.is_open())
  337.  
  338. {
  339.  
  340. while (!myfile.eof())
  341.  
  342. {
  343.  
  344. for (int x = 0; x < limit; x++)
  345.  
  346. {
  347.  
  348. myfile >> File[x];
  349.  
  350. cout << File[x] << " ";
  351.  
  352. }
  353.  
  354. }
  355.  
  356. }
  357.  
  358. myfile.close();
  359.  
  360. }
  361.  
  362. if (selection == '1') {
  363.  
  364. cout << "\nPlease enter sring to append to file:";
  365.  
  366. cin >> userEntered;
  367.  
  368. ofstream myfile("Input.TXT", ios::app);
  369.  
  370. if (myfile.is_open())
  371.  
  372. {
  373.  
  374. myfile << userEntered;
  375.  
  376. }
  377.  
  378. myfile.close();
  379.  
  380. }
  381.  
  382. cout << "Would you like to continue?";
  383. cin >> cont;
  384.  
  385. } while (cont == 'y' || cont == 'Y');
  386.  
  387.  
  388. }
  389.  
  390. //Lab 1
  391. void lab1()
  392. {
  393. string name;
  394.  
  395. system("cls");
  396.  
  397. cout << "Please enter your name: ";
  398. cin >> name;
  399.  
  400. cout << "Hello " << name;
  401.  
  402. return;
  403. }
  404.  
  405. //Lab 2
  406. void lab2()
  407. {
  408. const double KILOS_TO_MILES_RATE = 0.6213712;
  409.  
  410. double kilos, miles;
  411.  
  412. cout << "Please enter distance traveled in kilos: ";
  413. cin >> kilos;
  414.  
  415. miles = kilos * KILOS_TO_MILES_RATE;
  416.  
  417. cout << "You have traveled: \n" << kilos << " kilos \n" << miles << " miles";
  418.  
  419. return;
  420. }
  421.  
  422. //Lab 3
  423. void lab3()
  424. {
  425. double gpa, grade;
  426. string letterGrade;
  427.  
  428. cout << "Your grade should be between 0 - 100\n";
  429. cout << "Please enter your grade:";
  430. cin >> grade;
  431.  
  432. while (grade < 0 || grade > 100)
  433. {
  434. cout << "Please enter a valid grade between 0 - 100";
  435. cin >> grade;
  436. }
  437.  
  438. if (grade >= 93 && grade <= 100)
  439. {
  440. letterGrade = "A";
  441. gpa = 4.0;
  442. }
  443. else if (grade >= 90)
  444. {
  445. letterGrade = "A-";
  446. gpa = 3.67;
  447. }
  448. else if (grade >= 87)
  449. {
  450. letterGrade = "B+";
  451. gpa = 3.33;
  452. }
  453. else if (grade >= 83)
  454. {
  455. letterGrade = "B";
  456. gpa = 3.0;
  457. }
  458. else if (grade >= 80)
  459. {
  460. letterGrade = "B-";
  461. gpa = 2.67;
  462. }
  463. else if (grade >= 77)
  464. {
  465. letterGrade = "C+";
  466. gpa = 2.33;
  467. }
  468. else if (grade >= 73)
  469. {
  470. letterGrade = "C";
  471. gpa = 2.00;
  472. }
  473. else if (grade >= 70)
  474. {
  475. letterGrade = "C-";
  476. gpa = 1.67;
  477. }
  478. else if (grade >= 67)
  479. {
  480. letterGrade = "D+";
  481. gpa = 1.33;
  482. }
  483. else if (grade >= 60)
  484. {
  485. letterGrade = "D";
  486. gpa = 1.00;
  487. }
  488. else if (grade < 60)
  489. {
  490. letterGrade = "F";
  491. grade = 0;
  492. }
  493.  
  494. cout << "Your letter grade is a " << letterGrade << " and your gpa is " << gpa << endl;
  495.  
  496. if (letterGrade == "A")
  497. {
  498. cout << "Good job";
  499. }
  500. else if (letterGrade == "F")
  501. {
  502. cout << "Need to study";
  503. }
  504. else
  505. cout << "You passed";
  506.  
  507. return;
  508. }
  509.  
  510. //Assignment Menu
  511. void assignments()
  512. {
  513. char selection;
  514. system("cls");
  515.  
  516.  
  517. do
  518. {
  519. cout << " Assignment Menu\n";
  520. cout << " ====================================\n";
  521. cout << " 1. Assingment 1 - Rasing a number to a power\n";
  522. cout << " 2. Assignment 2 - Login loop examples (doWhile, for, while)\n";
  523. cout << " 3. Assignment 3 - Addition, Subtraction, Multiplication, Division Calculator\n";
  524. cout << " 4. Assignment 4 - Checking if a number is prime or not\n";
  525. cout << " 5. Assignment 5 - Read and Write to a file\n";
  526. cout << "\n";
  527. cout << " X. Exit\n";
  528. cout << " ====================================\n";
  529. cout << " Enter your selection: ";
  530. cin >> selection;
  531. cout << endl;
  532.  
  533. switch (selection)
  534. {
  535. case '1':
  536. system("cls");
  537. assignemnt1();
  538. cout << "\n";
  539. break;
  540. case '2':
  541. system("cls");
  542. assignment2();
  543. cout << "\n";
  544. break;
  545. case '3':
  546. system("cls");
  547. assignment3();
  548. cout << "\n";
  549. break;
  550. case '4':
  551. system("cls");
  552. assignment4();
  553. cout << "\n";
  554. break;
  555. case '5':
  556. system("cls");
  557. assignment5();
  558. cout << "\n";
  559. break;
  560. case 'x':
  561. case 'X':
  562. _getch();
  563. return;
  564. default: cout << selection << " is not a valid menu item.\n";
  565.  
  566. cout << endl;
  567. }
  568.  
  569. } while (selection != 'x' || selection != 'X');
  570. }
  571.  
  572. //Lab Menu
  573. void labs()
  574. {
  575. char selection;
  576. system("cls");
  577.  
  578. do
  579. {
  580. cout << " Lab Menu\n";
  581. cout << " ====================================\n";
  582. cout << " 1. Lab 1 - Hello World by asking user for their name\n";
  583. cout << " 2. Lab 2 - Kilos to miles converter\n";
  584. cout << " 3. Lab 3 - Grade converter\n";
  585. cout << "\n";
  586. cout << " X. Exit\n";
  587. cout << " ====================================\n";
  588. cout << " Enter your selection: ";
  589. cin >> selection;
  590. cout << endl;
  591.  
  592. switch (selection)
  593. {
  594. case '1':
  595. system("cls");
  596. lab1();
  597. cout << "\n";
  598. break;
  599.  
  600. case '2':
  601. system("cls");
  602. lab2();
  603. cout << "\n";
  604. break;
  605. case '3':
  606. system("cls");
  607. lab3();
  608. cout << "\n";
  609. break;
  610. case 'x':
  611. case 'X':
  612. _getch();
  613. return;
  614. default: cout << selection << " is not a valid menu item.\n";
  615.  
  616. cout << endl;
  617. }
  618.  
  619. } while (selection != 'x' || selection != 'X');
  620. }
  621.  
  622. //Main Menu
  623. int main()
  624. {
  625. char selection;
  626.  
  627. do
  628. {
  629. cout << " Main Menu\n";
  630. cout << " ====================================\n";
  631. cout << " 1. Assingments\n";
  632. cout << " 2. Labs\n";
  633. cout << "\n";
  634. cout << " X. Exit\n";
  635. cout << " ====================================\n";
  636. cout << " Enter your selection: ";
  637. cin >> selection;
  638. cout << endl;
  639.  
  640. switch (selection)
  641. {
  642. case '1':
  643. assignments();
  644. system("cls");
  645. break;
  646.  
  647. case '2':
  648. labs();
  649. system("cls");
  650. break;
  651.  
  652. case 'x':
  653. case 'X':
  654. cout << "Goodbye.\n";
  655. _getch();
  656. return 0;
  657. default: cout << selection << " is not a valid menu item.\n";
  658.  
  659. cout << endl;
  660. }
  661.  
  662. } while (selection != 'x' || selection != 'X');
  663.  
  664. return 0;
  665. }
Add Comment
Please, Sign In to add comment