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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
//
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "andy.h"
//using namespace std;
//-----------------------------function declarations
//string OpenLogFile();
//void GetLogFileName(string&)
//int OpenLogFile(ofstream&);
//-----------------------------variables
//Student MyStudents;
//Student MyGrades;
ofstream OutLogName;
string LogFileName;
string TextToWrite;
//-----------------------------main body
int main()
{
cout << "Welcome to the GradeCaculator Deluxe." << endl;
GetStudentList ();
GetClassHours ();
OpenOutputFile ();
string LogFileName;
GetLogFileName(LogFileName);
OpenLogFile(OutLogName, LogFileName, TextToWrite);
}//end main
//--------GetStudentList
string GetStudentList()
{
string FirstName;
string LastName;
int StudentId;
int NumberOfGrades;
string ClassName;
char Grade;
int Index = 0;
int LineIndex = 0;
ifstream StudentFile;
string File1;
ofstream LogFile;
student MyStudents;
grades MyGrades;
string TextToWrite;
cout <<"Enter the file name for the list of Students, including the extension::" << endl;
TextToWrite = "Students.txt successfully opened";
//WriteTextToLogFile(TextToWrite);
getline(cin, File1);
StudentFile.open(File1.c_str());
if(!StudentFile.is_open())
{
exit(EXIT_FAILURE);
}
// while (getline (inputFile, File1))
//{
//++LineIndex;
//}
//cout << "Number of Lines in text file is: " << LineIndex << endl;
while (StudentFile >> FirstName >> LastName >> StudentId >> NumberOfGrades)
{
MyStudents.FirstName = FirstName;
MyStudents.LastName = LastName;
MyStudents.StudentId = StudentId;
MyStudents.NumberOfGrades = NumberOfGrades;
for (int Index = 0; Index < NumberOfGrades; ++Index)
{
(StudentFile >> ClassName >> Grade);
MyGrades.ClassName = ClassName;
MyGrades.Grade = Grade;
}
}
cout << MyStudents.FirstName << ", " << MyStudents.LastName << ", " << MyStudents.StudentId << ", " << MyStudents.NumberOfGrades << endl;
cout << MyGrades.ClassName << ", " << MyGrades.Grade << endl;
//OpenLogFile(OutLogName, LogFileName, TextToWrite);
return TextToWrite;
}//end GetStudentList
//--------GetClassHours
string GetClassHours()
{
//int Grades MyHours [15];
ifstream HoursFile;
string File2;
//struct grades MyGrades;
cout <<"Enter the file name for the list of Class Hours, including the extension::" << endl;
getline(cin, File2);
HoursFile.open(File2.c_str());
if(!HoursFile.is_open())
{
exit(EXIT_FAILURE);
}
cout << "\nThe file has been successfully opened for reading.\n";
return File2;
}//end GetClassHours
//-------OpenOutputFile
string OpenOutputFile()
{
ifstream OutputFile;
string File3;
cout <<"Enter the file name to write the DATA to, including the extension::" << endl;
getline(cin, File3);
OutputFile.open(File3.c_str());
if(!OutputFile.is_open())
{
exit(EXIT_FAILURE);
}
cout << "\nThe file has been successfully opened for reading.\n";
return File3;
}//end GetClassHours
//-------GetLogFileName
void GetLogFileName (string& LogFileName)
{
cout << "Enter the file name to write the Log File data to, including the extension::" << endl;
cin >> LogFileName;
}//end GetLogFileName
//-------OpenLogFile
int OpenLogFile(ofstream& OutLogName, string& LogFileName, string TextToWrite)
{
OutLogName.open(LogFileName.c_str());
if (!OutLogName)
{
cout << "File FAILED to open....Program Terminated" << endl;
return 1;
}
OutLogName << TextToWrite << endl;
return 0;
}//end OpenLogFile
|