Alright, I have written this program for class. I guess it's supposed to be pretty straight forward passing array elements around between functions. It's taken me the better part of two days to write it and finally have it compiled. now when I go to open it using the ./ method it tells me permission denied.
so I looked around the web and tried using the gcc filename -o a.out method and it gives me this garbage:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
/tmp/ccEdcxsV.o: In function `readStudentFile(int*, int*, int*)':
tests.cpp:(.text+0x14d): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream()'
tests.cpp:(.text+0x172): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)'
tests.cpp:(.text+0x18f): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
tests.cpp:(.text+0x1a3): undefined reference to `std::basic_ios<char, std::char_traits<char> >::operator void*() const'
tests.cpp:(.text+0x1c7): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
tests.cpp:(.text+0x1db): undefined reference to `std::basic_ios<char, std::char_traits<char> >::operator void*() const'
tests.cpp:(.text+0x203): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
tests.cpp:(.text+0x217): undefined reference to `std::basic_ios<char, std::char_traits<char> >::operator void*() const'
tests.cpp:(.text+0x22e): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::close()'
tests.cpp:(.text+0x23f): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()'
tests.cpp:(.text+0x25d): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()'
/tmp/ccEdcxsV.o: In function `inputStudentRecords(int*, int*, int*, int)':
|
I'm assuming my code is faulty, but why would it still compile?
If there are any truly kind people looking to help a brother out, I'll put my whole code down at the bottom. Any tips would be most welcome and I'll be very grateful!!
//This program will recieve input from a file (if available)and the
// user for student identification numbers, and two test scores.
// The program will output a 3 column table displaying the two test
//scores for each student as well as display the max score and
//min score for each test, as well as the average score for each test
// Program will work for up to 40 students.
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes//
///////////////////////
int readStudentFile (int [], int [], int []);
//three arrays as parameters for student ID, and test 1 and test 2
//scores
int inputStudentRecords (int [], int [], int [], int);
//three student arrays as parameter and int to count the records
void calculateStatistics (int [], int [], int, int, int, int, int,
float, float);
//parameters are the two test arrays, int for the count, two ints for
// thenminimum score of each test, two ints for the max score of
//each test and two floats for the avg of each test
void outputStudentRecords (int [], int [], int [], int, int, int, int, int,
float, float);
//parameters are 3 student arrays, int for the count variable,
//two ints for min scores, two ints for max scores, and two floats for
// avgs
int main()
{
int test1 [40];
int test2 [40];
int stuID [40];
int count;
int min1;
int max1;
int min2;
int max2;
float avg1;
float avg2;
//function call for reading in saved files
readStudentFile (stuID, test1, test2);
//function call for user input
inputStudentRecords(stuID, test1, test2, count);
//function call for calculating mins, maxs, and avgs
calculateStatistics (test1, test2, count, min1, min2,
max1, max2, avg1, avg2);
//function call for outputting data
outputStudentRecords (stuID, test1, test2, count,
min1, min2, max1, max2, avg1, avg2);
return 0;
}
int readStudentFile (int stuID [], int test1 [], int test2 [])
{
ifstream inputFile;
int count = 0;
//open file and read contents into arrays
inputFile.open("grades.doc");
while (inputFile >>test2[count])
{
while (inputFile >>test1[count])
{
while (inputFile >>stuID[count])
{
}
}
count++;
}
inputFile.close();
return count;
}
int inputStudentRecords (int stuID [], int test1 [], int test2[], int count)
{
int response = 1;//to initialize the while loop
while (response == 1)
{
cout << "Enter '1' if you have student records to ";
cout << "input. Otherwise, enter any other digit. ";
cin >> response;
if (response == 1)
{
cout << endl << "Enter student ID: ";
cin >> stuID [count];
cout << endl << "Enter student's grade for ";
cout << "Test 1: ";
cin >> test1 [count];
cout << endl << "Enter student's grade for Test 2: ";
cin >> test2 [count];
count++;
}
}
return count;
}
void calculateStatistics (int test1 [], int test2 [], int count, int min1, int min2,int max1, int max2, float avg1, float avg2)
{
int i;
int total1;
int total2;
min1 = test1 [0];
min2 = test2 [0];
max1 = test1 [0];
max2 = test2 [0];
for (i = 1; i <= count; i++)
{
if (test1 [i] < min1)
min1 = test1 [i];
}
{ if (test2 [i] < min2)
min2 = test2 [i];
}
{ if (test1 [i] > max1)
max1 = test1 [i];
}
{ if (test2 [i] > max2)
max2 = test2 [i];
}
{
total1 += test1 [i];
}
{
total2 += test2 [i];
}
avg1 = (total1 + test1 [0])/count;
avg2 = (total2 + test2 [0])/count;
}
void outputStudentRecords (int stuID [], int test1 [], int test2 [], int count,
int min1, int min2, int max1, int max2, float avg1,
float avg2)
{
cout << "Student ID \t Test 1 \t Test 2\n";
cout << "--------------------------------------------";
for (int i = 0; i <= count; i++)
{
cout << stuID [i] << "\t\t";
cout << test1 [i] << "\t";
cout << test2 [i] << endl;
}
cout << "Lowest: \t\t" << min1 << "\t" << min2 << endl;
cout << "Highest: \t\t" << max1 << "\t" << max2 << endl;
cout << "Average: \t\t" << setw(3) << avg1 << "\t" << avg2;
}