diff options
| author | James Lawrance <[email protected]> | 2021-10-30 09:24:59 -0700 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-10-30 09:24:59 -0700 |
| commit | 0893882a2c5c432bb1ccd17258460a55dae9f08a (patch) | |
| tree | 779b993e163469811044bb2f64ee681160363e25 | |
| parent | Lab 5 changes night class 10/27 (diff) | |
| download | cst116-lab5-jemersonlawrance-0893882a2c5c432bb1ccd17258460a55dae9f08a.tar.xz cst116-lab5-jemersonlawrance-0893882a2c5c432bb1ccd17258460a55dae9f08a.zip | |
Morning Class Changes 10/30/21 up to 10a
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5(2).cpp | 42 | ||||
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5(Header).h | 9 | ||||
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5.cpp | 240 | ||||
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5.vcxproj | 4 | ||||
| -rw-r--r-- | CST116F2021-Lab5/CST116F2021-Lab5.vcxproj.filters | 8 | ||||
| -rw-r--r-- | TextFile1.txt | 9 |
6 files changed, 198 insertions, 114 deletions
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp b/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp new file mode 100644 index 0000000..343789c --- /dev/null +++ b/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp @@ -0,0 +1,42 @@ +#include "CST116F2021-Lab5(Header).h" + +//function getName definition +void getName(char first[], char last[]) +{ + cout << "Please enter your first name: "; + cin >> first; + cout << "Please enter your last name: "; + cin >> last; +} + +//function formatName definition +void formatName(char first[], char last[]) +{ + //defining local array and counter variable + char fullName[32] = {}; + int letterCount = 0; + int letterCountOffset = 0; + //copy first to fullName character by character + while (last[letterCount] != '\0') + { + fullName[letterCount] = last[letterCount]; + letterCount++; + letterCountOffset++; + } + //add comma and space to fullName after first + fullName[letterCount] = ','; + letterCount++; + letterCountOffset++; + + fullName[letterCount] = ' '; + letterCount++; + letterCountOffset++; + //copy last to fullName character by character + while (first[letterCount-letterCountOffset] != '\0') + { + fullName[letterCount] = first[letterCount-letterCountOffset]; + letterCount++; + } + + cout << fullName; +}
\ No newline at end of file diff --git a/CST116F2021-Lab5/CST116F2021-Lab5(Header).h b/CST116F2021-Lab5/CST116F2021-Lab5(Header).h new file mode 100644 index 0000000..86cdb62 --- /dev/null +++ b/CST116F2021-Lab5/CST116F2021-Lab5(Header).h @@ -0,0 +1,9 @@ +#pragma once + +#include <iostream> +using namespace std; + +//function getName prototype +void getName(char first[], char last[]); +//function formatName prototype +void formatName(char first[], char last[]);
\ No newline at end of file diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.cpp b/CST116F2021-Lab5/CST116F2021-Lab5.cpp index 27794e9..c1b57ec 100644 --- a/CST116F2021-Lab5/CST116F2021-Lab5.cpp +++ b/CST116F2021-Lab5/CST116F2021-Lab5.cpp @@ -1,6 +1,4 @@ -#include <iostream> -using namespace std; - +#include "CST116F2021-Lab5(Header).h" //9a - //Section 10.5 - @@ -97,126 +95,142 @@ using namespace std; //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[]); +//void getScores(int studentScores[]); +//void calculateGrades(int studentScores[], char studentGrades[]); +//void displayGrades(char studentGrades[]); +//void classAverage(int studentScores[]); +//void studentsPerGrade(char studentGrades[]); -int main() -{ +//int main() +//{ //defining - int studentScores[10]; - char studentGrades[10]; +// int studentScores[10]; +// char studentGrades[10]; //entry sequence - cout << "Welcome to the 10 scores to grades program." << endl; +// cout << "Welcome to the 10 scores to grades program." << endl; //get scores - cout << endl; - getScores(studentScores); +// cout << endl; +// getScores(studentScores); //calculate grades - calculateGrades(studentScores, studentGrades); +// calculateGrades(studentScores, studentGrades); //display grades - cout << endl; - displayGrades(studentGrades); +// cout << endl; +// displayGrades(studentGrades); //display class average - cout << endl; - classAverage(studentScores); +// cout << endl; +// classAverage(studentScores); //display students per grade - cout << endl; - studentsPerGrade(studentGrades); +// cout << endl; +// studentsPerGrade(studentGrades); - return 0; -} +// return 0; +//} -void getScores(int studentScores[]) -{ - for (int scoreCount = 0; scoreCount < 10; scoreCount++) - { - cout << "Please enter student " << scoreCount + 1 << "'s score: "; - cin >> studentScores[scoreCount]; - } -} - -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 getScores(int studentScores[]) +//{ +// for (int scoreCount = 0; scoreCount < 10; scoreCount++) +// { +// cout << "Please enter student " << scoreCount + 1 << "'s score: "; +// cin >> studentScores[scoreCount]; +// } +//} -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[]) +//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++; +// } +// } + +// 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; +//} + +//10a +//9.4 Learn by Doing Exercises (this problem will be broken into 3 files) + +int main() { - 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; + //defining arrays + char firstName[15] = {}; + char lastName[15] = {}; + //get firstName and lastName (call function getName) + getName(firstName, lastName); + //format full name (call function formatName) + formatName(firstName, lastName); + + return 0; }
\ No newline at end of file diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj b/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj index 14ee2b7..68edfb3 100644 --- a/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj +++ b/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj @@ -140,6 +140,10 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="CST116F2021-Lab5.cpp" /> + <ClCompile Include="CST116F2021-Lab5%282%29.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="CST116F2021-Lab5%28Header%29.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj.filters b/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj.filters index c9f2fd4..2ebb34c 100644 --- a/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj.filters +++ b/CST116F2021-Lab5/CST116F2021-Lab5.vcxproj.filters @@ -18,5 +18,13 @@ <ClCompile Include="CST116F2021-Lab5.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="CST116F2021-Lab5%282%29.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="CST116F2021-Lab5%28Header%29.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/TextFile1.txt b/TextFile1.txt index 911235a..d8685d7 100644 --- a/TextFile1.txt +++ b/TextFile1.txt @@ -67,4 +67,11 @@ Class average: 62.6 1 students got B's 1 students got C's 2 students got D's -4 students got F's
\ No newline at end of file +4 students got F's + +10a - +9.4 Learn by Doing Exercises output - + +Please enter your first name: James +Please enter your last name: Lawrance +Lawrance, James
\ No newline at end of file |