I have got your site of interest and useful. Iam a student and besides learning programing in class, i take time to teach myself C++ from the internet. i have this exercise in which i got stuck and wish to solicit for help,
do you offer help on such?
if its possible, i should be greatful if you helped on this.
im combining classes and structures.
thanks.

#include <iostream>                                                                                                      
#include <fstream>                                                                                                       
#include <iomanip>                                                                                                       
#include <conio.h>                                                                                                       
#include <CTime>                                                                                                         
#include <cstdlib>                                                                                                       
#include <cmath>                                                                                                         
#include <cstring> 
#define max 500 
// Header files 
#include < windows.h > 
typedef unsigned short bil; 

#define SCR 3 
#define Number 4 
#define Credit 3 
#define Subject 5 
class Technology 
{ 
public: 
        virtual  void accept  ()=0; 
        virtual  void compute ()=0; 
        virtual  void display ()=0; 
}; 

class Civil: public Technology 
{ 
        protected: 
        struct Students 
        { 
                char name[30];                   
                char RegNo[25];                  
                char course[5][5];               
        }; 


        struct Course 
        { 
                char  code[5];                   
                float CUnit[5];  
                float GPsum[4]; 
; 

        bil input(bil &x);// introducing a prototype bil 
        bil score[SCR][2]; 
        bil Total[Number][20]; 
        bil CUnit[Credit][2]; 



                   Course courses={ {"CE601",0.0},  // initialize subjects 
                                                                {"CE602",0.0}, 
                                                                {"CE603",0.0}, 
                                                                {"CE604",0.0}, 
                                                                {"CE605",0.0}} 



void accept() 
{ 

        cout<<"\tInput Number of Students in this class:\t"; 
        input(Total); 
        cout<<"\tEnter Credit units for following courses:\t"; 
        for(bil i=0; i<Total;i++) 
        { 
                cout<<endl<<courses[i].code<<" CU : "; 
                cin>>courses[i].CUnit; 
                GPsum+=courses[i].CUnit; 
        }        

                        system("cls\0"); 
                        students= new Student[Total];     // allocation of memory here 
                        for(i=0;i<Total;i++) 
                { 
                                cout<<"\nEnter the details of STUDENT number"<<(i+1)<<endl; 
                                cout<<endl<<"Names: "; 
                                cin>>students[i].names; 

                                cout << "\nEnter the RegNo:\t"; 
                                cin >>students[i].RegNo; 

                        for(bil k=0;k<SUBS;k++) 
                { 
                                do{      
                        cout<<"\nEnter the student scores for  " <<courses[k].code<<" : \t"; 
                        cin>>students[i].score[k]; 


                        if((students[i].score[k]<0) ||(students[i].score[k]>100)) 
                { 
                        cout<<"\nInvalid Mark Entered!\nThe marks should range from 0 to 100\n"; 
                } 
                }       while((students[i].score[k]<0) ||(students[i].score[k]>100)); 

        } // end of marks entry loop 

        } 
        if (students) delete [] students; // release any  allocated memory 



        } 







        void  compute () 
        { 

                // sorting 

                for(int s=0;s<Total;s++) 
                { 
                        for(int p=s+1;p<Total;p++) 
                        { 
                                if ( strcmp(students[s].names, students[p].names)<0 ) // compare the names 
                                        { 
                                                temp = students[s]; 
                                                students[s] = students[p]; 
                                                students[p] = temp; 
                                        } 
                        } 
                }// end of sorting 



                bestGPA=0.0; // set the best GPA as zero, initially, 
                students= new Student[Total]; 
                                                // Computing the GPs & GPA 
                for(i=0;i<Total;i++) 
                { 
                        sum=0.0; 
                        for(k=0;k<SUBS;k++) 
                                { 
                                        students[i].GP[k]=GetGP(students[i].score[k]); // get the GP for the mark 
                                        if(students[i].score[k]>=50)  // subject passmark 
                                        strcpy(students[i].course[k],PASSED); 
                                        else  strcpy(students[i].course[k],RETAKE); 
                                } // end of subjects analysis 

                                        // computing  GPA 
                                        for(k=0;k<SUBS;k++) sum+=(courses[k].CUnit * students[i].GP[k]); 
                                        students[i].GPA=sum/GPsum; // store the GPA obtained 

                                        //  normal progress or on probation 
                                        if(students[i].GPA< 2.00)  strcpy(students[i].unit,PROBATION); 
                                        else  strcpy(students[i].unit,NORMALPROGRESS); 
                                                    // determining best student 
                                        if(students[i].GPA> bestGPA) 
                                                { 
                                                        bestGPA=students[i].GPA; 
                                                        best=i; 

                                                } 

                        } 


        } 

        void display () 
                        { 

                        cout<<endl; // Retrive marks and GP of any student of interest 
                        cout<<"\tWhich student's Data would you like to retrieve?"; 
                        input(i); 
                        cout<<"\tThe Details of student"<<i<<"is"<<score[i-1]<<and GP is"<<GP[i-1]<<endl; 


                                Sleep(2000);             
                        cout << "\n\n" << setw(52) << "PRESS ANY KEY TO DISPLAY TABLE OF RESULTS" ; 
                        getch (); 
                                               // display of table of results 
                        cout<<endl; 
                        cout<<setw(65)<<"MAKERERE UNIVERSITY\n"<<endl 
                        <<setw(66)<<"FACULTY OF TECHNOLOGY\n"<<endl<<setw(70) 
                        <<"DEPARTMENT OF ELECTRICAL ENGINEERING \n"<<endl 
                        <<setw(50) 
                        <<"PERFORMANCE LIST FOR YEAR "<<YEAR<<" SEMESTER  "<<WHICH<<" ACADEMIC YEAR(2003\\2004) \n" 
                        <<endl; 


                        cout<<setiosflags(ios::left)<<setw(25)<<"  "; 
                        for(k=0;k<SUBS;k++) 
                        cout<<setiosflags(ios::left)<<setw(18)<<courses[k].code; 

                        cout<<endl; 
                        cout<<setiosflags(ios::left)<<setw(12)<<"NAME" 
                        <<setw(9)<<setiosflags(ios::left)<<"REG.No."; 
                        for(int j=0;j<SUBS;j++) 
                        { 
                                cout<<setw(6)<<  "MARK" // output marks 
                                    <<setw(5)<<  "GP" //  ouptut GP for the mark 
                                <<setw(6)<<  "STATE"; 
                        }                               //loop for headers ends here 



                        cout<<setw(5)<<"GPA" // write the student's GPA 
                        <<setw(5)<<"STATUS"<<endl; // indicate whether they have normal progress or not 

                for(i=0;i<NumOfStudents;i++) 
                                {               // tabulating  the results 
                                        cout<<endl; 
                                        cout<<setiosflags(ios::left)<<setw(15)<<students[i].names<<setw(10)<<se tiosflags(ios::left)<<students[i].RegNo; 
                                        for(k=0;k<SUBS;k++) 
                                                { 
                                                        cout<<setprecision(1)<<setw(4)<<setiosflags(ios::fixed)<<students[i]. score[k] // output marks 
                                                         <<setw(5)<<setprecision(2)<<setiosflags(ios::fixed)<<students[i].GP[k] // ouptut GP for the mark 
                                                        <<setw(5)<<setiosflags(ios::fixed | ios::left)<<students[i].course[k]; 
                                                 }                                      // end of loop for filing marks and their particulars 

                                                        cout<<setw(4)<<setprecision(2)<<students[i].GPA // write the student's GPA 
                                                        <<setw(4)<<students[i].unit; // indicate whether they have normal progress or not(i input [k] here 
                                } 
                                        // give name of best student and their GPA 
                        cout<<endl<<endl<<"The best student is:\n\n"; 

                        cout<<setiosflags(ios::left)<<setw(10)<<students[best].names<<setw(9)<<se tiosflags(ios::left)<<students[best].RegNo; 
                for(k=0;k<SUBS;k++) 
                        { 
                                cout<<setprecision(1)<<setw(6)<<setiosflags(ios::fixed)<<students[best]. score[k] // output marks 
                                <<setw(5)<<setprecision(2)<<setiosflags(ios::fixed)<<students[best].GP[k ] //  ouptut GP for the mark 
                                <<setw(5)<<setiosflags(ios::fixed | ios::left)<<students[best].course[k]; 
                         } 
                                 cout<<setw(6)<<setprecision(2)<<students[best].GPA 
                                 <<setw(6)<<students[best].unit; 
                                cout<<endl<<endl; 
                                cout<<endl<<"LEGEND\n" 
                                                  <<"======\n"; 

                                        cout<<"\nPS     PASSED SUBJECT\n" 
                                                 <<"RT     RETAKE\n" 
                                                 <<"NP     NORMAL PROGRESS\n" 
                                                 <<"PR     PROBATION\n" 
                                                 <<"%      PERCENTAGE MARK\n"; 
                                                cout<<endl<<endl; 
                                return 0; 
                        }; 

        //} 

float GetGP(float mark) 
{ 

if( mark>=80) return 5.0; 
else if(mark>=75) return 4.5; 
else if(mark>=70) return 4.0; 
  else if(mark>=65) return 3.5; 
    else if(mark>=60) return 3.0; 
     else if(mark>=55) return 2.5; 
       else if(mark>=50) return 2.0; 
         else if(mark>=45) return 1.5; 
          else if(mark>=40) return 1.0; 
           else if(mark>=35) return 0.5; 
            else  return 0.0; 
} 





int main () 
{ 
                Technology *Fot; 
                int ret; 
                char ch; 
        do 
        { 
                        cout<<"\n1.DEPARTMENT OF CIVIL ENGINEERING"; 
                        cout<<"\n2.DEPARTMENT OF ELECTRICAL ENGINEERING"; 
                        cout<<"\n3.DEPARTMENT OF MECHANICAL ENGINEERING"; 
                        cout<<"\n4.Exit"; 
                        cout<<"\n\nEnter your choice ::"; 
                        cin>>(ch); 
                        switch (ch) 
                        { 
        case '1': 
                        Fot=new Civil; 
                        Fot->accept(); 
                        Fot->compute(); 
                        Fot->display(); 
                        ret=1; 
                        break; 
        case '2': 
                        Fot=new Electrical; 
                        Fot->accept(); 
                        Fot->compute(); 
                        Fot->display(); 
                        ret=1; 
                        break; 

        case'3': 
                        Fot=new Mechanical; 
                        Fot->accept(); 
                        Fot->compute(); 
                        Fot->display(); 
                        ret=1; 
                        break; 


        case '4': 
                        ret=0; 
                        break; 
default: 
                        cout<<"\nSorry Input is out of range, Try again"; 
                        ret=1; 
                        break; 
                } 
        }while(ret); 
        return 0; 
} bil input(bil &x) 
{ 
        for(;;) 
        { 
                char trash[max]={0}; 
                cin>>x; 
                if(cin.fail()) 
                { 
                        cin.ignore(); 
                        cin.clear(); 
                } 
                cin.getline(trash,max); 
                if(strlen(trash)!=0) 
                        cerr<<setw(50)<<"\tInvalid Data Input, Try again:"; 
                else 
                        break; 
        } 
        return x; 
}

Recommended Answers

All 3 Replies

u learnt how to do ALL this from the net???

so where do i get back to the "ssen" code?

post your code enclosed in the [ code ] [ /code ] tags so it is formatted:

see the spaces get		   preserved

and post the section of code u need help on, not 19 pages of it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.