Home Forums C Programming c++ function help

Viewing 1 reply thread
  • Author
    Posts
    • #2128
      ClaribelConde
      Participant
      #include 
      #include
      #include
      using namespace std;
      void OpenFiles(char ch, float gpa);
      void initialize(int fcout, int mcout, float fgpa, float mgpt);
      void sumGrades( int fcout, int mcout, float fgpa, float mgpa);
      void averageGrades(float avfgpa, float avmgpa);
      void printResults(int fcout, int mcout, float avfgpa, float avmgpa);
      void main()
      {
       ofstream out;
       ifstream in;
       char ch;
       float gpa;
       float avfgpa;
       float avmgpa;
       int fcout, mcout;
       float fgpa;  //define female GPA
       float mgpa;  //define male GPA
       initialize (fcout, mcout, fgpa, mgpa);
       OpenFiles(ch, gpa);
       while(!in.eof())
       {
        sumGrades(fgpa,mgpa,fcout,mcout);
        in>>ch>>gpa;
        averageGrades(avfgpa, avmgpa);
       }

       printResults(fcout, mcout, avfgpa, avmgpa);
       
       return;
       
      }
      void OpenFiles(char ch, float gpa)
      {
       ofstream out;
       ifstream in;
       in.open("k:\prob-7.txt",ios::in);
       if (!in)
       {
        cout<<"Can not open input file"<   cout<<"program terminates!!"<  }
       in.get(ch);
       in>>gpa;
       in.eof();
       out.open("k:\out.txt", ios::out);
       out<  out<  //out<<"Female" < }
      void initialize(int fcout, int mcout, float fgpa, float mgpa)
      {
       fgpa = 0.0;
       mgpa= 0.0;
       fcout = 0;
       mcout = 0;
      }
      void sumGrades(int fcout, int mcout, float fgpa, float mgpa)
      {
       
       char ch;
       float gpa;
       OpenFiles(ch, gpa);
       switch (ch)
       {
        case 'F':
        case 'f': fgpa = fgpa+gpa;
         fcout++;
         //avfgpa = fgpa/fcout;
         break;
        case 'M':
        case 'm': mgpa = mgpa + gpa;
         mcout++;
         //avmgpa = mgpa/mcout;
         break;
        default: cout<<"invalid gender"<    return;
       }
       
      }
      void averageGrades(float avfgpa, float avmgpa)
      {
        
        float fgpa,  mgpa;
        int fcout, mcout;
        sumGrades(fcout, mcout, fgpa, mgpa);
        avfgpa = fgpa/fcout;
        avmgpa = mgpa/mcout;
      }
       
      void printResults(int fcout, int mcout, float avfgpa, float avmgpa)
      {
       ofstream out;
       out<<"Number of female ="<  out<<"Average female GPA  = "<  out<<"Number of male ="<  out<<"Average male GPA ="<  out.close();
      }

       
       
      give a lots of error vs warning, I think that having trouble with function calls, and passing to main function, but i have no idea to fix cause the book i am studying hasnt clear out much.

      summerize what program will do :

      open a file with 2 columes; one is letter of f or m (represent for female and male), the other colume is GPA (grade).

      read it and sum the gpa of female , sum the gpa of male, and display the everage of female and male gpa.

      the function calls need to have 5 of them:

      initialize variable

      open and format output

      sum gpa of female and male

      find the average of female male gpa

      print the rerults.

    • #3430
      Humayan
      Participant

      Could you give an example of what both the input and output files. The real problem with your program is how its organized and you haven’t used reference variables for some functions…..

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.