Page 1 of 1

Fundamental Programming Concepts

Unread postPosted: Sat Mar 28, 2015 10:01 am
by UCERD.COM
Basic Data Types : 
Code: Select all
char m_char;
string m_student_name;
int  m_cms;
double m_gpa;

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;
}

Image