aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab5
diff options
context:
space:
mode:
authorJames Lawrance <[email protected]>2021-10-27 20:42:30 -0700
committerJames Lawrance <[email protected]>2021-10-27 20:42:30 -0700
commitd60bba523093d55586efc843a9df9bca14d3dfa1 (patch)
treec011c6309101d12fb3b38dac5d7521755e3a65e8 /CST116F2021-Lab5
parentAdd online IDE url (diff)
downloadcst116-lab5-jemersonlawrance-d60bba523093d55586efc843a9df9bca14d3dfa1.tar.xz
cst116-lab5-jemersonlawrance-d60bba523093d55586efc843a9df9bca14d3dfa1.zip
Lab 5 changes night class 10/27
Diffstat (limited to 'CST116F2021-Lab5')
-rw-r--r--CST116F2021-Lab5/CST116F2021-Lab5.cpp228
1 files changed, 215 insertions, 13 deletions
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.cpp b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
index e7591f7..27794e9 100644
--- a/CST116F2021-Lab5/CST116F2021-Lab5.cpp
+++ b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
@@ -1,20 +1,222 @@
-// CST116F2021-Lab5.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
#include <iostream>
+using namespace std;
+
+
+//9a -
+//Section 10.5 -
+
+//int main()
+//{
+ //create arrays
+// int studentScores[10];
+// char studentGrades[10];
+ //loop input into array
+// for (int scoreCount = 0; scoreCount <= 9; scoreCount++)
+// {
+// cout << "Enter student " << scoreCount + 1 << "'s score: ";
+// cin >> studentScores[scoreCount];
+// }
+ //scores to grades loop
+// for (int scoreCount = 0; scoreCount <= 9; scoreCount++)
+// {
+// if (studentScores[scoreCount] >= 92.0)
+// {
+// studentGrades[scoreCount] = 'A';
+// }
+// else if (studentScores[scoreCount] >= 84.0)
+// {
+// studentGrades[scoreCount] = 'B';
+// }
+// else if (studentScores[scoreCount] >= 75.0)
+// {
+// studentGrades[scoreCount] = 'C';
+// }
+// else if (studentScores[scoreCount] >= 65.0)
+// {
+// studentGrades[scoreCount] = 'D';
+// }
+// else if (studentScores[scoreCount] < 65.0)
+// {
+// studentGrades[scoreCount] = 'F';
+// }
+// }
+ //display grades for each student
+// cout << endl;
+// for (int gradeCount = 0; gradeCount <= 9; gradeCount++)
+// {
+// cout << "Student " << gradeCount + 1 << "'s grade: " << studentGrades[gradeCount] << endl;
+// }
+ //display class average
+// cout << endl;
+// float classAverage = 0;
+// for (int scoreCount = 0; scoreCount < 10; scoreCount++)
+// {
+// classAverage = classAverage + studentScores[scoreCount];
+// }
+// cout << "Class average: " << classAverage/10 << endl;
+ //display number of students per grade
+// cout << endl;
+// int studentAs = 0;
+// int studentBs = 0;
+// int studentCs = 0;
+// int studentDs = 0;
+// int studentFs = 0;
+
+// for (int gradeCount = 0; gradeCount < 10; gradeCount++)
+// {
+// if (studentGrades[gradeCount] == 'A')
+// {
+// studentAs++;
+// }
+// if (studentGrades[gradeCount] == 'B')
+// {
+// studentBs++;
+// }
+// if (studentGrades[gradeCount] == 'C')
+// {
+// studentCs++;
+// }
+// if (studentGrades[gradeCount] == 'D')
+// {
+// studentDs++;
+// }
+// if (studentGrades[gradeCount] == 'F')
+// {
+// studentFs++;
+// }
+// }
+
+// cout << studentAs << " students got A's" << endl;
+// cout << studentBs << " students got B's" << endl;
+// cout << studentCs << " students got C's" << endl;
+// cout << studentDs << " students got D's" << endl;
+// cout << studentFs << " students got F's" << endl;
+//}
+
+//9b -
+//Section 10.6
+
+//Function Prototypes
+void getScores(int studentScores[]);
+void calculateGrades(int studentScores[], char studentGrades[]);
+void displayGrades(char studentGrades[]);
+void classAverage(int studentScores[]);
+void studentsPerGrade(char studentGrades[]);
int main()
{
- std::cout << "Hello World!\n";
+ //defining
+ int studentScores[10];
+ char studentGrades[10];
+ //entry sequence
+ cout << "Welcome to the 10 scores to grades program." << endl;
+ //get scores
+ cout << endl;
+ getScores(studentScores);
+ //calculate grades
+ calculateGrades(studentScores, studentGrades);
+ //display grades
+ cout << endl;
+ displayGrades(studentGrades);
+ //display class average
+ cout << endl;
+ classAverage(studentScores);
+ //display students per grade
+ cout << endl;
+ studentsPerGrade(studentGrades);
+
+ return 0;
+}
+
+void getScores(int studentScores[])
+{
+ for (int scoreCount = 0; scoreCount < 10; scoreCount++)
+ {
+ cout << "Please enter student " << scoreCount + 1 << "'s score: ";
+ cin >> studentScores[scoreCount];
+ }
}
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
+void calculateGrades(int studentScores[], char studentGrades[])
+{
+ for (int scoreCount = 0; scoreCount < 10; scoreCount++)
+ {
+ if (studentScores[scoreCount] >= 92.0)
+ {
+ studentGrades[scoreCount] = 'A';
+ }
+ else if (studentScores[scoreCount] >= 84.0)
+ {
+ studentGrades[scoreCount] = 'B';
+ }
+ else if (studentScores[scoreCount] >= 75.0)
+ {
+ studentGrades[scoreCount] = 'C';
+ }
+ else if (studentScores[scoreCount] >= 65.0)
+ {
+ studentGrades[scoreCount] = 'D';
+ }
+ else if (studentScores[scoreCount] < 65.0)
+ {
+ studentGrades[scoreCount] = 'F';
+ }
+ }
+}
+
+void displayGrades(char studentGrades[])
+{
+ for (int gradeCount = 0; gradeCount < 10; gradeCount++)
+ {
+ cout << "Student " << gradeCount + 1 << "'s final grade: " << studentGrades[gradeCount] << endl;
+ }
+}
+
+void classAverage(int studentScores[])
+{
+ float classAverage = 0;
+ for (int scoreCount = 0; scoreCount < 10; scoreCount++)
+ {
+ classAverage = classAverage + studentScores[scoreCount];
+ }
+ cout << "Class average: " << classAverage / 10 << endl;
+}
+
+void studentsPerGrade(char studentGrades[])
+{
+ int studentAs = 0;
+ int studentBs = 0;
+ int studentCs = 0;
+ int studentDs = 0;
+ int studentFs = 0;
+
+ for (int gradeCount = 0; gradeCount < 10; gradeCount++)
+ {
+ if (studentGrades[gradeCount] == 'A')
+ {
+ studentAs++;
+ }
+ if (studentGrades[gradeCount] == 'B')
+ {
+ studentBs++;
+ }
+ if (studentGrades[gradeCount] == 'C')
+ {
+ studentCs++;
+ }
+ if (studentGrades[gradeCount] == 'D')
+ {
+ studentDs++;
+ }
+ if (studentGrades[gradeCount] == 'F')
+ {
+ studentFs++;
+ }
+ }
-// Tips for Getting Started:
-// 1. Use the Solution Explorer window to add/manage files
-// 2. Use the Team Explorer window to connect to source control
-// 3. Use the Output window to see build output and other messages
-// 4. Use the Error List window to view errors
-// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
-// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
+ cout << studentAs << " students got A's" << endl;
+ cout << studentBs << " students got B's" << endl;
+ cout << studentCs << " students got C's" << endl;
+ cout << studentDs << " students got D's" << endl;
+ cout << studentFs << " students got F's" << endl;
+} \ No newline at end of file