subject

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.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Which of the following is an example of intellectual properly! oa. new version of a novelb. journal of ideasc. pages of a bookood. lines of a poem
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Knowing that the central portion of link bd has a uniform cross sectional area of 800 mm2 , determine the magnitude of the load p for which the normal stress in link bd is 50 mpa. (hint: link bd is a two-force member.) ans: p = 62.7 kn
Answers: 2
question
Computers and Technology, 23.06.2019 03:00
What are the different parts of computer
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
Which option correctly describes a dbms application? a. software used to manage databases b. software used to organize files and folders c. software used to develop specialized images d. software used to create effective presentations
Answers: 1
You know the right answer?
Consider the following C++ program that makes use of many features that are unique to C++ and did no...
Questions
question
English, 01.01.2021 14:00
question
English, 01.01.2021 14:00
question
Computers and Technology, 01.01.2021 14:00
question
Mathematics, 01.01.2021 14:00
question
Mathematics, 01.01.2021 14:00
question
Mathematics, 01.01.2021 14:00
Questions on the website: 13722362