Help

So is there away for me to grab the grade points out of my "double average(string grade) function? I need the number I get from "x" that is returned, to be sent to my "void report(double [], int*) function. Everything else is working. I also need to incorporate a way for my report function to decide whether or not the grade from "average(string grade) function is an F or not. Any help is appreciated and welcomed thank you. I am new but I want to learn as much as I can so explain in detail if possible thanks again!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;

double average(string);
char user(string*, string*, int*);
void input(string [], string [], double [], string [], int);
void report(double [], int*);

int main()
{
        //declare variables for function calls
        string student, term, grade;
        int numClasses;
        int *size = &numClasses;

        //call function to get information on student specifics
        user(&term, &student, &numClasses);

        //get arrays for student infomation
        string classList[numClasses];
        string classDescrip[numClasses];
        double units[numClasses];
        string grades[numClasses];


        //function call student "Class specifics" specifics
        input(classList, classDescrip, units, grades, numClasses);
        string *x = grades[numClasses];
        cout<<*x;
        //print out gpa report
        report(units, size);
        return 0;
}
double average(string grade)
{
        //use function to get grade points based off grade letter
        double x;
        if(grade == "A")
        {
                x = 4.0;
        }
        else if(grade == "A-")
        {
                x = 3.67;
        }
        else if(grade == "B+")
        {
                x = 3.33;
        }
        else if(grade == "B")
        {
               x = 3.0;
        }
        else if(grade == "B-")
        {
                x = 2.67;
        }
        else if(grade == "C+")
        {
                x = 2.33;
          }
        else if(grade == "C")
        {
                x = 2.0;
        }
        else if(grade == "C-")
        {
                x = 1.67;
        }
        else if(grade == "D+")
        {
                x = 1.33;
        }
        else if(grade == "D")
        {
                x = 1.0;
        }
        else if(grade =="D-")
        {
                x = .67;
        }
        else if(grade == "F")
        {
                x = 0.0;
        }
        else
        {
                cout<<"\n Grade letter not recognized"<<endl;
        }
        return x;
}
char user(string *term, string *student, int *x )
{
        //grab student specifics
        cout<<"\n What is the term? (Spring or Fall): ";
        cin>>*term;
        cout<<"\n What is the Student name?: ";
        cin>>*student;
        cout<<"\n Number of courses this student is enrolled in?: ";
        cin>>*x;
        cin.ignore();
}
void input(string *num, string *descr, double *units, string *grades, int size)
{
        //declare x as array for information
        double x[size];
        //for loop to loop throug array based on number of courses taken to grab information
        for(int i = 0; i < size; i++){
        cout<<"\n Enter Class Here: ";
        getline(cin,num[i]);
        cout<<"\n Class Description: ";
        getline(cin,descr[i]);
        cout<<"\n Enter number of units: ";
        cin>>units[i];
        cin.ignore();
        cout<<"\n Grade in class ";
        getline(cin,grades[i]);

        //grade points times number of units gets grade point score
        x[i] = average(grades[i]) * units[i];
        }
        //Student name, semester and number of classes should show here, but I did not complete this part. Very confused.
        //" This should say "Student Name" during "(???) Semester"

        //size for columns to make report
        cout << setw(10)<<"Class Number"<<setw(18)<<"Decription"<< setw(18)<< setprecision(2)<<"Units"<< setw(18)<<"Grade"<<setw(18)<<setprecision(4)<<"Grade Points"<<endl;
        for(int i = 0; i < size; i++){
        cout<<setw(12)<<num[i];
        cout<<setw(18)<<descr[i];
         cout<<"\n Enter number of units: ";
        cin>>units[i];
        cin.ignore();
        cout<<"\n Grade in class ";
        getline(cin,grades[i]);

        //grade points times number of units gets grade point score
        x[i] = average(grades[i]) * units[i];
        }
        //Student name, semester and number of classes should show here, but I did not complete this part. Very confused.
        //" This should say "Student Name" during "(???) Semester"

        //size for columns to make report
        cout << setw(10)<<"Class Number"<<setw(18)<<"Decription"<< setw(18)<< setprecision(2)<<"Units"<< setw(18)<<"Grade"<<setw(18)<<setprecision(4)<<"Grade Points"<<endl;
        for(int i = 0; i < size; i++){
        cout<<setw(12)<<num[i];
        cout<<setw(18)<<descr[i];
        cout<<setw(18)<<setprecision(2)<<units[i];
        cout<<setw(18)<<grades[i];
        cout<<setw(18)<<setprecision(3)<<x[i]<<endl;
        }
}
void report(double *units, int *size)
{
        string grades;
        int i = 0;
        int x = 0;
        //sizing stats for second report
        cout<<setw(10)<<"\n Taken: "<<setw(38)<<setprecision(3)<<(*units * (*size)) ;
        cout<<setw(10)<<"\n Passed: "<< setw(37)<<setprecision(3)<<*size;
        cout<<setw(10)<<"\n GPA Calculation: "<<setw(28)<<setprecision(3)<<endl;
        cout<<setw(10)<<"\n Total Grade Points: "<<setw(25)<<setprecision(3)<<*size;
        cout<<setw(10)<<"\n /Units Taken By Total GPA: "<<setw(18)<<setprecision(3)<<units;
        cout<<setw(10)<<"\n =GPA: "<<setw(39)<<setprecision(3)<<*units<<endl;
}
                     
Last edited on
Topic archived. No new replies allowed.