calculate CGPA with recursion help

How do I calculate CGPA while only using recursive and with no loops. I know that you multiply the grade by the credit hours and then divide that by the total credit hours but I can't seem to get the calculation right. I can get the data from the .txt file so that it's correct but it does not display like it should. I know to calculate CGPA you would do: //3.2(2)/17+3.6(4)/17+2.6(4)/17+3.2(4)/17+3.8(3)/17 = 3.259. but when I do it, it gives me 1.
I'm fairly sure that it has something to do with my calculateGPA.
Here is the data from my .txt file:
1400,Introduction to Programming,4,3.6
1410,C++ Programming,4,2.6
2420,Introduction to Data Structures,4,3.2
2810,Computer Architecture,3,3.8
1030,Introduction to Computers,2,3.2
// Recursion.cpp : Defines the entry point for the console application.
#include <iostream>
#include <fstream>
#include "LinkedList.h"
#include "Course.h"
using namespace std;
int main()
{
char dataFileName[] = "data.txt";
ifstream fileData;
fileData.open(dataFileName, 0);
if (fileData.good() == false)
{
cout << "ERROR: can't open data file: " << dataFileName << endl;
// wait for the user to press enter to quit
cout << endl << "Press the [Enter] key to quit...";
getchar();
return -1;
}
{
LinkedList courses;
while (fileData.eof() == false)
{
int courseNumber = 0;
string courseName = "";
unsigned int creditHours = 0;
double grade = 0.0;
fileData >> courseNumber;
if (fileData.good() == false)
break;
fileData.ignore(1024, ',');
getline(fileData, courseName, ',');
fileData >> creditHours;
fileData.ignore(1024, ',');
fileData >> grade;
// add a course
courses.insert(new Course(courseNumber, courseName, creditHours, grade));
}
fileData.close();
// display the ordered list of courses
courses.PrintList();
double gpa = courses.CalculateGPA();
cout.precision(4);
cout << "Cumulative GPA: " << gpa << endl;
// wait for the user to press enter to quit
cout << endl << "Press the [Enter] key to quit...";
getchar();
}
return 0;
}
#pragma once
#include "Course.h"
class LinkedList
{
public:
LinkedList();
~LinkedList();
// prints the contents of the list of courses to cout
void PrintList();
// precondition: list is in sorted order
// postcondition: newCourse is inserted into the list so the list maintains
//sorted order. using recursison.
void insert(Course* newCourse);
// postcondition: size is returned. Must be calculated using recursion.
unsigned int size();
// calculates the Cumulative GPA of all courses in the list.
// Cumulative GPA is the sum of all earned grade points divided by the sum of all credits
// grade points is found by multiplying the grade of a course by the number of credits for that course
// this must be calculated recursively.
double CalculateGPA();
private:
Course * head_ptr; // start of linked list
Course *InsertAfter(Course *head_ptr, Course *newCourse); // recursive helper for insert()
unsigned int SizeHelper(Course *ptr); // recursive helper for size()
void PrintListHelper(Course *course); // recursive helper for PrintList()
double GradeHelper(Course*);
unsigned int TotalCredits(Course*);
double CalculateTotalGradePoints(); // total of all earned Grade Points in list of courses
unsigned int CalculateTotalCredits(); // total of all credits in list of courses
};
#include "LinkedList.h"
#include <iostream>
LinkedList::LinkedList()
{
head_ptr = nullptr;
}
LinkedList::~LinkedList()
{
}
void LinkedList::PrintList()
{
}
void LinkedList::insert(Course * newCourse)
{
if (head_ptr == nullptr)
{
head_ptr = newCourse;
}
else
{
Course *lastNode = InsertAfter(head_ptr , newCourse);
lastNode->next = newCourse;
}
}
unsigned int LinkedList::size()
{
if (head_ptr == nullptr)
return 0;
//Course* temp = head_ptr;
//int used = 0;
return 0;
}
double LinkedList::CalculateGPA()
{
return CalculateTotalGradePoints() * CalculateTotalCredits() / 17;
//return 3.259;
}
Course * LinkedList::InsertAfter(Course * head_ptr, Course * newCourse)
{
if (head_ptr->next == nullptr)
return head_ptr;
else
{
return InsertAfter(head_ptr->next, newCourse);
}
}
unsigned int LinkedList::SizeHelper(Course * ptr)
{
return 0;
}
void LinkedList::PrintListHelper(Course * course)
{
}
double LinkedList::GradeHelper(Course * course)
{
if(course = nullptr)
return 0;
else
{
return true;
}
}
unsigned int LinkedList::TotalCredits(Course * course)
{
return;
}
double LinkedList::CalculateTotalGradePoints()
{
return; }
unsigned int LinkedList::CalculateTotalCredits()
{
return TotalCredits(head_ptr);
}
and then there is this code that I couldn't include:
#pragma once
#include <string>
using namespace std;

class Course
{
public:
// parameterized constructor
Course(int courseNumber, string courseName, unsigned int credits, double grade);

// destructor
~Course(); // use recursion to delete all Courses in the list

// returns the Grade Points (grade * credits) for this currentCourse and all
// courses linked to currentCourse
// must use recursion
double CalculateGradePoints(Course *currentCourse);

// returns the total credits for the currentCourse and all courses linked to currentCourse
// must use recursion
unsigned int CalculateCredits(Course *currentCourse);

// next Course in the linked list
Course *next;

unsigned int courseNumber; // ie: 1400, 1410, 2420, etc...
string courseName;
unsigned int credits; // 0 - 4
double grade; // 0.0 - 4.0
}

#include "Course.h"
#include <string>

Course::Course(int courseNumber, string courseName, unsigned int credits, double grade)
{
this->courseNumber = courseNumber;
this->courseName = courseName;
this->credits = credits;
this->grade = grade;
}

Course::~Course()
{

}

double Course::CalculateGradePoints(Course * currentCourse)
{
return; not sure what to return here
}

unsigned int Course::CalculateCredits(Course *currentCourse)
{
return; I'm not sure what to return here
}
Topic archived. No new replies allowed.