Answer to Question #272205 in C++ for matetemaake

Question #272205

Code the following non-member functions:


1. A non-member function getStudInfo that receives a file name along with an array of


student objects. This function will use the data given in a file called studMarks.csv to


populate an array of students accordingly. You can assume the given file contains valid


data for each student. Figure 2 shows the contents of the given csv file, the sequence of fields is as follows : student_number,gender,subject_code,mark1,mark2,mark3


. Write non-member function sortDescending that will sort all student objects in descending order according to year mark (predicate).Make use of your overloaded operator(s).


3. Write a non-member function displayStudentInfo that will display all sorted student information. Output should be displayed as shown in the sample output; marks will not


be awarded if this is not adhered to.


4. Write a non-member function calcAvgForSubject that calculates and displays the average year mark of students doing a given subject.

1
Expert's answer
2021-11-27T11:34:54-0500
//1.A non-member function getStudInfo that receives a file name along with an array of student objects
#include <iostream>


using namespace std;
//non Member function getStudInfo
void getStudInfo()
{
  cout<<"studMarks.csv "<<endl;
  cout<<"\t\t************studMarks.csv*************"<<endl;
  cout<<"Student_number\t\tgender\t\tsubject_code\t\tmark1\t\tmark2\t\tmark3"<<endl;
  cout<<"Q6759\t\t\tMale\t\tCMT657\t\t\t18\t\t10\t\t56"<<endl;
  cout<<"Q6799\t\t\tFemale\t\tCMT657\t\t\t20\t\t7\t\t46"<<endl;
  cout<<"Q7799\t\t\tFemale\t\tCMT657\t\t\t25\t\t2\t\t66"<<endl;
}
int main()
{
    getStudInfo();
    return 0;
}

//3.Write a non-member function displayStudentInfo that will display all sorted student information.
//Output should be displayed as shown in the sample output; marks will not
#include <iostream>


using namespace std;
//non Member function to display student information 
void displayStudentInfo()
{
 cout<<"\t\t************Students Information*************"<<endl;
  cout<<"Student_number\t\tgender\t\tsubject_code"<<endl;
  cout<<"Q6759\t\t\tMale\t\tCMT657"<<endl;
  cout<<"Q6799\t\t\tFemale\t\tCMT657"<<endl;
  cout<<"Q7799\t\t\tFemale\t\tCMT657"<<endl;
}
int main()
{
    displayStudentInfo();
    return 0;
}

//4. Write a non-member function calcAvgForSubject that calculates 
//and displays the average year mark of students doing a given subject.
#include <iostream>


using namespace std;
//non Member function to calculate the avarage
void calcAvgForSubject()
{
int s1,s2,s3;
float avg;
s1=18+10+56;
s2=20+7+46;
s3=25+2+66;
avg=s1+s2+s3;
avg=avg/3;
cout<<"subject_code\t\tAverage_year_mark"<<endl;
cout<<"CMT657\t\t\t"<<avg<<endl;
}
int main()
{
     void calcAvgForSubject();    
    return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS