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=\dfrac{\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 = \dfrac{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} = \dfrac{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;
    	inData.open("gradeData.txt");
    
    	//Open output file
    	ofstream outData;
    	outData.open("transcript.txt");
    
    	//Declare variables for student name, semester, classes, grades, points, and credit hours
    	//More ...
    	
    	//Read data from the input file
    	//More ...
            //Hint: Use getline(inData, name) and getline(inData, semester) to read the first two lines containing student name and semester year.	
    
    	//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;
    
    	switch(grade)
    	{
    	case 'A':
    		pts = 4.0;
    		break;
    	case 'B':
    		pts = 3.0;
    		break;
    	case 'C':
    		pts = 2.0;
    		break;
    	case 'D':
    		pts = 1.0;
    		break;
    	case 'F':
    		pts = 0.0;
    		break;
    	default:
    		pts = 0.0;
    	}
    
    	return pts;
    }
    
    //Data file "gradeData.txt" contains the following:
    
    Olivia Miyazawa
    Fall 2023
    CSC1321 B
    ASE1311 F
    EXS1220 D
    PHY1401 C
    ENG1302 A
    
    
    //Output in transcript.txt:
    
    //*********** Transcript of Texas Welseyan University ***********
    //
    // Student Name: Olivia Miyazawa
    //     Semester: Fall 2023
    //  Total Hours: 15
    // Semester GPA: 2.07
    //
    //Classes taken and grades in Fall 2023:
    //CSC1321 B
    //ASE1311 F
    //EXS1220 D
    //PHY1401 C
    //ENG1302 A
    //***************************************************************
    
  3. Write a program to calculate student loan payment. Prompt the user of your program to enter the amount of loan, loan term, and interest rate. Use the following formular to calculate monthly payment. \( monthlyPayment = loanAmount \dfrac{ monthlyInterest{(1+monthlyInterest)}^{numberOfPayments} }{(1+monthlyInterest)^ {numberOfPayments} - 1}\)
    Note that the interest rate entered is a yearly interest rate. Dividing it by 12 gives a monthly interest rate. The number of payments = loan term (in years) times 12.
    Sample output:
    Enter the amount of your student loan: 50000
    Enter the number of years you want to repay your student loan: 10
    Enter the interest rate of your student loan: 0.054
    For a student loan amount of $50000.00 with an interest rate of 5.40% and a 10-year loan term,  
    your monthly payments are $540.16.
  4. 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.
  5. Your programs should be properly formatted using indentation and empty lines (spaces). Use "camel" notation for variable naming.
  6. 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.