Can anyone help me figure out how to write this program?

closed account (GhvX92yv)
I am trying to make a program that will calculate gpa using a transcript from an input file. The transcript includes the title of the subject, the letter grade, and the credits per class. However, I wouldn't know how many courses are in the file. How would I start to write out this program? The only things I can use are ifstream, ofstream, for-loops, if statements, and if-else statements.
Wouldn't the grades just be single letters? Can you assume the class would not be a single letter in name?

I would write this program by scanning the file 1 char at a time and putting them into char* based on spaces (if you cant use strings). I would throw out any char* that are bigger than 1 immediately.

The weight calibration could be a little tricky so you may have to wait until the end of the program and save a char* of grades with an int* of hours, with correlating indices from grade to weight. (do 1 input of grade amout per hour and then divide at the end by total number of hours)

Also, I would assume a standard grading scale based to A B C D F and appropriate weight for each letter grade.
Last edited on
closed account (GhvX92yv)
No, the class would be a single letter.

How would I start to type out the code for the program?

I dont have a compiler handy. But based on http://www.cplusplus.com/doc/tutorial/files/ to handle file IO.



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
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () 
{
  cahr ch; 
  ifstream myfile ("example.txt");
  int totalPoints = 0, totalPossible = 0;

  if (myfile.is_open())
  {
     while (inFile >> ch)
     {
        if(ch == 'A')
        {
           //advance in file to get # of hours         
           totalPoints += 4 * #hours;
           totalPossible+= #hours; 
        }
        if(ch == 'B')
        {
           //advance in file to get # of hours         
           totalPoints += 3 * #hours;
           totalPossible+= #hours;  
        }
        if(ch == 'C')
        {
           //advance in file to get # of hours         
           totalPoints += 2 * #hours;
           totalPossible+= #hours; 
        }
        if(ch == 'D')
        {
           //advance in file to get # of hours         
           totalPoints += 1 * #hours;
           totalPossible++= #hours;  
        }
        if(ch == 'F')
        {
           //advance in file to get # of hours  
           totalPossible+= #hours;  
        }

     }
 }

  else cout << "Unable to open file"; 

  cout<< "GPA: " << totalPoints / totalPossible;

  return 0;
}


There must be better criteria for the syntax of the transcript. I am assuming no class can be named A B C D or F. Also, this code would break when a class contained with A B C D or F in the name. Also, I was not able to compile and insure this would work correctly but maybe it will give you a kickstart?
Last edited on
Topic archived. No new replies allowed.