Using visual studio Design and develop a C++ program for reporting grades for a
ID: 3571746 • Letter: U
Question
Using visual studio
Design and develop a C++ program for reporting grades for a class. Your program should read in an input file of student grades records, and it should produce an output file of student grades records plus a report (output to monitor) of grade distributions. Your program would read in the records from the file one record at a time (sequentially) and output one record at a time to the output file, it update an array of grades. After building the array of grades, then it processes the array to print the grade distributions histogram. The program will also build array each student score in the class and then sort it (use bubble sort) then out put the LOWEST SCORE IN CLASS, HIGHEST SCORE IN CLASS, and NUMBER OF STUDENTS.
Explanation / Answer
Hey heres the code, can you explain about input file, like hows its format going to be. If you can be explicit about it , I will do the remaining code too. So far this program reads input marks converts them to integers and finds for maximum and minimum marks.
Source code:
#include <fstream>
#include <iostream>
using namespace std;
int power(int k,int n)
{
if(n==0)
return 1;
if(n==1 )
return k;
int t=k;
for(int i=2;i<=n;i++)
{
t=t*k;
}
return t;
}
int getNum(int arr[],int length)
{
int j=0;
int total=0;
for(int i=length;i>0;i--)
{
total=total + power(10,i-1)*arr[j];
j++;
}
return total;
}
int getMin(int arr[],int n)
{
int min=arr[0];
for(int i=1;i<n;i++)
{
if(min>arr[i])
{
min =arr[i];
}
}
return min;
}
int getMax(int arr[],int n)
{
int max=arr[0];
for(int i=1;i<n;i++)
{
if(max<arr[i])
{
max=arr[i];
}
}
return max;
}
int main () {
ifstream in;
in.open("inputfile.txt");
char c;
int i=0,count=0;
int num[100];
int marks[1000];
while(in.good()) {
if(isdigit(c))
{
num[i]=int(c)-48;
i++;
}
if(c==' ')
{
cout<<c;
marks[count]=getNum(num,i);
i=0;
cout<<marks[count];
count++;
}
in.get(c);
}
in.close();
int min =getMin(marks,count);
int max =getMax(marks,count);
return 0;
}
So far the above code reads file and converts numbers to integers and stores them in marks array thats the main part.
Now when you said input and output format you confused me. Output format is already given that is to print lowest marks and highest marks.. so on. So it is input format i was asking.
Here if input is EXAM01:100 which says that marks of exam01 is 100, since this represented without any spaces in between you need to take that as entire string and divide on basis of delimiter i.e. colon ( : )
After separating into two strings you will check for conditions as below:
suppose one sub string is s1 and other sub string is s2:
if(s1=="Exam01" )
marks1[ i ] = s2;
else if(s1=="Exam02")
marks2[ i ]= s2;
else if (s1=="Exam03")
marks3[ i ]= s2;
else if(s1=="Exam04")
marsk4[ i ] =s2;
And you might have to calculate lowest marks in exam1 or exam2... in which you can use arrays marks1[ ],marks2[ ] so on in the functions getMin() and for highest in getMax(marks1[ ])......So now you can make changes and use the same functions.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.