USING C VECTORS I wrote This program using arrays BUT I NEED
USING C++ (VECTORS)
I wrote This program using arrays, BUT I NEED TO CHANGE BY VECTOR( PLEASE HELP ME WITH THAT, IS THE SAME PROGRAM BUT USING VECTOR)
this is my program using arrays:
write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student ID number. The number of students in the class is unknown. However; the last ID number is 0000. The file pr2.data.txt is included and contains the data .
According to data given there are 22 students:
pr2.data.txt
1234   52   70   75
 2134   90   76   90
 3124   90   95   98
 4532   11   17   81
 5678   20   12   45
 6134   34   45   55
 7874   60   100   56
 8026   70   10   66
 9893   34   09   77
 2233   78   20   78
 1947   45   40   88
 3456   78   55   78
 2877   55   50   99
 3189   70   100   78
 2132   77   100   80
 4602   89   50   91
 3445   78   60   78
 5405   11   11   00
 4556   78   20   10
 6999   88   98   89
 0000
This is my code: ( its work well, however I send the display to a file)
#include <iostream>
 #include <iomanip>
 #include <fstream>
using namespace std;
const int size = 22;
typedef int student[size];
 typedef int quiz1[size];
 typedef int quiz2[size];
 typedef int quiz3[size];
 typedef float stavg[size];
void getdata(ifstream &,student, quiz1, quiz2, quiz3);
 void findstavg (quiz1, quiz2, quiz3, stavg);
 void findhigh(quiz1, quiz2, quiz3, int&, int&, int&);
 void findlow(quiz1, quiz2, quiz3, int&, int&, int&);
 void findqzavg(quiz1, quiz2, quiz3, float&, float&, float&);
 void printall(ofstream &, student, quiz1, quiz2, quiz3,
 stavg, int, int, int, int, int, int, float, float, float);
int main()   
 {   ifstream infile(\"pr2data.txt\");
    ofstream outfile;
    outfile.open(\"pr3output.txt\");
   
    student id;
    quiz1 q1;
    quiz2 q2;
    quiz3 q3;
    stavg savg;
    int lo1;
    int lo2;
    int lo3;
    int hi1;
    int hi2;
    int hi3;
    float qavg1 = 0;
    float qavg2 = 0;
    float qavg3 = 0;
   
    if(!infile) //check if file exists
    {
        cout<<\"Unable to open the file.\"<<endl;
    }
    else
    {
        getdata(infile,id,q1,q2,q3);
        findstavg(q1, q2, q3, savg);
        findhigh(q1, q2, q3, hi1, hi2, hi3);
        findlow(q1, q2, q3, lo1, lo2, lo3);
        findqzavg(q1 , q2 , q3 , qavg1 , qavg2 , qavg3 );
        printall(outfile, id, q1, q2, q3, savg, hi1,
        hi2, hi3, lo1, lo2, lo3, qavg1, qavg2, qavg3);
    }
 return 0;
 }
 // find quiz average for each student
 void findstavg(quiz1 q1, quiz2 q2, quiz3 q3, stavg savg)
 {
 for(int i = 0; i < size; i++)
 savg[i] = (q1[i] + q2[i] + q3[i]) / 3.0;
 }
 // find the lowest grade
 void findlow(quiz1 q1, quiz2 q2, quiz3 q3, int & lo1, int & lo2, int & lo3 )
 {
    int x1 = q1[0];
    int x2 = q2[0];
    int x3 = q3[0];
    lo1 = 0;
    lo2 = 0;
    lo3 = 0;
    for(int i = 1; i < size; i++)
    {
    if(x1 >= q1[i])
        {
        x1 = q1[i];
        lo1 = x1;
        }
    if(x2 >= q2[i])
        {
        x2 = q2[i];
        lo2 = x2;
        }
    if(x3 >= q3[i])
        {
        x3 = q3[i];
        lo3 = x3;
        }
    }
 }
 // find the highest grade
 void findhigh(quiz1 q1, quiz2 q2, quiz3 q3, int & hi1, int & hi2, int & hi3 )
 {
    int x1 = q1[0];
    int x2 = q2[0];
    int x3 = q3[0];
    hi1 = 0;
    hi2 = 0;
    hi3 = 0;
    for(int i = 1; i < size; i++)
    {
    if(x1 <= q1[i])
        {
        x1 = q1[i];
        hi1 = x1;
        }
    if(x2 <= q2[i])
        {
        x2 = q2[i];
        hi2 = x2;
        }
    if(x3 <= q3[i])
        {
        x3 = q3[i];
        hi3 = x3;
        }
    }
 }
 //find average scores for for each quiz
 void findqzavg(quiz1 q1, quiz2 q2, quiz3 q3, float & qavg1, float & qavg2, float & qavg3)
 {
 for(int i = 0; i < size; i++)
 {
 qavg1 += q1[i];
 qavg2 += q2[i];
 qavg3 += q3[i];
 }
 qavg1 = qavg1 / size;
 qavg2 = qavg2 / size;
 qavg3 = qavg3 / size;
 }
void getdata(ifstream &fin, student id, quiz1 q1, quiz2 q2, quiz3 q3)//read student ID, then each of
                                                                    //the 3 quiz\'s for each student
 {
   
 for(int i = 0; i < size; i++)
 {
 fin>>id[i]>>q1[i]>>q2[i]>>q3[i];
}
 }
void printall(ofstream &fout, student id, quiz1 q1, quiz2 q2, quiz3 q3, stavg savg, int hi1,
 int hi2, int hi3,int lo1, int lo2, int lo3, float qavg1, float qavg2, float qavg3)//print all data on a new .txt file
 {
    fout<<\"\\t\"<<\"student\"<<\"\\t quiz1 \"<<\"\\t quiz2 \"<<\"\\t quiz3 \"<<\"\\t average \"<<fixed<<setprecision(2)<<endl;
 for(int i = 0; i < size; i++)
    {
    fout<<\"\\t\"<<id[i]<<\"\\t \"<<q1[i]<<\"\\t \"<<q2[i]<<\"\\t \"<<q3[i]<<\"\\t \"<<fixed<<setprecision(2)<<savg[i]<<endl;
     }
 fout<<\"\"<<endl;
 fout<<\"High Score : \"<<\"\\t\"<<hi1<<\"\\t\"<<hi2<<\"\\t\"<<hi3<<endl;
  fout<<\"Low Score : \"<<\"\\t\"<<lo1<<\"\\t\"<<lo2<<\"\\t\"<<lo3<<endl;
  fout<<\"Quiz Average: \"<<\"\\t quiz1 \"<<qavg1<<\"\\t quiz2 \"<<qavg2<<\"\\t quiz3 \"<<qavg3<<endl;
 }
This program works well, as you noted I\'m using vectors and I\'m sending the output to a file.
PLEASE I JUST NEED HELP USING VECTORS, PLEASE JUST CHANGE ARRAYS BY VECTOR AND USE THE SAME LOGICAL AND CODES, JUST NEED CHANGE ARRAYS BY VECTOR AND ALSO I DO NOT NEED TO SEND THE OUTPUT TO A FILE
Solution
Solution:
#include <iostream>
 #include <iomanip>
 #include <fstream>
 #include <vector>
using namespace std;
const int size = 22;
typedef vector<int> student;
 typedef vector<int> quiz1;
 typedef vector<int> quiz2;
 typedef vector<int> quiz3;
 typedef vector<float> stavg;
void getdata(ifstream &,student, quiz1, quiz2, quiz3);
 void findstavg (quiz1, quiz2, quiz3, stavg);
 void findhigh(quiz1, quiz2, quiz3, int&, int&, int&);
 void findlow(quiz1, quiz2, quiz3, int&, int&, int&);
 void findqzavg(quiz1, quiz2, quiz3, float&, float&, float&);
 void printall(student, quiz1, quiz2, quiz3,stavg, int, int, int, int, int, int, float, float, float);
int main()
 {
    ifstream infile(\"pr2data.txt\");
       
     student id;
     quiz1 q1;
     quiz2 q2;
     quiz3 q3;
     stavg savg;
     int lo1;
     int lo2;
     int lo3;
     int hi1;
     int hi2;
     int hi3;
     float qavg1 = 0;
     float qavg2 = 0;
     float qavg3 = 0;
   
     if(!infile) //check if file exists
     {
         cout<<\"Unable to open the file.\"<<endl;
     }
     else
     {
         getdata(infile,id,q1,q2,q3);
         findstavg(q1, q2, q3, savg);
         findhigh(q1, q2, q3, hi1, hi2, hi3);
         findlow(q1, q2, q3, lo1, lo2, lo3);
         findqzavg(q1 , q2 , q3 , qavg1 , qavg2 , qavg3 );
         printall(id, q1, q2, q3, savg, hi1, hi2, hi3, lo1, lo2, lo3, qavg1, qavg2, qavg3);
     }
    system(\"pause\");
     return 0;
 }
// find quiz average for each student
 void findstavg(quiz1 q1, quiz2 q2, quiz3 q3, stavg savg)
 {
    float avg;
    for(int i = 0; i < q1.size(); i++)
    {
        avg=(q1[i] + q2[i] + q3[i]) / 3.0;
        savg.push_back(avg);
    }
        //savg[i] = (q1[i] + q2[i] + q3[i]) / 3.0;
 }
 // find the lowest grade
 void findlow(quiz1 q1, quiz2 q2, quiz3 q3, int & lo1, int & lo2, int & lo3 )
 {
     int x1 = q1[0];
     int x2 = q2[0];
     int x3 = q3[0];
     lo1 = 0;
     lo2 = 0;
     lo3 = 0;
     for(int i = 1; i < size; i++)
     {
     if(x1 >= q1[i])
         {
         x1 = q1[i];
         lo1 = x1;
         }
     if(x2 >= q2[i])
         {
         x2 = q2[i];
         lo2 = x2;
         }
     if(x3 >= q3[i])
         {
         x3 = q3[i];
         lo3 = x3;
         }
     }
 }
 // find the highest grade
 void findhigh(quiz1 q1, quiz2 q2, quiz3 q3, int & hi1, int & hi2, int & hi3 )
 {
     int x1 = q1[0];
     int x2 = q2[0];
     int x3 = q3[0];
     hi1 = 0;
     hi2 = 0;
     hi3 = 0;
     for(int i = 1; i < q1.size(); i++)
     {
     if(x1 <= q1[i])
         {
         x1 = q1[i];
         hi1 = x1;
         }
     if(x2 <= q2[i])
         {
         x2 = q2[i];
         hi2 = x2;
         }
     if(x3 <= q3[i])
         {
         x3 = q3[i];
         hi3 = x3;
         }
     }
 }
 //find average scores for for each quiz
 void findqzavg(quiz1 q1, quiz2 q2, quiz3 q3, float & qavg1, float & qavg2, float & qavg3)
 {
       for(int i = 0; i < q1.size(); i++)
         {
         qavg1 += q1[i];
         qavg2 += q2[i];
         qavg3 += q3[i];
         }
         qavg1 = qavg1 / size;
         qavg2 = qavg2 / size;
         qavg3 = qavg3 / size;
 }
void getdata(ifstream &fin, student id, quiz1 q1, quiz2 q2, quiz3 q3)//read student ID, then each of
                                                                     //the 3 quiz\'s for each student
 {
    int idval,v1,v2,v3;
   
    for(int i = 0; i < size; i++)
    {
        fin>>idval>>v1>>v2>>v3;
        id.push_back(idval);
        q1.push_back(v1);
        q2.push_back(v2);
        q3.push_back(v3);
    }
 }
void printall(student id, quiz1 q1, quiz2 q2, quiz3 q3, stavg savg, int hi1, int hi2, int hi3,int lo1, int lo2, int lo3, float qavg1, float qavg2, float qavg3)//print all data on a new .txt file
 {
     cout<<\"\\t\"<<\"student\"<<\"\\t quiz1 \"<<\"\\t quiz2 \"<<\"\\t quiz3 \"<<\"\\t average \"<<fixed<<setprecision(2)<<endl;
    for(int i = 0; i < q1.size(); i++)
    {
        cout<<\"\\t\"<<id[i]<<\"\\t \"<<q1[i]<<\"\\t \"<<q2[i]<<\"\\t \"<<q3[i]<<\"\\t \"<<fixed<<setprecision(2)<<savg[i]<<endl;
     }
    cout<<\"\"<<endl;
    cout<<\"High Score : \"<<\"\\t\"<<hi1<<\"\\t\"<<hi2<<\"\\t\"<<hi3<<endl;
     cout<<\"Low Score : \"<<\"\\t\"<<lo1<<\"\\t\"<<lo2<<\"\\t\"<<lo3<<endl;
     cout<<\"Quiz Average: \"<<\"\\t quiz1 \"<<qavg1<<\"\\t quiz2 \"<<qavg2<<\"\\t quiz3 \"<<qavg3<<endl;
 }







