nateholtrop
Diamond Member
ok my compiler is old and i cant find Borland 5.02 to do this on all i have is 5.01 ya really i know ahhha. heres the assignment...
write an oop program that will read a data file of student names, ages, number of tests taken and test scores. The program should firs redisplay the students names ages and average the scores. The sorted output data should be displayed in a table format with an appropriate header.
I have all of that done but i think its just a matter of getting it all in the right order which i am strugglin with. thanks for you help see BELOW FOR FILES!
my header file
__________________
//==includes
#ifndef class_h
#define class_h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <fstream.h>
//==prototypes
//==globles
//===================================
// Nathan Holtrop //
// co 127 - 6921 //
// m00.h //
//===================================
extern ofstream outfile;
extern ifstream infile;
void report();
int main(argc, char* argv[])
{
if (argc !=3)
cerr << "\n\tFormat: student infilename outfilename";
// read from standard output
exit(-1);
}
infile.open(argv[2], ios::in);
if(!infile)
{
cerr << "\n\t Can't open " << argv[1];
exit(-1);
}
outfile.open(argv[2], ios:😱ut);
if(!outfile)
{
cerr << "\n\tCant Open " << argv[2];
exit(-1);
}
report();
infile.close();
outfile.close();
}
void center(char* s)
{
int spaces;
spaces = (80 + strlen(s)) / 2;
fileout << setw(spaces);
fileout << s << endl;
}
class student
{
private:
char name[21];
int age;
int numtest;
int score[5];
public:
student();
student(char *n, int a = 0, int t = 0, int s1 = 0, int s2 = 0,
int s3 = 0, int s4 = 0, int s5 = 0) : age(a), numtest(t)
{
strcpy(name, n);
score[0] = s1;
score[1] = s2;
score[2] = s3;
score[3] = s4;
score[4] = s5;
}
void input();
void print();
void copy(student & s);
char* name_is();
int age_is();
int numtest_is();
int score_is(int i);
friend int operator< (student s1, student s2);
float average_grade();
};
#endif
_________________________________________________
my main.cpp
____________________
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include "m00.h"
#include "student.h"
void main()
{
// First segment:
const int MAX = 3;
student studx[MAX] =; // hard coded array of 3 student objects
{
student( "Randy" , 34 , 2 , 70, 70),
student( "Mary" , 25 , 3 , 90 , 80 , 100),
student( "Bill" , 36 , 1 , 100)
};
// End segment:
*/
// Second:
// change value of MAX to 10
// create an array of 10 student objects to store student data
// use the previously created array of floats
// this array will call the default constructor
// GET STUDENTS FROM FILE TO BE SORTED
// used with default constructor only
// comment out for hard coded constuctor use
student studx[MAX];
for (int i = 0; i < MAX; i++)
{
studx.input();
}
//title output
center("Programming Student Grades"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉;
for (int i = 0; i < MAX; i++)
{
studx.print();
}
// SORT THE ARRAY INTO ALPHABETICAL ORDER BY STUDENT NAME
student temp;
int i,j; //loop counters
for (i = 0; i < MAX - 1; i++)
{
for (j = i + 1; j < MAX; j++)
{
if (studx[j] < studx)
{
temp = studx;
studx = studx[j];
studx[j] = temp;
}
}
}
________________________________________
my other cpp file
_____________________________
// Test program to evaluate header file and function definitions
// for student project. Files used:
//
//========================================================
// Project files:
// student.cpp - definitions
// stud.cpp - main program file for testing
// m00.cpp - implementation of myheader.h file
// Data files:
// stud1.dat and/or stud2.dat
//========================================================
//==Includes
#include <student.h> //for student object
#include <m00.h>
#include <class.h> //for center and stuff.
//==Globles
const int MAX = 10;
extern ofstream outfile;
extern ifstream infile;
//==Functions
/* void main()
{
/*
// First segment:
student studx[MAX] = // hard coded array of 3 student objects
{
student( "Randy" , 34 , 2 , 70, 70),
student( "Mary" , 25 , 3 , 90 , 80 , 100),
student( "Bill" , 36 , 1 , 100)
};
// End segment:
*/
// Second:
// change value of MAX to 10
// create an array of 10 student objects to store student data
// use the previously created array of floats
// this array will call the default constructor
// GET STUDENTS FROM FILE TO BE SORTED
// used with default constructor only
// comment out for hard coded constuctor use
/* student studx[MAX];
for (int i = 0; i < MAX; i++)
{
studx.input();
}
//title output
center("Programming Student Grades"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉;
for (int i = 0; i < MAX; i++)
{
studx.print();
}
// SORT THE ARRAY INTO ALPHABETICAL ORDER BY STUDENT NAME
student temp;
int i,j; //loop counters
for (i = 0; i < MAX - 1; i++)
{
for (j = i + 1; j < MAX; j++)
{
if (studx[j] < studx)
{
temp = studx;
studx = studx[j];
studx[j] = temp;
}
}
}
center("Sorted Output from Student Grades Program"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉; */
//output!!!
void report();
int main(argc, char* argv[])
{
if argc !=3)
{
cerr << "\n\tFormat: student infilename outfilename";
// read from standard output
exit(-1);
}
infile.open(argv[2], ios::in);
if(!infile) {
cerr << "\n\t Can't open " << argv[1];
exit(-1);
}
outfile.open(argv[2], ios:😱ut);
if(!outfile) {
cerr << "\n\tCant Open " << argv[2];
exit(-1);
}
report();
infile.close();
outfile.close();
return 0;
}
const int buff = 10;
const int col1 = 20;
const int col2 = 10;
const int col3 = 30;
fileout << setiosflags( ios::left );
fileout << setw(buff) << "" << setw(col1) << "Student";
fileout << setiosflags( ios::right );
fileout << setw(col2) << "" << setw(col3) << " Average";
fileout << endl;
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << " Name ";
fileout << setiosflags( ios::right );
fileout << setw(col2) << "Age" << setw(col3) << "Test Grade";
fileout << endl;
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << "-------";
fileout << setiosflags( ios::right);
fileout << setw(col2) << "---" << setw(col3) << "----------";
fileout << endl << endl;
for( int k = 0; k < MAX; k++)
{
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << studx[k].name_is();
fileout << setiosflags( ios::right);
fileout << setw(col2) << studx[k].age_is() << setw(col3) << studx[k].average_grade();
fileout << endl;
}
} // End of function main()
PS THANKS FOR READING THIS FAR!! THANKS A MILLION!
write an oop program that will read a data file of student names, ages, number of tests taken and test scores. The program should firs redisplay the students names ages and average the scores. The sorted output data should be displayed in a table format with an appropriate header.
I have all of that done but i think its just a matter of getting it all in the right order which i am strugglin with. thanks for you help see BELOW FOR FILES!
my header file
__________________
//==includes
#ifndef class_h
#define class_h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <fstream.h>
//==prototypes
//==globles
//===================================
// Nathan Holtrop //
// co 127 - 6921 //
// m00.h //
//===================================
extern ofstream outfile;
extern ifstream infile;
void report();
int main(argc, char* argv[])
{
if (argc !=3)
cerr << "\n\tFormat: student infilename outfilename";
// read from standard output
exit(-1);
}
infile.open(argv[2], ios::in);
if(!infile)
{
cerr << "\n\t Can't open " << argv[1];
exit(-1);
}
outfile.open(argv[2], ios:😱ut);
if(!outfile)
{
cerr << "\n\tCant Open " << argv[2];
exit(-1);
}
report();
infile.close();
outfile.close();
}
void center(char* s)
{
int spaces;
spaces = (80 + strlen(s)) / 2;
fileout << setw(spaces);
fileout << s << endl;
}
class student
{
private:
char name[21];
int age;
int numtest;
int score[5];
public:
student();
student(char *n, int a = 0, int t = 0, int s1 = 0, int s2 = 0,
int s3 = 0, int s4 = 0, int s5 = 0) : age(a), numtest(t)
{
strcpy(name, n);
score[0] = s1;
score[1] = s2;
score[2] = s3;
score[3] = s4;
score[4] = s5;
}
void input();
void print();
void copy(student & s);
char* name_is();
int age_is();
int numtest_is();
int score_is(int i);
friend int operator< (student s1, student s2);
float average_grade();
};
#endif
_________________________________________________
my main.cpp
____________________
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include "m00.h"
#include "student.h"
void main()
{
// First segment:
const int MAX = 3;
student studx[MAX] =; // hard coded array of 3 student objects
{
student( "Randy" , 34 , 2 , 70, 70),
student( "Mary" , 25 , 3 , 90 , 80 , 100),
student( "Bill" , 36 , 1 , 100)
};
// End segment:
*/
// Second:
// change value of MAX to 10
// create an array of 10 student objects to store student data
// use the previously created array of floats
// this array will call the default constructor
// GET STUDENTS FROM FILE TO BE SORTED
// used with default constructor only
// comment out for hard coded constuctor use
student studx[MAX];
for (int i = 0; i < MAX; i++)
{
studx.input();
}
//title output
center("Programming Student Grades"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉;
for (int i = 0; i < MAX; i++)
{
studx.print();
}
// SORT THE ARRAY INTO ALPHABETICAL ORDER BY STUDENT NAME
student temp;
int i,j; //loop counters
for (i = 0; i < MAX - 1; i++)
{
for (j = i + 1; j < MAX; j++)
{
if (studx[j] < studx)
{
temp = studx;
studx = studx[j];
studx[j] = temp;
}
}
}
________________________________________
my other cpp file
_____________________________
// Test program to evaluate header file and function definitions
// for student project. Files used:
//
//========================================================
// Project files:
// student.cpp - definitions
// stud.cpp - main program file for testing
// m00.cpp - implementation of myheader.h file
// Data files:
// stud1.dat and/or stud2.dat
//========================================================
//==Includes
#include <student.h> //for student object
#include <m00.h>
#include <class.h> //for center and stuff.
//==Globles
const int MAX = 10;
extern ofstream outfile;
extern ifstream infile;
//==Functions
/* void main()
{
/*
// First segment:
student studx[MAX] = // hard coded array of 3 student objects
{
student( "Randy" , 34 , 2 , 70, 70),
student( "Mary" , 25 , 3 , 90 , 80 , 100),
student( "Bill" , 36 , 1 , 100)
};
// End segment:
*/
// Second:
// change value of MAX to 10
// create an array of 10 student objects to store student data
// use the previously created array of floats
// this array will call the default constructor
// GET STUDENTS FROM FILE TO BE SORTED
// used with default constructor only
// comment out for hard coded constuctor use
/* student studx[MAX];
for (int i = 0; i < MAX; i++)
{
studx.input();
}
//title output
center("Programming Student Grades"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉;
for (int i = 0; i < MAX; i++)
{
studx.print();
}
// SORT THE ARRAY INTO ALPHABETICAL ORDER BY STUDENT NAME
student temp;
int i,j; //loop counters
for (i = 0; i < MAX - 1; i++)
{
for (j = i + 1; j < MAX; j++)
{
if (studx[j] < studx)
{
temp = studx;
studx = studx[j];
studx[j] = temp;
}
}
}
center("Sorted Output from Student Grades Program"😉;
center("Prepared by Nathan Holtrop"😉;
center("May 1, 2001"😉; */
//output!!!
void report();
int main(argc, char* argv[])
{
if argc !=3)
{
cerr << "\n\tFormat: student infilename outfilename";
// read from standard output
exit(-1);
}
infile.open(argv[2], ios::in);
if(!infile) {
cerr << "\n\t Can't open " << argv[1];
exit(-1);
}
outfile.open(argv[2], ios:😱ut);
if(!outfile) {
cerr << "\n\tCant Open " << argv[2];
exit(-1);
}
report();
infile.close();
outfile.close();
return 0;
}
const int buff = 10;
const int col1 = 20;
const int col2 = 10;
const int col3 = 30;
fileout << setiosflags( ios::left );
fileout << setw(buff) << "" << setw(col1) << "Student";
fileout << setiosflags( ios::right );
fileout << setw(col2) << "" << setw(col3) << " Average";
fileout << endl;
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << " Name ";
fileout << setiosflags( ios::right );
fileout << setw(col2) << "Age" << setw(col3) << "Test Grade";
fileout << endl;
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << "-------";
fileout << setiosflags( ios::right);
fileout << setw(col2) << "---" << setw(col3) << "----------";
fileout << endl << endl;
for( int k = 0; k < MAX; k++)
{
fileout << setiosflags( ios::left);
fileout << setw(buff) << "" << setw(col1) << studx[k].name_is();
fileout << setiosflags( ios::right);
fileout << setw(col2) << studx[k].age_is() << setw(col3) << studx[k].average_grade();
fileout << endl;
}
} // End of function main()
PS THANKS FOR READING THIS FAR!! THANKS A MILLION!