aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST116F2021-Lab5/CONSOLE OUTPUT.txt116
-rw-r--r--CST116F2021-Lab5/CST116F2021-Lab5.cpp164
-rw-r--r--CST116F2021-Lab5/External_functions.cpp157
-rw-r--r--CST116F2021-Lab5/Main_header.h28
4 files changed, 451 insertions, 14 deletions
diff --git a/CST116F2021-Lab5/CONSOLE OUTPUT.txt b/CST116F2021-Lab5/CONSOLE OUTPUT.txt
new file mode 100644
index 0000000..df2759f
--- /dev/null
+++ b/CST116F2021-Lab5/CONSOLE OUTPUT.txt
@@ -0,0 +1,116 @@
+This file contains the console output for each program.
+
+10.5 LBD-Ex #1:
+
+Enter score #1 of 10: 99.54
+Score: 99.54 Grade: A
+Enter score #2 of 10: 73.85
+Score: 73.85 Grade: D
+Enter score #3 of 10: 68.76
+Score: 68.76 Grade: D
+Enter score #4 of 10: 82.47
+Score: 82.47 Grade: C
+Enter score #5 of 10: 63.98
+Score: 63.98 Grade: F
+Enter score #6 of 10: 87.61
+Score: 87.61 Grade: B
+Enter score #7 of 10: 85.0
+Score: 85 Grade: B
+Enter score #8 of 10: 52.84
+Score: 52.84 Grade: F
+Enter score #9 of 10: 96.2
+Score: 96.2 Grade: A
+Enter score #10 of 10: 84.15
+Score: 84.15 Grade: B
+
+The average score is: 79.44%
+Distribution of achieved grades:
+A: 2
+B: 3
+C: 1
+D: 2
+F: 2
+
+C:\Users\jorda\Source\Repos\cst116-lab5-JordanHT-OIT\Debug\CST116F2021-Lab5.exe (process 1424) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+
+10.6 LBD-Ex #1:
+
+Enter score #1 of 10: 99
+Enter score #2 of 10: 94.65
+Enter score #3 of 10: 91.24
+Enter score #4 of 10: 58.23
+Enter score #5 of 10: -65
+
+Error: Score cannot be negative
+Enter score #5 of 10: 65.0
+Enter score #6 of 10: 79.23
+Enter score #7 of 10: 80.234
+Enter score #8 of 10: 23.5
+Enter score #9 of 10: 83.7
+Enter score #10 of 10: 94.3
+
+The average score is: 76.9084
+The number of assigned grades are as follows: A - 3, B - 1, C - 3, D - 1, F - 2
+The individual scores are as follows:
+Student 1 scored 99 (A)
+Student 2 scored 94.65 (A)
+Student 3 scored 91.24 (B)
+Student 4 scored 58.23 (F)
+Student 5 scored 65 (D)
+Student 6 scored 79.23 (C)
+Student 7 scored 80.234 (C)
+Student 8 scored 23.5 (F)
+Student 9 scored 83.7 (C)
+Student 10 scored 94.3 (A)
+
+C:\Users\jorda\Source\Repos\cst116-lab5-JordanHT-OIT\Debug\CST116F2021-Lab5.exe (process 10688) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+
+10.7 LBD-Ex #2
+
+Please enter your first name: Jordan
+Please enter your last name: Harris-Toovy
+
+Your full name is: Jordan, Harris-Toovy
+
+C:\Users\jorda\Source\Repos\cst116-lab5-JordanHT-OIT\Debug\CST116F2021-Lab5.exe (process 1176) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+
+10.8 Ex #7
+
+---[Run 1]---
+
+Please enter a string (alphanumeric and +-,.): Hello!
+Please enter another string: Hello!
+
+Enter the number of characters to compair (left to right): 5
+
+The first 5 characters match.
+
+C:\Users\jorda\Source\Repos\cst116-lab5-JordanHT-OIT\Debug\CST116F2021-Lab5.exe (process 1792) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+---[Run 2]---
+
+Please enter a string (alphanumeric and +-,.): THIS_IS_A_TEST
+Please enter another string: THIS_IS_A_DIFFERENCE
+
+Enter the number of characters to compair (left to right): 12
+
+There is a mismatch within the fisrt 12 characters.
+
+C:\Users\jorda\Source\Repos\cst116-lab5-JordanHT-OIT\Debug\CST116F2021-Lab5.exe (process 10840) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.cpp b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
index e7591f7..53991b1 100644
--- a/CST116F2021-Lab5/CST116F2021-Lab5.cpp
+++ b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
@@ -1,20 +1,156 @@
-// CST116F2021-Lab5.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
+//Code by Jordan Harris-Toovy for OIT's CST116 Lab 5, November 2021
-#include <iostream>
+//NOTE: When evaluating code, please keep in mind that global vars have been moved the header file.
-int main()
+#include "Main_header.h"
+
+//10.5 LBD-Ex #1
+
+/*
+int main(void)
{
- std::cout << "Hello World!\n";
+ float student_score[NUM_SCORES] = {0.0F}, class_avarage = 0.0F;
+ char student_grade[NUM_SCORES] = {'X'};
+ int total_scores[NUM_GRADES] = { 0 };
+
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ cout << "Enter score #" << idx + 1 << " of " << NUM_SCORES << ": ";
+ cin >> student_score[idx];
+
+ if (student_score[idx] >= 92.0F)
+ {
+ student_grade[idx] = 'A';
+ total_scores[0]++;
+ }
+ else if (student_score[idx] >= 84.0F)
+ {
+ student_grade[idx] = 'B';
+ total_scores[1]++;
+ }
+ else if (student_score[idx] >= 75.0F)
+ {
+ student_grade[idx] = 'C';
+ total_scores[2]++;
+ }
+ else if (student_score[idx] >= 65.0F)
+ {
+ student_grade[idx] = 'D';
+ total_scores[3]++;
+ }
+ else if (student_score[idx] >= 0.0F)
+ {
+ student_grade[idx] = 'F';
+ total_scores[4]++;
+ }
+ else
+ {
+ cout << endl << "Score error" << endl;
+ return -1;
+ }
+
+ cout << "Score: " << student_score[idx] << " Grade: " << student_grade[idx] << endl;
+
+ class_avarage += student_score[idx];
+
+ }
+
+ class_avarage /= NUM_SCORES;
+
+ cout << endl << "The average score is: " << class_avarage << "%" << endl;
+ cout << "Distribution of achieved grades:" << endl << "A: " << total_scores[0] << endl << "B: " << total_scores[1]
+ << endl << "C: " << total_scores[2] << endl << "D: " << total_scores[3] << endl << "F: " << total_scores[4] << endl;
+
+ return 0;
+}
+*/
+
+
+//10.6 LBD-Ex #1 INCOMPLETE
+
+/*
+int main(void)
+{
+ float student_score[NUM_SCORES] = { 0.0F }, class_avarage = 0.0F;
+ char student_grade[NUM_SCORES] = { 'X' };
+ int total_scores[NUM_GRADES] = { 0 };
+
+ get_scores(student_score);
+
+ grade_scores(student_score, student_grade);
+
+ total_grades(student_grade, total_scores);
+
+ class_avarage = average_scores(student_score);
+
+ display_info(class_avarage, total_scores, student_grade, student_score);
+
+ return 0;
}
+*/
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
-// 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
+//10.7 LBD-Ex #2 (Mislabeled as "9.5 LBD-Ex #2")
+
+/*
+int main(void)
+{
+ char firstName[NAMELENGTHMAX]{}, lastName[NAMELENGTHMAX]{}, totalName[NAMELENGTHMAX * 2]{};
+ int firstSize = 0, lastSize = 0;
+
+ getName(firstName, 0);
+ getName(lastName, 1);
+
+ firstSize = getStringSize(firstName);
+ lastSize = getStringSize(lastName);
+
+ for (int idx = 0; idx < firstSize; idx++)
+ {
+ totalName[idx] = firstName[idx];
+ }
+
+ totalName[firstSize] = ',';
+ totalName[firstSize + 1] = ' ';
+
+ for (int idx = 0; idx < lastSize; idx++)
+ {
+ totalName[firstSize + 2 + idx] = lastName[idx];
+ }
+
+ totalName[firstSize + 3 + lastSize] = '\0';
+
+ cout << "\nYour full name is: " << totalName <<endl;
+
+ return 0;
+}
+*/
+
+
+//10.8 Ex #7 (Mislabeled as "9.6 LBD-Ex #7")
+
+/*
+int main(void)
+{
+ char string_1[25] = "X", string_2[25] = "X";
+ bool compair = true;
+ int num_compair = 1;
+
+ get_string(string_1, 0);
+ get_string(string_2, 1);
+
+ cout << "\nEnter the number of characters to compair (left to right): ";
+ cin >> num_compair;
+
+ compair = string_compair_N(string_1, string_2, num_compair);
+
+ if (compair)
+ {
+ cout << "\nThe first " << num_compair << " characters match." << endl;
+ }
+ else
+ {
+ cout << "\nThere is a mismatch within the fisrt " << num_compair << " characters." << endl;
+ }
+ return (0);
+}
+*/ \ No newline at end of file
diff --git a/CST116F2021-Lab5/External_functions.cpp b/CST116F2021-Lab5/External_functions.cpp
new file mode 100644
index 0000000..b455792
--- /dev/null
+++ b/CST116F2021-Lab5/External_functions.cpp
@@ -0,0 +1,157 @@
+//This file contains all of the functions in the project. Code by Jordan Harris-Toovy, November 2021
+
+#include "Main_header.h"
+
+//10.6 LBD-Ex #1
+void get_scores(float storage[])
+{
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ while (storage[idx] <= 0)
+ {
+ cout << "Enter score #" << idx + 1 << " of " << NUM_SCORES << ": ";
+ cin >> storage[idx];
+ if (storage[idx] < 0)
+ {
+ cout << "\nError: Score cannot be negative\n";
+ }
+ }
+ }
+}
+
+void grade_scores(float score[], char grade[])
+{
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ if (score[idx] >= 92.0F)
+ {
+ grade[idx] = 'A';
+ }
+ else if (score[idx] >= 84.0F)
+ {
+ grade[idx] = 'B';
+ }
+ else if (score[idx] >= 75.0F)
+ {
+ grade[idx] = 'C';
+ }
+ else if (score[idx] >= 65.0F)
+ {
+ grade[idx] = 'D';
+ }
+ else
+ {
+ grade[idx] = 'F';
+ }
+ }
+}
+
+void total_grades(char grades[], int grade_total[])
+{
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ switch (grades[idx])
+ {
+ case 'A':
+ grade_total[0]++;
+ break;
+ case 'B':
+ grade_total[1]++;
+ break;
+ case 'C':
+ grade_total[2]++;
+ break;
+ case 'D':
+ grade_total[3]++;
+ break;
+ case 'F':
+ grade_total[4]++;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+float average_scores(float scores[])
+{
+ float total = 0.0F;
+
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ total += scores[idx];
+ }
+
+ return (total / NUM_SCORES);
+}
+
+void display_info(float& avg, int total_grades[], char grades[], float scores[])
+{
+ cout << endl << "The average score is: " << avg << endl << "The number of assigned grades are as follows: ";
+ cout << "A - " << total_grades[0] << ", B - " << total_grades[1] << ", C - " << total_grades[2]
+ << ", D - " << total_grades[3] << ", F - " << total_grades[4] << endl;
+ cout << "The individual scores are as follows: " << endl;
+ for (int idx = 0; idx < NUM_SCORES; idx++)
+ {
+ cout << "Student " << idx + 1 << " scored " << scores[idx] << " (" << grades[idx] << ")\n";
+ }
+}
+
+
+//10.7 LBD-Ex #2
+void getName(char name[], int nameMode = 0)
+{
+ if (nameMode == 0)
+ {
+ cout << "Please enter your first name: ";
+ cin >> name;
+ }
+ else if (nameMode == 1)
+ {
+ cout << "Please enter your last name: ";
+ cin >> name;
+ }
+ else
+ {
+ cout << "\nERROR: INVALID getName MODE\n" << endl;
+ }
+}
+
+int getStringSize(char string[])
+{
+ int idx = 0;
+ while (string[idx] != '\0')
+ {
+ idx++;
+ }
+ return idx;
+}
+
+
+//10.8 Ex #7
+void get_string(char user_string[], int mode)
+{
+ if (mode == 0)
+ {
+ cout << "Please enter a string (alphanumeric and +-,.): ";
+ }
+ else
+ {
+ cout << "Please enter another string: ";
+ }
+ cin >> user_string;
+ //BUG: some characters, such as the space character, will act as delimiters, causing cin to pickup two strings instantly.
+}
+
+bool string_compair_N(char str1[], char str2[], int num_cmp)
+{
+ bool result = true;
+ for (int idx = 0; idx < num_cmp; idx++)
+ {
+ if (str1[idx] != str2[idx])
+ {
+ result = false;
+ }
+ }
+ return result;
+} \ No newline at end of file
diff --git a/CST116F2021-Lab5/Main_header.h b/CST116F2021-Lab5/Main_header.h
new file mode 100644
index 0000000..b5fbf4e
--- /dev/null
+++ b/CST116F2021-Lab5/Main_header.h
@@ -0,0 +1,28 @@
+//This is the main header file for the project. Code by Jordan Harris-Toovy, November 2021
+
+#pragma once
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+//10.5 LBD-Ex #1 & 10.6 LBD-Ex #1
+const int NUM_SCORES = 10;
+const int NUM_GRADES = 5;
+
+//10.6 LBD-Ex #1
+void get_scores(float[]);
+void grade_scores(float[], char[]);
+void total_grades(char[], int[]);
+float average_scores(float[]);
+void display_info(float&, int[], char[], float[]);
+
+//10.7 LBD-Ex #2
+const int NAMELENGTHMAX = 20;
+
+void getName(char[], int);
+int getStringSize(char[]);
+
+//10.8 Ex #7
+void get_string(char[], int);
+bool string_compair_N(char[], char[], int); \ No newline at end of file