Question

Need the solutions for the following problem from Starting out with C++: From Control Structures Through...

Need the solutions for the following problem from Starting out with C++: From Control Structures Through Objects - 8th edition

CH.11 Page 651 Programing challenges #12

Please send the solution codes to [email protected] if you can.

Need the solutions for the following problem

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

const int columns = 4;

struct StuDent //user defined datatype

{

        int id[6];

        char names[6][20];

        int scores[6][4];

        double avg[6];

        char grade[6];

}; //semi-colon required

//pass by reference

void calculateAverage(StuDent&);

char letterGrade(StuDent&);

int main()

{

        const int rows = 6;

       

        //declare and allocate

        StuDent r;

       

        //enter student id

        cout<<"Student id: ";

               for(int i=0; i<6 ;i++)

        cin>>r.id[i];

       

       

        //enter student+scores

        for(int i=0; i<6 ;i++)

        {

               cout<<"Enter Name of student "<<i+1<<": ";

               cin>>r.names[i];

               cout<<endl;

        }

        for(int i=0; i<rows; i++)

        {

               cout<<"Enter "<<columns<<" scores for student "<<i+1<<": ";

               for (int j=0; j<columns; j++)

               {

                       cin>>r.scores[i][j];

               }

               cout<<endl;

        }

       

        //display

        cout<<"Student id: "<<r.id<<endl;

        cout<<"Scores: ";

        for(int i=0; i<4 ; i++)

               cout<<r.scores<<" ";

        cout<<endl;

       

        //compAvg

       

        calculateAverage(r);

       

        cout<<"Avg Score: "<<r.avg<<endl;

       

        letterGrade(r);

       

        cout<<"Letter Grade: "<<r.grade<<endl;

       

}//endmain

void avg(StuDent& r)

{

       

        int sum=0;

        for(int i=0; i<6 ; i++)

               sum+=r.scores[columns][i];

        r.avg=static_cast<double>(sum)/4;

                                         //error: incompatible types in

                                        //assignment of 'double' to 'double [6]'

                                       //

}

char grade(StuDent& r)

{

        int sum = 0;

        char grade;

        for(int j=0; j<6; j++)

        {

               sum += r.scores[columns][j];

        }

        double avg = sum/4;

        cout<<"Avg: "<<avg;

       

        if(avg >= 90)

               grade = 'A';

        if(avg >= 80 && avg < 90)

               grade = 'B';

        if(avg >= 70 && avg < 80)

               grade = 'C';

        if(avg >= 60 && avg < 70)

               grade = 'D';

        if(avg < 60)

               grade = 'F';

       

        return grade;

}

Add a comment
Know the answer?
Add Answer to:
Need the solutions for the following problem from Starting out with C++: From Control Structures Through...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT