Fundamental Programming Concepts

Structure :
- Code: Select all
struct RIU
{
string m_student_name;
int m_cms;
double m_gpa;
};
struct RIU m_class_2014 // single strcuture
struct RIU m_array_of_strucutre[max_student]; // array of strcutures
Data Entery in the arrays of structure using loop statments :
- Code: Select all
for(m_counter=0;m_counter<max_student;m_counter=m_counter+1)
{
cout<<"Value of the Counter "<<m_counter<<endl;
cout<<"Enter Name of the Student "<<endl;
cin>>m_class_2014[m_counter].m_student_name;
cout<<"Enter CMS of the Student "<<endl;
cin>>m_class_2014[m_counter].m_cms;
cout<<"Enter GPA of the Student "<<endl;
cin>>m_class_2014[m_counter].m_gpa;
m_counter=m_counter+1;
}
Search Data from the Array Strcutures :
- Code: Select all
string m_search;
cout<<"Enter Name of Student for Searching "<<endl;
cin>>m_search;
for(m_counter=0;m_counter<max_student;m_counter=m_counter+1)
{
cout<<"Value of the Counter "<<m_counter<<endl;
if(m_search==m_class_2014[m_counter].m_student_name)
{
cout<<"Student Named "<<m_search <<" has CMS "<< m_class_2014[m_counter].m_cms << " and CGPA "<< m_class_2014[m_counter].m_gpa<<endl;
}
}
Function for a simple calculator :
- Code: Select all
int calculator(int input_1, int input_2, char m_operator)
{
int output;
switch(m_operator)
{
case '+':
output=input_1+input_2;
break;
case '-':
output=input_1-input_2;
break;
case '/':
output=input_1/input_2;
break;
case '*':
output=input_1*input_2;
break;
}
return output;
}
