Computers and Technology
Computers and Technology, 18.02.2021 21:20, shmote12

Consider the following C++ program that makes use of many features that are unique to C++ and did not exist in C. #include #include #include #include
using namespace std;
enum LetterGrade { A = 4,
B = 3, C = 2, D = 1, F=0
};
// type T must be castable into a double template
double getArrayAverage(vector& vec) {
double sum = 0;
for (const auto& value : vec) {
sum += static_cast(value); }
const auto avg = sum / vec. size();
return avg; }
void convertCharToLetterGrade(char& grade) { switch (grade) {
case 'A': case 'a': grade = 4;
return;
case 'B': case 'b':
grade = 3;
return;
case 'C': case 'c':
grade = 2;
return;
case 'D': case 'd':
grade = 1;
return;
case 'F': case 'f':
grade = 0; return;
} }
LetterGrade if (avg
default:
cout << "Warning... Invalid Character... Recording an F.\n"; return;
(const double avg) {
>= 90)
return LetterGrade::A;
else if (avg >= 80) return LetterGrade::B;
else if (avg >= 70) return LetterGrade::C;
else if (avg >= 60) return LetterGrade::D;
else
return LetterGrade::F;
}
int main() {
string firstName;
cout << "Please enter your cin >> firstName;
string lastName;
cout << "Please enter your cin >> lastName;
first name: ";
last name: ";
int32_t numPrevCourses;
cout << "Enter number of previous courses: ";
cin >> numPrevCourses;
cin. ignore();
vector prevGrades(numPrevCourses);
for (int32_t courseIx = 0; courseIx < numPrevCourses; ++courseIx) {
cout << "Enter letter grade for course " << courseIx << ": "; char letterGrade;
cin. get(letterGrade);
cin. ignore();
convertCharToLetterGrade(letterGrad e);
prevGrades. at(courseIx) = static_cast(letterGrade); }
int32_t numEx; // (Exam)
cout << "Enter number of test this semester: "; cin >> numEx;
cin. ignore();
vector exGrades(numEx);
for (int32_t exIx = 0; exIx < numEx; ++exIx) {
cout << "Enter grade " << exIx << " as an integer: "; cin >> exGrades. at(exIx) ;
cin. ignore();
}
const auto fullName = firstName + " " + lastName;
cout << "Grade Report For " << fullName << ":\n";
const auto exAverage = getArrayAverage(exGrades); cout << "Your average is: " << exAverage << "\n";
// get GPA with newest course added:
const auto newLetterGrade = (exAverage); prevGrades. push_back(newLetterGrade);
const auto gpa = getArrayAverage(prevGrades);
cout << "Your latest GPA is: " << gpa << "\n";
return 0;
}
Please rewrite this program in pure C and without any C++ elements. You may use any compiler that you would like, but your program cannot have any C++ features. A few extra notes:1. If the C++ code uses dynamic allocation, then your C version also must use dynamic allocation.2. You may not change the primitive data types used (e. g., do not convert ints to doubles just so you can avoid dealing with the workaround for the function overloading). Once you finish writing your program, please write a brief report (no more than a few paragraphs) describing features in the above program that are in C++ and not in C and the different work-arounds you had to come up with in order to achieve the same functionality. Please feel free to elaborate on the aspects of the C program that were difficult to implement.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 18:30, Svetakotok
Ineed on my history if anyone can check out the last few questions i posted and i will be posting !
Answers: 2
image
Computers and Technology, 21.06.2019 23:00, xxbriannahollandxx
In a file-oriented information system, a work file stores relatively permanent data about an entity is created and saved for backup and recovery purposes stores records that contain day-to-day business and operational data is a temporary file created by an information system for a single task
Answers: 1
image
Computers and Technology, 22.06.2019 00:20, kcameronanderso
What’s resistance in an electrical circuit ?
Answers: 1
image
Computers and Technology, 22.06.2019 21:00, mazolethrin9632
Which of these is most responsible for differences between the twentieth century to the twenty-first century?
Answers: 2
Do you know the correct answer?
Consider the following C++ program that makes use of many features that are unique to C++ and did no...

Questions in other subjects: