#include <iostream>
#include <cctype>
#include <fstream>
#include <cstring>
#include "ass1.h"
using namespace std;
const int MAXSIZE = 100;
int records = 0;
char Menu();
void ReadFile();
void DisplayRecs();
void AddRecord();
void SearchArray();
struct StudentRec
{
string Number;
string GName;
string FName;
string subjects[4];
int results[4];
int numsubs;
};
StudentRec StudentArray[MAXSIZE];
int main()
{
bool quit = false;
do
{
switch(Menu())
{
case 'r':
ReadFile();
break;
case 'd':
DisplayRecs();
break;
case 'a':
AddRecord();
break;
case 's':
SearchArray();
break;
case 'q':
quit = true;
break;
default:
cerr << "Invalid command!\n";
}
} while(!quit);
cout << "Thank you for using the student records database" << endl;
return 0;
}
char Menu()
{
char cmd;
cout << "*********************************"<< endl;
cout << "* Student Records Database *"<< endl;
cout << "* (r)ead data file *"<< endl;
cout << "* (d)isplay records *"<< endl;
cout << "* (a)dd record to DB *"<< endl;
cout << "* (s)earch records *"<< endl;
cout << "* (q)uit *"<< endl;
cout << "*********************************"<< endl;
cout << "Command: ";
cin >> cmd;
cin.ignore(100,'\n');
return tolower(cmd);
}
void ReadFile()
{
int i = 0, j;
{
ifstream fin;
fin.open("students.txt");
if (fin.fail())
{
cerr << "Not sucessful in opening file" << endl;
}
cout << "Sucessfull in opening file" << endl;
fin >> StudentArray[i].Number;
while (!fin.eof() && fin.good())
{
fin >> StudentArray[i].GName;
fin >> StudentArray[i].FName;
j = 0;
fin >> StudentArray[i].subjects[j];
int len = StudentArray[i].subjects[j].length();
fin >> StudentArray[i].results[j];
while (j < 3)
{
j++;
fin >> StudentArray[i].subjects[j];
len = StudentArray[i].subjects[j].length();
fin >> StudentArray[i].results[j];
}
i++;
fin >> StudentArray[i].Number;
}
records = i;
fin.close();
cout << "There are " << records << " records in the student records database." << "\n" << endl;
}
}
void DisplayRecs()
{
char ans;
int i,j;
for (i=0; i < records; i++)
{
cout << "Student No: " << StudentArray[i].Number << endl;
cout << "Given Name: " << StudentArray[i].GName << endl;
cout << "Family Name: " << StudentArray[i].FName << endl;
cout << "Subjects: ";
for (j=0; j < 4; j++)
{
cout << StudentArray[i].subjects[j] << " ";
}
cout << "\n";
cout << "Results ";
for (j=0; j < 4; j++)
{
if (StudentArray[i].results[j] <= 44 && StudentArray[i].results[j] >= 0)
{
cout << " F " << StudentArray[i].results[j] << " ";
}
else if (StudentArray[i].results[j] <= 49 && StudentArray[i].results[j] >= 45)
{
cout << "PC " << StudentArray[i].results[j] << " ";
}
else if (StudentArray[i].results[j] <= 64 && StudentArray[i].results[j] >= 50)
{
cout << " P " << StudentArray[i].results[j] << " ";
}
else if (StudentArray[i].results[j] <= 74 && StudentArray[i].results[j] >= 65)
{
cout << " C " << StudentArray[i].results[j] << " ";
}
else if (StudentArray[i].results[j] <= 84 && StudentArray[i].results[j] >= 75)
{
cout << " D " << StudentArray[i].results[j] << " ";
}
else if (StudentArray[i].results[j] <= 100 && StudentArray[i].results[j] >= 85)
{
cout << "HD " << StudentArray[i].results[j] << " ";
}
else
{
cout << "Error Result " << StudentArray[i].results[j] << " ";
}
}
cout << "\n";
cout << "Display next record (y/n): ";
do
{
cin >> ans;
}while(ans !='y');
}
}
void AddRecord()
{
}
void SearchArray()
{
}
danny.chungie
0
Newbie Poster
Recommended Answers
Jump to PostWow! You're so close! Just fill in the last two functions and you're done. Then you'll see that you don't even need our help.
You also need to attach the ass1.h file to your post and give proper code tags...
Jump to Posttheres not even any "hello, could you help me with this etc etc" just a command in the title and a buch of code!
All 6 Replies
xavier666
56
Junior Poster
hanvyj
7
Posting Whiz in Training
danny.chungie
0
Newbie Poster
danny.chungie
0
Newbie Poster
Prof.Castle
0
Newbie Poster
ithelp
757
Posting Virtuoso
Banned
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.