i have this project for my class that i am having a few syntax errors with.
the whole story of the project is to create an array from 3 numbers stored in a txt file. I need to pull the data from the file, display it, write the data to an array, organize them(#order) and re-write them to the txt file in that order. then display that order, find the sum of those numbers, average them & display them both. these projects all require a 3 file object oriented project with a *.h file, *.cpp file and a main.cpp file. all the function prototypes are in the *.h file, & all match the functions in the test.cpp file.
i feel comfortable with the functions i have written(but im not 100%), but i am having issues with the program actually reading/using those functions. even with a cout <<" "<< in the function, it doesnt display in the program.
"Test.cpp"--where the work of my code is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include<fstream>
#include<string>
#include "Test.h"
using namespace std;
const int size = 100;
ifstream ifs;
int mainer()
{
void TakeTrial();
void SortNums(int);
int AveNums(int);
int Total(int);
void write(int);
void display(int);
return 0;
}
void Testing::TakeTrial()
{
ifs.open("trial.txt");//using the text file.
for (int i = 0; i < 100; i++)//reading files into the array
{
while (i < 100 && ifs >> array[i])
i++;
}
for (int i = 0; i < 3; i++)
{
cout << array[i] << endl;
}
ifs.close();
}
void Testing::SortNums(int array[])
{
ifs.open("trial.txt");
int temp;
if (array[0] > array[1])
{//swapping
temp = array[0];
array[0] = array[1];
array[1] = temp;
}
if (array[1] > array[2])
{
temp = array[1];
array[1] = array[2];
array[2] = temp;
}
for (int i = 0; i < 3; i++)
{
cout << "the new order is given" << endl;
cout << array[i];
}
ifs.close();
}
int Testing::AveNums(int array[])
{
int average;
int total = 0;
for (int i = 0; i < 3; i++)
{
total += array[i];
}
average = total / 3;
cout<<"the average is: " << average << endl;
return average;
}
int Testing::total(int array[])
{
int total = 0;
for (int i = 0; i < 3; i++)
{
total += array[i];
}
return total;
}
void Testing::write(int array[])
{
ofstream ofs;
ofs.open("trial.txt");
cout << "writing to file" << endl;
for (int i = 0; i < 3; i++)
ofs << array[i];
ofs.close();
}
void Testing::display(int array[])
{
cout << "Numbers" << endl;
cout << array[0] << endl << array[1] << array[2] << endl;
}
|
this is the header file "Test.h"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef Test_H//this will be the name of the .cpp file and header file
#define Test_H// this will also be the name of the .cpp file and header file
class Testing
{
private:
int array[100];
public:
void TakeTrial();////list prororypes
void SortNums(int array[]);
int AveNums(int array[]);
int total(int array[]);
void write(int array[]);
void display(int array[]);
};
#endif
|
the only function that runs is the first one, displaying the numbers from the text file.
<3 look forward to hearing your advise
Thanks in advance :D
(If you need the main.cpp file, i can post it)