0% found this document useful (0 votes)
74 views4 pages

C++ Student Management System

This C++ program defines a student class with attributes like name, gender, grades, and average. It overloads input and output operators to read and display student objects. Functions are defined to find a student by name, find the student with the highest average, and print total statistics. The main function initializes an array of students, reads their data, calls the class methods, and displays results.

Uploaded by

ljjb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views4 pages

C++ Student Management System

This C++ program defines a student class with attributes like name, gender, grades, and average. It overloads input and output operators to read and display student objects. Functions are defined to find a student by name, find the student with the highest average, and print total statistics. The main function initializes an array of students, reads their data, calls the class methods, and displays results.

Uploaded by

ljjb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

//By:Ali Mahmood Ali ^_^

//Second Class _Network


#include<iostream>
#include<conio.h>
#include<string>
using namespace std;

class student
{
public:

friend istream & operator >> (istream


&input ,student &s);
friend ostream & operator << (ostream
&out ,student s);

void avg()
{ float sum=0;
for(int j=0;j<3;j++)
sum+=gd[j];
avrage=sum/3;
}//end function

friend void find(student s[],int size);


friend void findbest(student s[], int size);
friend void printtotl(student s[], int size);

~student(){};
private:
string name;
string gr;
int gd[3];
float avrage;
};//end class

void find(student s[],int size)


{ int choice=0;
string name2;
cout<<"\nEnter the name of student:";
cin>>name2;
for(int i=0;i<size;i++)
if (name2==s[i].name)
{cout<<"\nfind student\n";
choice=1;
cout<<s[i];
if(s[i].avrage>=50)
// ‫حتة ياخذ المعدل مال هذا الكالس الن الزم يعرف ياكالس منهم يشوف‬
‫معدلة ميصير انطي المعدل بدون ماحدد مال ياكالس منهم‬
cout<<"passd";
else
cout<<"falid";
}//end if
if(choice==0)
cout<<"\nSorry, this student name does not
exist .\nEnter a new name,plase :";
}//end function

void findbest(student s[], int size)


{ int location_max;
cout<<"\nthe best student is:\n ";
for(int i=0;i<size-1;i++)
//size-1 ‫الن الرقم االخير ميحتاج اقارنة بعد‬
{
for(int j=i+1;j<size;j++)
//i+1 ‫حتة مياخذ الرقم نفسة يقارنة وية نفسة‬
if(s[j].avrage>=s[i].avrage)
location_max=j;
// ‫علمود اذا تحقق الشرط الماكس تحفظ اكبر قيمة واحفظ قيمة الموقع حتة‬
‫اعرف ياطالب اريد اطبع معلوماتة اعتمادا علة الموقع‬
}//endl for loop
cout<<s[location_max];
}//end function

void printtotl(student s[], int size)


{ int i,total=0,m=0,f=0 ;
float statc;
cout<<"the total namber of student in
class: "<<size;
for( i=0;i<size;i++)
{ if(s[i].avrage>50)
{ total++;
if (s[i].gr =="male")
m++;
if(s[i].gr =="female")
f++;
}//end if
}//end for loop
statc=(total*100)/size;
cout<< "\n\nthe success rate is:"
<<statc;
cout<< "\nthe male passed is:" <<m;
cout<< "\nthe female passed is:" <<f;
}//end function

istream &operator>>(istream &input ,student &s)


{
cout<<"enter name : ";
input>>s.name;
cout<<"male or famel : ";
input>>s.gr;
cout<<"enter three grad: ";
for(int j=0;j<3;j++)
input>>s.gd[j];

return input;
}

ostream &operator<<(ostream&out ,student s)


{
out<<s.name<<"\t"<<s.gr<<"\t";
for(int j=0;j<3;j++)
out<<s.gd[j]<<"\t";
out<<s.avrage<<endl;
return out;
}
void main()
{ int size,choice=1;
cout<<"Enter the number of student : ";
cin>>size;
student *s=new student[size];
for(int i=0;i<size;i++)
{cout<<"\nstudent # "<<i+1<<endl;
cin>>s[i];
s[i].avg();
}
for(int i=0;i<size;i++)
cout<<s[i];
while (choice)
{ find(s,size);
cout<<"\n\nEnter (1) to find new student or
(0) to stop :";
cin>>choice;
}//end while
findbest(s,size);
printtotl(s,size);
_getch();
}

You might also like