In this post we will write a C++ program to print student details using structure. user will enter the detail of 4 students like his/her name, roll number, math, physics, and c++ subject marks, and then the program will print the details of the students including the Grades.
C++ program to print student details using structure.
#include<iostream>
#include<conio.h>
#include<windows.h>
BOOL gotoxy(const WORD x, const WORD y) {
COORD xy;
xy.X = x;
xy.Y = y;
return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}
struct res
{
int rn;
char name[30];
int math;
int phy;
int c;
};
struct res a[5];
int main()
{
system("cls");
int i;
int total;
int avg;
for(i=0;i<=4;i++)
{
std::cout<<"Name = ";
std::cin>>a[i].name;
std::cout<<"Roll Number = ";
std::cin>>a[i].rn;
std::cout<<"Math Number = ";
std::cin>>a[i].math;
std::cout<<"Physics Number = ";
std::cin>>a[i].phy;
std::cout<<"C++ Number = ";
std::cin>>a[i].c;
}
for(i=0;i<=4;i++)
{
total = a[i].math+a[i].phy+a[i].c;
avg = total/3.0;
gotoxy(20,5+i);
std::cout<<a[i].name<<std::endl;
gotoxy(30,5+i);
std::cout<<a[i].rn<<std::endl;
gotoxy(37,5+i);
std::cout<<a[i].math<<std::endl;
gotoxy(44,5+i);
std::cout<<a[i].phy<<std::endl;
gotoxy(51,5+i);
std::cout<<a[i].c<<std::endl;
gotoxy(58,5+i);
std::cout<<total<<std::endl;
gotoxy(65,5+i);
std::cout<<avg<<std::endl;
if(avg >= 80)
{
gotoxy(73,5+i);
std::cout<<"A"<<std::endl;
}
else if(avg >= 70 && avg <= 79)
{
gotoxy(73, 5+i);
std::cout<<"B"<<std::endl;
}
else if(avg >= 60 && avg <= 69)
{
gotoxy(73,5+i);
std::cout<<"C"<<std::endl;
}
else if(avg >= 50 && avg <= 59)
{
gotoxy(73,5+i);
std::cout<<"C"<<std::endl;
}
else
{
gotoxy(73,5+i);
std::cout<<"Fail"<<std::endl;
}
}
gotoxy(20,4);
std::cout<<"Name"<<std::endl;
gotoxy(30,4);
std::cout<<"Roll"<<std::endl;
gotoxy(37,4);
std::cout<<"Math"<<std::endl;
gotoxy(44,4);
std::cout<<"Phy"<<std::endl;
gotoxy(51,4);
std::cout<<"C++"<<std::endl;
gotoxy(58,4);
std::cout<<"Total"<<std::endl;
gotoxy(65,4);
std::cout<<"Aver"<<std::endl;
gotoxy(73,4);
std::cout<<"Grade"<<std::endl;
getch();
return 0;
}
Output
Name = yashpal Roll Number = 5 Math Number = 50 Physics Number = 70 C++ Number = 80 Name = yash Roll Number = 6 Math Number = 70 Physics Number = 90 C++ Number = 80 Name = rahul Roll Number = 7 Math Number = 80 Physics Number = 80 C++ Number = 80 Name = pooja Roll Number = 8 Math Number = 80 Physics Number = 90 C++ Number = 100 Name = Kajal Roll Number = 9 Math Number = 70 Physics Number = 70 C++ Number = 70 Name Roll Math Phy C++ Total Aver Grade yashpal 5 50 70 80 200 66 C yash 6 70 90 80 240 80 A rahul 7 80 80 80 240 80 A pooja 8 80 90 100 270 90 A kajal 9 70 70 70 210 70 B
0 Comments