Need code for declaring a structure
Write a program that declares a structure, to store data of a student. The program should define a structure variable, input the values and then display these.
Write a program that declares a structure, to store data of a student. The program should define a structure variable, input the values and then display these.
You can create the structure variable as you can create the data member or variable of a class. The process will be like:
Student s;
s.rno;
s.marks;
and etc
I am very much confused about the concept you are describing. Can you please provide me a simple code in step wise format?
#include<iostream.h>
#include<conio.h>
struct student
{
int RNo;
int marks;
float avg;
char grade;
};
void main()
{
clrscr();
student s;
cout<<”Enter Roll No”;
cin>>s.rno;
cout<<”Enter Marks”;
cin>>s.marks;
cout<<”Enter Average”;
cin>>s.avg;
cout<<”Enter Grade”;
cin>>s.grade;
cout<<”you entered the following details”;
cout<<”Roll No :”<<s.rno<<endl;
cout<<”Marks:”<<s.marks<<endl;
cout<<”Average :”<<s.avg<<endl;
cout<<”Grade :”<<s.grade<<endl;
getch();
}
hello Baigsb,
Here I am subitting a Program regarding your problem ….
#include<iostream.h>
#include<conio.h>
struct student
{
int roll_no;
char name[100];
char clas[3];
}s;
void main()
{
clrscr();
int n;
cout<<"n Enter Roll no.
of student";
cin>>s.roll_no;
cout<<"n Enter name of
the student";
cin>>s.name;
cout<<"n Enter class of
the student";
cin>>s.clas;
cout<<"n n1.Roll no is
"<<s.roll_no;
cout<<"n n2.Name is
"<<s.name;
cout<<"n n3.class is
"<<s.clas;
getch();
}
you can run this program …and you will get your perfect output.