I am new in C++ programming. My code gets error but i can't find and fix it. can someone help me?
error:
1>g:\assignment2\gpa_computation.cpp(51): warning C4700: uninitialized local variable 'GPA1' used
1>g:\assignment2\gpa_computation.cpp(52): warning C4700: uninitialized local variable 'sum_Unit' used
1>GPA_computation.obj : error LNK2019: unresolved external symbol "double __cdecl GPA(int,int * const,double * const,double * const,double)" (?GPA@@YANHQAHQAN1N@Z) referenced in function _main
1>GPA_computation.obj : error LNK2019: unresolved external symbol "void __cdecl input_data(int &,int * const,int *,double * const,double * const,int * const,int * const,class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?input_data@@YAXAAHQAHPAHQAN311AAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ofstream@DU?$char_traits@D@std@@@2@@Z) referenced in function _main
1>G:\assignment2\Debug\assignment2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is my code.
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#define SIZE 30
using namespace std;
void main ()
{
// function declaration
void input_data (int&, int[], int*, double[], double[], int[], int[], ifstream&, ofstream&);
void compute_grade (int*, int[], int[], double[], double[], double[], double[], ifstream&, ofstream&);
double GPA (int, int[], double[], double[], double);
void print_report (double, double[], int, int, ofstream&);
void print_out (int, int[], double, ofstream&);
void sort_list (int[], double, ofstream&);
//variable declaration
int matric[SIZE], course_no, count, sum_Unit, unit_no[SIZE], code[SIZE];
double GPA1, grade_average, cw[SIZE], exam[SIZE], middle_pt[SIZE], final_pt[SIZE];
count = 0;
ifstream inFile;
ofstream outFile;
inFile.open("studentsdata.txt", ios::in);
outFile.open("output.txt", ios::out);
if (inFile.fail())
{
cerr << "Input file could not be opened" << endl;
exit (-1);
}
if (outFile.fail())
{
cerr << "Output file could not be opened" << endl;
exit (-1);
}
outFile << "\t\tUNIVERSITI SAINS MALAYSIA\n" << endl;
outFile << "\tSTUDENTS' RESULTS SEMESTER 1 ACADEMIC YEAR 2014/2015\n\n";
outFile << "________________________________________________________________________________";
while (!inFile.eof())
{
input_data (count, matric, &course_no, cw, exam, unit_no, code, inFile, outFile);
compute_grade (&course_no, unit_no, code, cw, exam, middle_pt, final_pt, inFile, outFile);
grade_average = GPA (course_no, unit_no, middle_pt, final_pt, GPA1);
print_report (grade_average, final_pt, course_no, sum_Unit, outFile);
print_out (count, matric, grade_average, outFile);
sort_list (matric, GPA1, outFile);
count++;
}
inFile.close();
outFile.close();
_getch();
}
void input_data (int count, int matric[], int *course_no, double cw[], double exam[], int unit_no[], int code[], ifstream &inFile, ofstream &outFile)
{
inFile >> matric[count];
inFile >> *course_no;
for (int i = 0; i < *course_no; i++)
{
inFile >> unit_no[i] >> cw[i] >> exam[i] >> code[i];
}
outFile << "Matric Number: " << matric << endl;
outFile << "\nThe number of courses taken: " << course_no << endl;
outFile << "\n\nUnits\t\tCW Grade\t\tExam Grade\t\tCode (1 for 30/70; 2 for 40/60)";
for (int i = 0; i < *course_no; i++)
{
outFile << unit_no << "\t\t" << cw[i] << "\t\t" << exam[i] << "\t\t" << code[i];
outFile << endl;
}
}
void compute_grade (int* course_no, int code[], int unit_no[], double cw[], double exam[], double middle_pt[], double final_pt[], ifstream &inFile, ofstream &outFile)
{
for (int i = 0; i <= *course_no; i++)
{
if (code[i] == 1)
{
middle_pt[i] = (cw[i] * 0.3) + (exam[i] * 0.7);
}
else if (code[i] == 2)
{
middle_pt[i] = (cw[i] * 0.4) + (exam[i] * 0.6);
}
outFile << endl << "Final grades" << endl;
for (i = 0; i <= *course_no; i++)
{
if (middle_pt[i] >= 3.84 && middle_pt[i]<= 4.00)
{
final_pt[i] = 4.00;
outFile << "Course: " << i+1 << "A";
}
if (middle_pt[i] >= 3.50 && middle_pt[i] <= 3.83)
{
final_pt[i] = 3.67;
outFile << "Course: " << i+1 << "A-";
}
if (middle_pt[i] >= 3.17 && middle_pt[i] <= 3.49)
{
final_pt[i] = 3.33;
outFile << "Course: " << i+1 <<"B+";
}
if (middle_pt[i] >= 2.84 && middle_pt[i] <= 3.16)
{
final_pt[i] = 3.00;
outFile << "Course: " << i+1 << "B";
}
if (middle_pt[i] >= 2.50 && middle_pt[i] <= 2.83)
{
final_pt[i] = 2.67;
outFile << "Course: " << i+1 << "B-";
}
if (middle_pt[i] >= 2.17 && middle_pt[i] <= 2.49)
{
final_pt[i] = 2.33;
outFile << "Course: " << i+1 << "C+";
}
if (middle_pt[i] >= 1.84 && middle_pt[i] <= 2.16)
{
final_pt[i] = 2.00;
outFile << "Course: " << i+1 << "C";
}
if (middle_pt[i] >= 1.50 && middle_pt[i] <= 1.83)
{
final_pt[i] = 1.67;
outFile << "Course: " << i+1 << "C-";
}
if (middle_pt[i] >= 1.17 && middle_pt[i] <= 1.49)
{
final_pt[i] = 1.33;
outFile << "Course: " << i+1 << "D+";
}
if (middle_pt[i] >= 0.84 && middle_pt[i] <= 1.16)
{
final_pt[i] = 1.00;
outFile << "Course: " << i+1 << "D";
}
if (middle_pt[i] >= 0.34 && middle_pt[i] <= 0.83)
{
final_pt[i] = 0.67;
outFile << "Course: " << i+1 << "D-";
}
if (middle_pt[i] >= 0.00 && middle_pt[i] <= 0.33)
{
final_pt[i] = 0.00;
outFile << "Course: " << i+1 << "F";
}
}
}
}
double GPA (int course_no, int unit_no[], double middle_pt, double final_pt[], double GPA1)
{
int i , Unit, sum_Unit;
double sum_UM, UM;
sum_UM = 0;
sum_Unit = 0;
for (i = 0; i < course_no ; i++)
{
UM = unit_no[i] * final_pt[i];
sum_UM = sum_UM + UM;
Unit = unit_no[i];
sum_Unit = sum_Unit + Unit;
}
GPA1 = sum_UM / sum_Unit;
return GPA1;
}
void print_report (double grade_average, double final_pt[], int course_no, int sum_Unit, ofstream &outFile)
{
int i, sum1, sum2;
sum1 = 0;
sum2 = 0;
outFile << "Grade Point Average = " << grade_average << endl;
for (i =0; i < course_no; i++)
{
if (grade_average >= 2.00)
outFile << "\nStatus : Active " ;
else
outFile << "Under probation";
}
for (i = 0; i < course_no; i++)
{
if (final_pt[i] >= 2.00)
{
sum1 = sum1 + 1;
outFile << "\nDo not need to repeat any course.";
}
else if (final_pt[i] < 2.00)
{
sum2 = sum2 + 1;
outFile << "\nNeed to repeat " << sum2 << "course.";
}
}
if (grade_average >= 3.5 && sum_Unit >= 12)
outFile << "\nEligible for Dean's list.";
else
outFile << "\nNot eligible for Dean's list.";
}
void print_out (int count, int matric_no[], double grade_average, ofstream &outFile)
{
outFile << endl << endl;
outFile << "-----------------------------------------------------------------------" << endl;
outFile << "\n\t\tOverall Students' Grades" << endl;
outFile << "-----------------------------------------------------------------------" << endl;
outFile << "\tMatric\t\tGPA";
for (int i = 0; i < count; i++)
{
outFile << i << "\t" << matric_no[i] << "\t\t" << grade_average << endl;
}
}
void sort_list (int matric_no[], double grade_average, ofstream &outFile)
{
int i, pass, hold;
outFile << endl << endl;
outFile << "\t\tSorted Students' Grades" << endl;
outFile << "------------------------------------------------------------------------" << endl;
outFile << "\tMatric\t\tGPA" << endl;
for (pass = 1; pass < SIZE; pass++)
{
for (i = 0; i < SIZE-1; i++)
{
if (matric_no[i] < matric_no[i+1])
{
hold = matric_no[i];
matric_no[i] = matric_no[i+1];
matric_no[i+1] = hold;
}
}
}
for (i = 0; i < SIZE; i++)
{
outFile << i << "\t" << matric_no[i] << "\t\t" << grade_average;
}
}