I've finished my assignment in C. But I learned I'm supposed to submit a C++ file. Now I'm trying to convert my program to C++. All I could do is change #include<stdio.h> and #include<stdlib.h> with #include <iostream> and #include <cstdlib>. I learned that C++ codes are able to read C codes too, so I didn't change the code part of my program. But when I compile, I get many errors. While I was working on C file, I didn't get any error and the program worked perfectly. What's wrong in my codes as they're in C++? Any help will be greatly appreciated. Here it is:
Code:
#include <iostream>
#include <cstdlib>
struct Student
{
char name[20], lettergrade;
int id, testgrades[10];
int average;
int total;
};
struct Student Stud[81];
void getinfo(int size, struct Student Stud[size]);
double calculateGrade(int siz, struct Student Stud[siz]);
void display(int si, struct Student Stud[si]);
int k,s,t,r,g;
int a[81]={0};
int main(int argc, char *argv[])
{
printf("Enter the number of students:");
scanf("%i", &s);
printf("\n");
printf("Enter the number of tests:");
scanf("%i", &t);
printf("\n");
getinfo(81, Stud);
system("PAUSE");
return 0;
}
void getinfo(int siz, struct Student Stud[siz])
{
for(k=1; k<=s; k++){
printf("Enter %i. student name:", k);
scanf("%20s", Stud[k].name);
printf("\n");
printf("Enter %i. student id:", k);
scanf("%i", &Stud[k].id);
printf("\n");
for(g=1; g<=t; g++){
printf("Enter %i. test:", g);
scanf("%i", &Stud[k].testgrades[g]);
printf("\n");
};
calculateGrade(81, Stud);
display(81, Stud);
};
}
double calculateGrade(int siz, struct Student Stud[siz])
{
for(r=1; r<=t; r++){
Stud[k].total=Stud[k].total+Stud[k].testgrades[r] ; };
a[k]=(Stud[k].total)/t ;
if( a[k] <= 100 && a[k] >= 85)
Stud[k].lettergrade='A';
if(a[k]<85 && a[k]>=75)
Stud[k].lettergrade='B';
if(a[k]<75 && a[k]>=65)
Stud[k].lettergrade='C';
if(a[k]<65 && a[k]>=50)
Stud[k].lettergrade='D';
if(a[k]<50 && a[k]>=0)
Stud[k].lettergrade='F';
}
void display(int si, struct Student Stud[si])
{
printf("Average is: %i ", a[k]);
printf("Letter grade is: %c\n", Stud[k].lettergrade);
printf("\n");
}