A program that will accept name,category ,marks for five subjects and a registration number.The registration number must consist of areacode, region code, school code, current year and serial number.


Our aim in this post is to write a simple program that will accept name of the user,category (st/sc/OBc/gen/other) (neglect category if you are not from India ) ,marks for five subject and a registration number.The registration number will consists of areacode , region code , school code ,current year and serial number.To make our program more organized and maintainable we will use two structures:the first structure will hold the registration number codes and the second structure will hold the other information.The first structure will look like this.

 

struct regst_number
{
long areaCode ,
  regionCode ,
  schoolCode ,
  currentYear ,
  serialNumber ;
};

 
The data type is long type because we do not known how long any of the code might be ,so just making sure that we are on the safe side.
 
We are going to make this first structure a data member of the second structure because both of this structures are part of the same problem that we are dealing with.You should note , organising the structure based on the specific problem they are made to handle will make your program easy to maintain and understandable.The second structure is given below.
 

struct data
{
string name ,
  category ;

double marks[5] ;

regst_number reg_no ;
};

 
Now we have the two structures all we need is the main( ) function.The main() function will do nothing but ask the user for their names and all the other information that is required.We will limit the number of users to 10 person.
The full program is shown below.
 

#include <iostream>

using namespace std ;

struct regst_number
{
long areaCode ,
  regionCode ,
  schoolCode ,
  currentYear ,
  serialNumber ;
} ;

struct data
{
string name ,
  category ;

double marks[5] ;

regst_number reg_no ;
} ;

int main( )
{
data arr[10] ;

///Getting the data and registration code for 10 user
for( int i=0 ; i<10 ; i++ )
{
cout<<“Please enter your personal information below \n” ;
cout<<“Name :: ” ;
cin>> arr[i].name ;
cout<< “Category(st/sc/Gen/other)::” ;
cin>> arr[i].category ;

cout<< “\nEnter marks in any five Subjects \n” ;
///Marks in five Subjects
{ //You may or may not add local scope
cout<< ” 1)Science::” ;
cin>> arr[i].marks[0] ;
cout<< ” 2)Math::” ;
cin>> arr[i].marks[1] ;
cout<< ” 3)English::” ;
cin>> arr[i].marks[2] ;
cout<< ” 4)Geography::”;
cin>> arr[i].marks[3] ;
cout<< ” 5)C++::” ;
cin>> arr[i].marks[4] ;
} ///local scope ends here

cout<< “\nEnter your registration number” ;
cout<< ” Area code::” ;
cin>> arr[i].reg_no.areaCode ;
cout<< ” Region code::” ;
cin>> arr[i].reg_no.regionCode ;
cout<< ” School code::” ;
cin>> arr[i].reg_no.schoolCode ;
cout<< ” Current year::”;
cin>> arr[i].reg_no.currentYear ;
cout<< ” Serial number::” ;
cin>> arr[i].reg_no.serialNumber ;

cin.ignore( ) ; ///Do not forget ,this function will ignore the newline key pressed
cout<<“\n\n” ;
} ///for() ends here

cin.get( ) ;
return 0 ;
}

 

 
The screen shot of the console output is shown below.
 
program to print out name marks registration number meant for C++ CBSE student