Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by lab4 ( 7 years ago )
#include<iostream>
#include<string>
using namespace std;
/**/
class Test
{
 int mark[5];
public:
Test(int[]);
Test();
~Test();
void setMark(int[]);
void getMark(int []);
void print() const;
Test getAllGreater(int); 
int getAllLess(int) ; 
void Avg(double&); };

Test ::Test(int a[]){
   setMark(a);
}
Test ::Test() {
    for (int i =0; i<5 ;i++)
    mark[i]= 0;
}
Test ::~Test(){
    cout <<"end of class Test\n";
}
void Test ::setMark(int a[]){
  for (int i =0; i<5 ;i++)
    mark[i]= a[i];
}
void Test ::getMark(int a[]){
    for (int i =0; i<5 ;i++)
   a[i] = mark[i];
}
void Test ::print() const{
     for (int i =0; i<5 ;i++)
       cout <<mark[i]<<" ";
       cout<<endl;
}
Test Test ::getAllGreater(int a){
    Test temp;
    int counter =0;
    for (int i =0; i<5 ;i++)
      {
           if (mark[i]>a) {temp.mark[counter]=mark[i]; counter++ ;}
      }
    for (int i =0; i<counter ;i++)  
    {
          cout << temp.mark[i]<<" ";
    }
    cout <<endl; 
    return temp;
}
int Test ::getAllLess(int x){
    int counter =0;
    for (int i =0; i<5 ;i++)
      {
           if (mark[i]<x) { counter++ ;}
      }
} 
void Test:: Avg(double &x){
x = (mark[0]+mark[1]+mark[2]+mark[3]+mark[4])/5.0 ;
}
Test compare(Test g1, Test g2) {
int a , b;
a=g1.getAllLess(50); b=g2.getAllLess(50);
if (a > b) return g2; else g1;
} 


int main()
{ int a[5] ,b[5] ; double avg1 , avg2;
  for (int i=0 ; i<5 ;i++){cin >>a[i];}
  for (int i=0 ; i<5 ;i++){cin >>b[i];}
  Test g1(a); cout <<"grades and average at first test :\n"; g1.print();  g1.Avg(avg1); cout <<"avg = "<<avg1<<endl;
  Test g2(b); cout <<"grades and average at second test :\n"; g2.print();  g2.Avg(avg2); cout <<"avg = "<<avg2<<endl;
  Test g3 ;
  cout <<"A grades i.e >= 90 at first test :\n"; g3 =g1.getAllGreater(89); 
  Test g4 ;
  cout <<"test with more pass grades :\n";
  g4 =compare (g1 , g2); g4.print();
return 0;
}

 

Revise this Paste

Your Name: Code Language: