Write a C++ program to calculate if a student is a Freshman, Sophomore, Junior,
ID: 3768780 • Letter: W
Question
Write a C++ program to calculate if a student is a Freshman, Sophomore, Junior, or Senior. Use the variable intCredits and input the number of credits using a keyboard. Use the following number of credit hours for each class: Freshmabn - below 32, Sophomore - 32, Junior - 64, Senior - 96. Have your program print out if the student is a Freshman, Sophomore, Junior, or Senior. Make sure to include comments in your code. Write a C++ program to calculate if a student is a Freshman, Sophomore, Junior, or Senior. Use the variable intCredits and input the number of credits using a keyboard. Use the following number of credit hours for each class: Freshmabn - below 32, Sophomore - 32, Junior - 64, Senior - 96. Have your program print out if the student is a Freshman, Sophomore, Junior, or Senior. Make sure to include comments in your code. Write a C++ program to calculate if a student is a Freshman, Sophomore, Junior, or Senior. Use the variable intCredits and input the number of credits using a keyboard. Use the following number of credit hours for each class: Freshmabn - below 32, Sophomore - 32, Junior - 64, Senior - 96. Have your program print out if the student is a Freshman, Sophomore, Junior, or Senior. Make sure to include comments in your code.Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main()
{
int studYear = 0, smithCnt = 0, johnCnt = 0;
int year1Cnt = 0, year2Cnt = 0, year3Cnt = 0, year4Cnt = 0;
int mathCnt = 0, CISCnt = 0, totalMathCnt = 0, totalCISCnt = 0;
double average = 0.0, studGpa = 0.0, mathGPASum = 0.0, CISGPASum = 0.0;
string studName, studMajor, studAdvisor, complete;
do
{
cout << "1-Freshman 2-Sophomore 3-Junior 4-Senior ";
cout << "Enter 0 if no more students to input ";
cout << "Enter year in school: ";
cin >> studYear;
if(studYear != 0)
{
if(studYear == 1)
{
year1Cnt++;
}
else if(studYear == 2)
{
year2Cnt++;
}
else if(studYear == 3)
{
year3Cnt++;
}
else
{
year4Cnt++;
}
cout << "Enter Student's name: ";
cin >> studName;
cout << "Math or CIS Major: ";
cin >> studMajor;
cout << "Enter students GPA: ";
cin >> studGpa;
if (studMajor == "Math")
{
mathCnt++;
mathGPASum += studGpa;
totalMathCnt++;
}
else
{
CISCnt++;
CISGPASum += studGpa;
totalCISCnt++;
}
cout << "Enter sutdent advisor(Johnson or Smith): ";
cin >> studAdvisor;
if (studAdvisor[0] == 'J' || studAdvisor[0] == 'j')
{
johnCnt++;
}
else
{
smithCnt++;
}
}
}
while(studYear != 0);
cout << "Year 1 students: " << year1Cnt << endl;
cout << "Year 2 students: " << year2Cnt << endl;
cout << "Year 3 students: " << year3Cnt << endl;
cout << "Year 4 students: " << year4Cnt << endl;
cout << "Johnson has " << johnCnt << " students ";
cout << "Smith has " << smithCnt << " students ";
average = mathGPASum / totalMathCnt;
cout << "Math GPA: " << average << endl;
average = CISGPASum / totalCISCnt;
cout << "CIS GPA: " << average << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.