1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
# include <iostream>
# include <stdlib.h>
# include <cstring>
using namespace std;
float mesos; //dhlwsh genikwn metavlhtwn
int p;
int f;
float min;
float max;
class student
{
private:
int am ;
char *onoma ;
int mathimata ;
float *vathmologia ;
float mo ;
int perase ;
int kopike ;
float minvathm ;
float maxvathm ;
public:
student ( int arithmos , char *name , int mathm , float *vathm ) {setstudent(arithmos,name,mathm,vathm);} //constructor
student () {mo=0, perase=0, kopike=0, minvathm=0, maxvathm=0;}
void setstudent(int arithmos , char *name , int mathm , float *vathm );
void calc(); //synarthshsh ypologismou
void emfanish(); //synarthsh ektypwshs
};
void student::setstudent(int arithmos , char *name , int mathm , float *vathm) //arxikopoihsh dedomenwn
{
am=0; onoma="NO NAME"; mathimata=0; vathmologia=0;
if (arithmos >=1 && arithmos <=9999 )
{
am = arithmos;
}
if (mathm >= 1 && mathm <=8)
{
mathimata = mathm;
}
onoma = new char [strlen(name)];
if (strlen(name)>=1 && strlen(name)<=40)
{
onoma = name ;
}
vathmologia = new float [mathm];
for (int i=0; i<=mathm ; i++)
{
if (vathm[i] >= 1 && vathm[i] <=10)
{
vathmologia[i] = vathm[i] ;
}
}
}
void student::calc()
{
float sum = 0 ; //ypologismos mesou orou
for (int i=0 ; i < mathimata ; i++ )
{
sum = sum + vathmologia[i];
}
mo = sum/mathimata;
mesos = mo ;
perase=0; kopike=0; //ypologismos mathimatwn pou perase kai kopike
for (int i=0 ; i < mathimata ; i++ )
{
if (vathmologia[i] < 5)
{
perase = perase +1;
}
else
{
kopike = kopike + 1;
}
}
p=perase;
f=kopike;
minvathm=10; maxvathm=0; //ypologismos min max
for (int i=0 ; i < mathimata ; i++ )
{
if (vathmologia[i] < minvathm)
{
minvathm = vathmologia[i];
}
if (vathmologia[i] > maxvathm )
{
maxvathm = vathmologia[i];
}
}
max=maxvathm;
min=minvathm;
}
void student::emfanish()
{
cout << "Name: " << onoma <<"\n" ;
cout << "id: " << am <<"\n" ;
cout << "Subjects Given: " << mathimata << "\n" ;
cout << "Grades Taken: " ;
for (int i=0 ; i < mathimata ; i++ )
{
cout << vathmologia[i] << " " ;
}
cout<<"\n";
}
int main()
{
student ant;
float vathm[] = {7.0, 3.0, 6.0, 10.0, 4.0};
ant.setstudent(1510, "James Stathatos", 5, vathm);
ant.emfanish();
//float min; float max;
ant.calc();
cout << "Passed in " << p << " Subjects, \n";
cout << "Failed in " << f << " Subjects \n";
cout << "Average Grade: " << mesos <<"\n";
cout << "Minimum Grade: " << min <<"\n";
cout << "Maximum Grade: " << max <<"\n";
system ("pause");
return 0 ;
}
|