Answer to Question #331919 in C++ for John

Question #331919

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.


1
Expert's answer
2022-04-21T14:38:15-0400


//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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS