PROGRAMMING USING CLASS




Program

#include <iostream>
#include <string>
#include<windows.h>
using namespace std;
int g=1,l,f=4,n=0;
float sum=0;
class Student
{   
int con,sem;
    char name[50],DOB[50],section[50];
float gpa;
public:
void getName()
{
cin.ignore();
cin.getline(name,50);
}

void getgpa()
{
cin >> gpa;
}

void getDOB()
{
cin.ignore();
cin.getline(DOB,50);
}
void getsec()
{
cin >> section;
}
void getcon()
{
cin >> con;
}
void getsem()
{
cin >>sem;
}
void getdata(int k){
cout<<k<<"\t\t"<<name<<"\t\t"<<con<<"\t\t"<<sem<<"\t\t"<<section<<"\t\t"<<gpa<<"\t\t"<<DOB<<endl;
}
void displayAll()
{
cout << "Name : " << name << endl;
cout << "GPA : " << gpa << endl;
cout << "Date of birth : " << DOB << endl;
cout<<"Section"<<section<<endl;
cout<<"Contact #:"<<con<<endl;
cout<<"semister:"<<sem<<endl;
}
void displayS()
{
cout << "Name : " << name << endl;
cout << "GPA : " << gpa << endl;
cout << "Date of birth : " << DOB << endl;
cout<<"Section"<<section<<endl;
cout<<"Contact #:"<<con<<endl;
cout<<"semister"<<sem<<endl;
}
void larger(int s){
if(gpa>g){
l=s;
g=gpa;
}
}
void lower(int s){
if(gpa<=f){
l=s;
f=gpa;
}
}
void average(){
sum=sum+gpa;
n=n+1;
}
};
Student st[3];
int z=1;
int main()
{
system("color B");
int s,i;

system("cls");
cout<<"\n\n"<<endl;
cout << "\n\n\t\t\t**************Student Management System**************";
cout<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\t\t\tMain Menu"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
cout<<"\t\t\t1)New Student"<<endl;
Sleep(200);
cout<<"\t\t\t2)Display All"<<endl;
     Sleep(200);
        cout<<"\t\t\t3)Display a Student"<<endl;
        Sleep(200);
         cout<<"\t\t\t4)Student with larger GPA"<<endl;
        Sleep(200);
         cout<<"\t\t\t5)Student with lower GPA"<<endl;
        Sleep(200);
         cout<<"\t\t\t6)Student with Average GPA"<<endl;
        Sleep(200);
         cout<<"\t\t\t7)Exit"<<endl;
        Sleep(200);
            cout<<"\t\t*********************************************************************"<<endl;
        Sleep(200);
cout<<"Select an option that you want(1-3):";
        cin>>s;
        if(s==1){
        system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\t\t\tADD STUDENT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
  for( i=z; i<=z; i++ )
{
cout << "Student " << i << endl;
cout << "Enter name:";
st[i].getName();
cout << "Enter GPA:";
st[i].getgpa();
cout << "Enter DOB:";
st[i].getDOB();
cout << "Enter Section:";
st[i].getsec();
cout << "Eter contact#:";
st[i].getcon();
cout << "Enter Semister:";
st[i].getsem();
}
cout<<"Please wait.........";
Sleep(2000);
z++;
main();
}
    else if(s==2){
    system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\t\t\tDISPLAY ALL STUDENT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
for( int i=1; i<z; i++ )
{
cout << "Student " << i  << endl;
st[i].displayAll();
}
cout<<"Please wait.........";
Sleep(2000);
main();
}
 else if(s==3){
int w;
system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\t\t\tDISPLAY A STUDENT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
cout<<"Enter your ID:";
cin>>w;
st[w].displayS();
cout<<"Please wait.........";
Sleep(2000);
main();
}
else if(s==4){
system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\tDISPLAY A LARGER GPA STUDENT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
for( int i=1; i<z; i++ )
{
st[i].larger(i);
}
st[l].displayS();
cout<<"Please wait.........";
Sleep(2000);
main();
}
else if(s==5){
system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\tDISPLAY A LOWER GPA STUDENT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
for( int i=1; i<z; i++ )
{
st[i].lower(i);
}
st[l].displayS();
cout<<"Please wait.........";
Sleep(2000);
main();
}
else if(s==6){
system("cls");
cout<<"\n\n"<<endl;
cout<<"\t\t********************************************************************"<<endl;
cout<<"\t\t\t\t\t\tDISPLAY A AVERAGE RESULT"<<endl;
cout<<"\t\t*********************************************************************"<<endl;
for( int i=1; i<z; i++ )
{
st[i].average();
}
cout<<"Average GPA:"<<sum/n<<endl;
cout<<"Please wait.........";
Sleep(20000);
main();
}
else if(s==7){
system("cls");
system("color D");
cout<<"\n\n\n\n\n\t\t\t\tTHHANKS FOR USING";
}
return 0;
}

Comments

Popular posts from this blog

Stack

EXTRA INFORMATION ABOUT TECHNOLOGY