Question: Change this C++ code to C, using printf instead of cout, just to mention one of the things that should be modified. In the C++

Change this C++ code to C, using printf instead of cout, just to mention one of the things that should be modified.

In the C++ below, we created a class student with rollno, name, marks and grade as its data members and three member functions: getdata(i): to read details of the student i. calgrade() calculates the letter grade of the student according to marks entered using a series of if conditions. And a display(i) function that displays details of student i.

In the main() function, we create an array of student objects. Then ask the user to enter number of students.

Then using a while loop , call the getdata() and calgrade() functions for those students.Then using another while loop, call the display function to display details of those students.

CODE:

#include

using namespace std;

class Student{

private:

int rollno;

string name;

int marks;

char grade;

public:

void getdata(int i) //to read student details

{

cout<<" Enter details of student "<

cout<<"Roll number: ";

cin>>rollno;

cout<<"Name: ";

cin>>name;

cout<<"Marks: ";

cin>>marks;

}

void calgrade() //to calculate grade

{ //assignoing grades according to marks

if(marks >= 90)

grade = 'A';

else if(marks<90 && marks>=80)

grade = 'B';

else if(marks<80 && marks>=70)

grade = 'C';

else if(marks<70 && marks>=60)

grade = 'D';

else if(marks<60 )

grade = 'F';

}

void display(int i) //displaying student details

{

cout<<" Student "<

cout<<" Roll number: "<

cout<<" Name: "<

cout<<" Marks: "<

cout<<" Grade: "<

}

};

int main()

{

int num;

Student s[10]; //creating array of student objects

cout<<"Enter number of students: ";

cin>>num; //reading number of students

int i=0;

while(i

{ //caliing functions to read details and calculate grade

s[i].getdata(i+1);

s[i].calgrade();

i++; //next student

}

i=0;

cout<<" Students' Details: ";

while(i

{

//calling function to show details of students

s[i].display(i+1);

i++;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!