This Cpp program is for Displaying the details of Students with Structures. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA.
Structures are used to store a collection of different types of data types. Structure in C++ or Cpp is a precursor of a Class. Here we have used an array of Structures to Store the Details of Students and Display them. 'Struct' is the keyword we need to use to declare a structure.
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[20];
int roll;
int age;
char sex;
int height;
}s[20];
void main()
{
int i,n,a;
clrscr();
cout<<"How many records do u want to enter : ";
cin>>n;
for(i=0;i<n;i++)
{
name:
cout<<"\n\nEnter Name For Student "<<i+1<<" : ";
cin>>s[i].name;
roll:
cout<<"Enter Roll Number for Student "<<i+1<<" : ";
cin>>s[i].roll;
if(s[i].roll<1 || s[i].roll>30)
{
cout<<"The Limit Exceeds"<<endl;
goto roll;
}
age:
cout<<"Enter Age for Student "<<i+1<<" : ";
cin>>s[i].age;
if(s[i].age<18 || s[i].age>25)
{
cout<<"The Limit Exceeds"<<endl;
goto age;
}
sex:
cout<<"Enter Sex for Student "<<i+1<<" : ";
cin>>s[i].sex;
if(s[i].sex=='F' || s[i].sex=='M') {}
else
{
cout<<"Enter correct Sex"<<endl;
goto sex;
}
height:
cout<<"Enter Height for Student "<<i+1<<" : ";
cin>>s[i].height;
if(s[i].height<50 || s[i].height>250)
{
cout<<"The Limit Exceeds"<<endl;
goto height;
}
}
cout<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<"-----Student "<<i+1<<"-----"<<endl;
cout<<"Name :"<<s[i].name<<endl;
cout<<"Roll No. :"<<s[i].roll<<endl;
cout<<"Age :"<<s[i].age<<endl;
cout<<"Sex :"<<s[i].sex<<endl;
cout<<"Height :"<<s[i].height<<endl;
cout<<endl<<endl;
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.
Structures are used to store a collection of different types of data types. Structure in C++ or Cpp is a precursor of a Class. Here we have used an array of Structures to Store the Details of Students and Display them. 'Struct' is the keyword we need to use to declare a structure.
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[20];
int roll;
int age;
char sex;
int height;
}s[20];
void main()
{
int i,n,a;
clrscr();
cout<<"How many records do u want to enter : ";
cin>>n;
for(i=0;i<n;i++)
{
name:
cout<<"\n\nEnter Name For Student "<<i+1<<" : ";
cin>>s[i].name;
roll:
cout<<"Enter Roll Number for Student "<<i+1<<" : ";
cin>>s[i].roll;
if(s[i].roll<1 || s[i].roll>30)
{
cout<<"The Limit Exceeds"<<endl;
goto roll;
}
age:
cout<<"Enter Age for Student "<<i+1<<" : ";
cin>>s[i].age;
if(s[i].age<18 || s[i].age>25)
{
cout<<"The Limit Exceeds"<<endl;
goto age;
}
sex:
cout<<"Enter Sex for Student "<<i+1<<" : ";
cin>>s[i].sex;
if(s[i].sex=='F' || s[i].sex=='M') {}
else
{
cout<<"Enter correct Sex"<<endl;
goto sex;
}
height:
cout<<"Enter Height for Student "<<i+1<<" : ";
cin>>s[i].height;
if(s[i].height<50 || s[i].height>250)
{
cout<<"The Limit Exceeds"<<endl;
goto height;
}
}
cout<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<"-----Student "<<i+1<<"-----"<<endl;
cout<<"Name :"<<s[i].name<<endl;
cout<<"Roll No. :"<<s[i].roll<<endl;
cout<<"Age :"<<s[i].age<<endl;
cout<<"Sex :"<<s[i].sex<<endl;
cout<<"Height :"<<s[i].height<<endl;
cout<<endl<<endl;
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.
No comments:
Post a Comment