Programming Assignment: P3

  1. Read the following sample programs to find out the output with input of 10 20. Then run the program on computer and compare the output you found manually with the output from computer to make sure to understand basic C++ input.

    // Program Frame prompts the user to input values that
    // represent the dimensions of a print.  The amount of wood
    // needed for the frame is calculated and printed on the screen.
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main ()
      int  side;                  // Vertical dimension in inches
      int  top;                   // Horizontal dimension in inches
      int  inchesOfWood;          // Inches of wood needed
      cout << "Enter the vertical dimension of your print." << endl;   
      cout << "The dimension should be in whole inches. "
           << "Press return."  << endl;                                 
      cin >> side;                                             
      cout << "Enter the horizontal dimension of your print." << endl;   
      cout << "The dimension should be in whole inches. "
           << "Press return."  << endl;                                 
      cin  >> top;                                             
      inchesOfWood = top + top + side + side;                  
      cout << "You need "  << inchesOfWood  <<" inches of wood."  << endl;
      return 0;
  2. GPA Calculator: Write a C++ program that reads data from the input file (gradeData.txt) and then calculate GPA and total credit hours. Print them out along with other information into an output file (transcript.txt) in the required format given in the sample output file.

    Use the following formula to calculate GPA:

    \( GPA=\frac{\sum_{k=1}^n G_k H_k} {\sum_{k=1}^n H_k } \\ \)
    \(G_k\) is grade points earned for course k; \(H_k\) is the number of credit hours for course k

    For example:
    Courses Grades Points Hours Points x Hours
    CSC1321 B 3.0 3 9
    ASE1311 A 4.0 3 12
    EXS1220 D 1.0 2 2
    PHY1401 C 2.0 4 8
    ENG1301 F 0.0 3 0

    \( GPA = \frac{3 \times 3.0 + 3 \times 4.0 + 2 \times 1.0 + 4 \times 2.0 + 3 \times 0.0 }{ 3 + 3 + 2 + 4+3} = \frac{31}{15} = 2.07 \)
    //GPA Calculator
    //GPA is a credit hour weighted average.
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    using namespace std;
    double getPoints(char);
    int main()
    	//Open input file
    	ifstream inData;"gradeData.txt");
    	//Open output file
    	ofstream outData;"transcript.txt");
    	//Declare variables for student name, semester, classes, grades, points, and credit hours
    	//More ...
    	//Read data from the input file
    	//More ...
    	//Get credit hours for each class. e.g. if class1 <= CSC1321, then hours1 <= 1
    	hours1 = class1.substr(4, 1).at(0) - '0';
    	//More ...
    	//Get points for each letter grade. e.g. if grade1 <= B, then points1 <= 3.0
    	points1 = getPoints(grade1);
    	//More ...
    	//Calculate total credit hours. Add all credit hours.
    	//More ...
    	//Calculate credit hour weighted average using GPA calculation formula
    	//More ...
    	//Print transcript into the output file named "transcript.txt" The format should be the same as the sample.
    	//Keep two fractional places for GPA value.
    	//More ...
    	return 0;
    //Given a letter grade, it returns points earned.
    //For example, it returns 4.0 points for a grade of A
    double getPoints(char grade)
    	double pts = 0.0;
    	case 'A':
    		pts = 4.0;
    	case 'B':
    		pts = 3.0;
    	case 'C':
    		pts = 2.0;
    	case 'D':
    		pts = 1.0;
    	case 'F':
    		pts = 0.0;
    		pts = 0.0;
    	return pts;
    //Data file "gradeData.txt" contains the following:
    Julie Hough
    Fall 2018
    CSC1321 B
    ASE1311 A
    EXS1220 D
    PHY1401 C
    ENG1301 F
    //Output in transcript.txt:
    //*********** Transcript of Texas Welseyan University ***********
    // Student Name: Julie Hough
    //     Semester: Fall 2018
    //  Total Hours: 15
    // Semester GPA: 2.07
    //Classes taken and grades:
    //CSC1321 B
    //ASE1311 A
    //EXS1220 D
    //PHY1401 C
    //ENG1301 F
  3. At the top section of your program you need to use C++ comments to include your name, class name, programming assignment name, and date the program was written.
  4. Your programs should be properly formatted using indentation and empty lines (spaces). Use "camel" notation for variable naming.
  5. Upon completion, save all programs and the required output into a single text file using notepad (or notepad++). The file should be named in this format: P3_YourName.txt, for example, P3_JohnDoe.txt. Then submit to the Blackboard (Bb) as attachment by the deadline. The submission link on the Bb will be closed automatically after the deadline. Assignments that fail to follow the instructions will NOT be graded.