In: Computer Science
I need to convert the following into C++. The general idea is to
create an application that can support 10 ID's and 10 grades. It
needs to calculate the grade average of said ID, and determine if
it is an below or above a certain average, ergo A or C.
string[10] studentIDArray
int[10] gradeArray
int averageGrade
for(int i = 0; i < gradeArray; i++)
{
averageGrade += gradeArray[i]
}
averageGrade = averageGrade / sizeof(gradeArray)
for(int i = 0; i < studentIDArray; i++){
if(gradeArray[i] > averageGrade)
{
Output: studentIDArray[i] gradeArray[i] grade is A
}
else
{
Output: studentIDArray[i] gradeArray[i] grade is C
}
}
#include <iostream>
using namespace std;
int main()
{
// assign with default to test
string studentIDArray[10]={"101","102","103","104","105","106","107","108","109","110"};
// assign with default to test
int gradeArray[10] =
{1,2,3,4,5,6,7,8,9,10};
double averageGrade; // since average is double
for(int i = 0; i < 10; i++)
{
averageGrade +=
gradeArray[i];
}
averageGrade = averageGrade /
(sizeof(gradeArray)/sizeof(gradeArray[0])); // divide by size
for(int i = 0; i < 10; i++){
if(gradeArray[i] >
averageGrade)
{
// print id grade grades got
cout<<studentIDArray[i]<<" "<<gradeArray[i]
<<" grade is A"<<endl;
}
else
{
cout<<studentIDArray[i]<<"
"<<gradeArray[i]<<" grade is C"<<endl;
}
}
return 0;
}
/* OUTPUT */
/* PLEASE UPVOTE */