Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

grade.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5. struct student {
  6. string name;
  7. int grade;
  8. string letter_grade;
  9. };
  10. int main() {
  11. // this is incorrect: typedef struct student1;
  12. struct student student1;
  13. struct student student2;
  14. int lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10, lab11;
  15. int exam1, exam2, final;
  16. int late_days;
  17. int late_daytotal = 0;
  18. int exam_late_days;
  19. int exam_late_days_total = 0;
  20. string name;
  21. for(int i = 1; i<3; i++){
  22. cout << "Please enter name of student: " << endl;
  23. cin >> name;
  24. cout << "Please enter grade for lab 1: " << endl;
  25. cin >> lab1;
  26. if(lab1 >20 or lab1 < 0){
  27. cout << "This is not in the range!" << endl;
  28. return 0;
  29. }
  30. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  31. cin >> late_days;
  32. if(late_days <-2 or late_days > 2){
  33. cout << "This is not in the range!" << endl;
  34. return 0;
  35. }
  36. late_daytotal = late_daytotal + late_days;
  37. cout << "Please enter grade for lab 2: " << endl;
  38. cin >> lab2;
  39. if(lab2 >20 or lab2 < 0){
  40. cout << "This is not in the range!" << endl;
  41. return 0;
  42. }
  43. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  44. cin >> late_days;
  45. if(late_days <-2 or late_days > 2){
  46. cout << "This is not in the range!" << endl;
  47. return 0;
  48. }
  49. late_daytotal = late_daytotal + late_days;
  50. cout << "Please enter grade for lab 3: " << endl;
  51. cin >> lab3;
  52. if(lab3 >30 or lab3 < 0){
  53. cout << "This is not in the range!" << endl;
  54. return 0;
  55. }
  56. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  57. cin >> late_days;
  58. if(late_days <-3 or late_days > 3){
  59. cout << "This is not in the range!" << endl;
  60. return 0;
  61. }
  62. late_daytotal = late_daytotal + late_days;
  63. cout << "Please enter grade for lab 4: " << endl;
  64. cin >> lab4;
  65. if(lab4 >30 or lab4 < 0){
  66. cout << "This is not in the range!" << endl;
  67. return 0;
  68. }
  69. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  70. cin >> late_days;
  71. if(late_days <-3 or late_days > 3){
  72. cout << "This is not in the range!" << endl;
  73. return 0;
  74. }
  75. late_daytotal = late_daytotal + late_days;
  76. cout << "Please enter grade for lab 5: " << endl;
  77. cin >> lab5;
  78. if(lab5 >30 or lab5 < 0){
  79. cout << "This is not in the range!" << endl;
  80. return 0;
  81. }
  82. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  83. cin >> late_days;
  84. if(late_days <-3 or late_days > 3){
  85. cout << "This is not in the range!" << endl;
  86. return 0;
  87. }
  88. late_daytotal = late_daytotal + late_days;
  89. cout << "Please enter grade for lab 6: " << endl;
  90. cin >> lab6;
  91. if(lab6 >30 or lab6 < 0){
  92. cout << "This is not in the range!" << endl;
  93. return 0;
  94. }
  95. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  96. cin >> late_days;
  97. if(late_days <-3 or late_days > 3){
  98. cout << "This is not in the range!" << endl;
  99. return 0;
  100. }
  101. late_daytotal = late_daytotal + late_days;
  102. cout << "Please enter grade for lab 7: " << endl;
  103. cin >> lab7;
  104. if(lab7 >30 or lab7 < 0){
  105. cout << "This is not in the range!" << endl;
  106. return 0;
  107. }
  108. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  109. cin >> late_days;
  110. if(late_days <-3 or late_days > 3){
  111. cout << "This is not in the range!" << endl;
  112. return 0;
  113. }
  114. late_daytotal = late_daytotal + late_days;
  115. cout << "Please enter grade for lab 8: " << endl;
  116. cin >> lab8;
  117. if(lab8 >30 or lab8 < 0){
  118. cout << "This is not in the range!" << endl;
  119. return 0;
  120. }
  121. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  122. cin >> late_days;
  123. if(late_days <-3 or late_days > 3){
  124. cout << "This is not in the range!" << endl;
  125. return 0;
  126. }
  127. late_daytotal = late_daytotal + late_days;
  128. cout << "Please enter grade for lab 9: " << endl;
  129. cin >> lab9;
  130. if(lab9 >20 or lab9 < 0){
  131. cout << "This is not in the range!" << endl;
  132. return 0;
  133. }
  134. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  135. cin >> late_days;
  136. if(late_days <-2 or late_days > 2){
  137. cout << "This is not in the range!" << endl;
  138. return 0;
  139. }
  140. late_daytotal = late_daytotal + late_days;
  141. cout << "Please enter grade for lab 10: " << endl;
  142. cin >> lab10;
  143. if(lab10 >20 or lab10 < 0){
  144. cout << "This is not in the range!" << endl;
  145. return 0;
  146. }
  147. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  148. cin >> late_days;
  149. if(late_days <-2 or late_days > 2){
  150. cout << "This is not in the range!" << endl;
  151. return 0;
  152. }
  153. late_daytotal = late_daytotal + late_days;
  154. cout << "Please enter grade for lab 11: " << endl;
  155. cin >> lab11;
  156. if(lab11 >40 or lab11 < 0){
  157. cout << "This is not in the range!" << endl;
  158. return 0;
  159. }
  160. cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
  161. cin >> late_days;
  162. if(late_days <-4 or late_days > 4){
  163. cout << "This is not in the range!" << endl;
  164. return 0;
  165. }
  166. late_daytotal = late_daytotal + late_days;
  167. cout << "Please enter exam 1 score: " << endl;
  168. cin >> exam1;
  169. if(exam1 < 0 or exam1 > 100){
  170. cout << "This is not in the range!" << endl;
  171. return 0;
  172. }
  173. cout << "Were there late days/early days?" << endl;
  174. cin >> exam_late_days;
  175. if(exam_late_days < 0 or exam_late_days > 3){
  176. cout << "This is not in the range!" << endl;
  177. return 0;
  178. }
  179. exam_late_days_total = exam_late_days_total + exam_late_days;
  180. cout << "Please enter exam 2 score: " << endl;
  181. cin >> exam2;
  182. if(exam2 < 0 or exam2 > 100){
  183. cout << "This is not in the range!" << endl;
  184. return 0;
  185. }
  186. cout << "Were there late days/early days?" << endl;
  187. cin >> exam_late_days;
  188. if(exam_late_days < 0 or exam_late_days > 3){
  189. cout << "This is not in the range!" << endl;
  190. return 0;
  191. }
  192. exam_late_days_total = exam_late_days_total + exam_late_days;
  193. cout << "Please enter final score: " << endl;
  194. cin >> final;
  195. if(final < 0 or final > 100){
  196. cout << "This is not in the range!" << endl;
  197. return 0;
  198. }
  199. cout << "Were there late days/early days?" << endl;
  200. cin >> exam_late_days;
  201. if(exam_late_days < 0 or exam_late_days > 3){
  202. cout << "This is not in the range!" << endl;
  203. return 0;
  204. }
  205. exam_late_days_total = exam_late_days_total + exam_late_days;
  206. int total_labs = lab1+lab2+lab3+lab4+lab5+lab6+lab7+lab8+lab9+lab10+lab11;
  207. int total_exam = exam1 + exam2 + final;
  208. int final_grade = total_labs + total_exam;
  209. if(late_daytotal < 0){
  210. final_grade = final_grade + abs(late_daytotal);
  211. }
  212. else{
  213. final_grade = final_grade - late_daytotal;
  214. }
  215. final_grade = final_grade - exam_late_days_total*20;
  216. string letter_grade;
  217. if(final_grade >= 570)
  218. letter_grade = "A";
  219. if(final_grade <570 && final_grade >=540)
  220. letter_grade = "A-";
  221. if(final_grade < 540 && final_grade >= 522)
  222. letter_grade = "B+";
  223. if(final_grade < 522 && final_grade >= 498)
  224. letter_grade = "B";
  225. if(final_grade < 498 && final_grade >= 480)
  226. letter_grade = "B-";
  227. if(final_grade < 480 && final_grade >= 462)
  228. letter_grade = "C+";
  229. if(final_grade < 462 && final_grade >= 438)
  230. letter_grade = "C";
  231. if(final_grade < 438 && final_grade >= 420)
  232. letter_grade = "C-";
  233. if(final_grade < 420 && final_grade >= 402)
  234. letter_grade = "D+";
  235. if(final_grade < 402 && final_grade >= 378)
  236. letter_grade = "D";
  237. if(final_grade < 378 && final_grade >= 360)
  238. letter_grade = "D-";
  239. if(final_grade < 360)
  240. letter_grade = "E";
  241. // something looks iffy here: (check your warnings (read all the words (even 'assignment')))
  242. if (i == 1) {
  243. student1.name = name;
  244. student1.grade = final_grade;
  245. student1.letter_grade = letter_grade;
  246. }
  247. else {
  248. student2.name = name;
  249. student2.grade = final_grade;
  250. student2.letter_grade = letter_grade;
  251. }
  252. }
  253. int order = 0;
  254. cout << "Please enter what order you want to see the students: " << endl;
  255. cout << "enter 1 for alphabetical or 2 for highest score first: " << endl;
  256. cin >> order;
  257. if(order > 2 or order < 1) {
  258. cout << "out of range" <<endl;
  259. return 0;
  260. }
  261. if(order == 1){
  262. if(student1.name < student2.name) {
  263. cout << "name " << student1.name << endl;
  264. cout << "points " << student1.grade << endl;
  265. cout << "letter grade " << student1.letter_grade << endl;
  266. cout << "name " << student2.name << endl;
  267. cout << "points " << student2.grade << endl;
  268. cout << "letter grade " << student2.letter_grade << endl;
  269. }
  270. else {
  271. cout << "name " << student2.name << endl;
  272. cout << "points " << student2.grade << endl;
  273. cout << "letter grade " << student2.letter_grade << endl;
  274. cout << "name " << student1.name << endl;
  275. cout << "points " << student1.grade << endl;
  276. cout << "letter grade " << student1.letter_grade << endl;
  277. }
  278. }
  279. if(order == 2){
  280. if(student1.grade > student2.grade){
  281. cout << "name " << student1.name << endl;
  282. cout << "points " << student1.grade << endl;
  283. cout << "letter grade " << student1.letter_grade << endl;
  284. cout << "name " << student2.name << endl;
  285. cout << "points " << student2.grade << endl;
  286. cout << "letter grade " << student2.letter_grade << endl;
  287. }
  288. else {
  289. cout << "name " << student2.name << endl;
  290. cout << "points " << student2.grade << endl;
  291. cout << "letter grade " << student2.letter_grade << endl;
  292. cout << "name " << student1.name << endl;
  293. cout << "points " << student1.grade << endl;
  294. cout << "letter grade " << student1.letter_grade << endl;
  295. }
  296. }
  297. }