Write C++ Program that obtains several number of students’ info and displays it to
the console. Define a structure Student, structure data members char ID[15], char
grade.
//This code tested with online compiler LUNIX OS **and Working all OS
#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
//Define a structure for Student
struct Student
{
char ID[15];//Unique ID of Student
char grade;//A-F or 2-5
};
//Define function Print Data of Students
void PrintStudent(Student* st)
{
cout<<"|"<<setw(15)<<st->ID<<"|"<<st->grade<<"|\n";
}
//Define a function for Input data for Student
void InputData(Student*st)
{
cout<<"Input ID:";
cin>>st->ID;
cout<<"Input grade:";
cin>>st->grade;
}
int main()
{
int size;
cout<<"Number of Students:";
cin>>size;
Student *st=new Student[size];//Array of Students
for(int i=0;i<size;i++)
{
InputData(&st[i]);
}
cout<<"*********************************************\n\n";
cout<<"|+++++++++++++++|+|\n";
cout<<"| ID |G|\n";
cout<<"|+++++++++++++++|+|\n";
for(int i=0;i<size;i++)
{
PrintStudent(&st[i]);
}
cout<<"|+++++++++++++++|+|\n";
return 0;
}
Comments
Leave a comment