6G Celicas Forums

Welcome Guest ( Log In | Register )

> Help me with my C++ assignment :(, functions wtf?
post Oct 13, 2009 - 11:59 PM
+Quote Post
Mstoochn

Enthusiast
***
Joined Apr 27, '09
From West Coast Canada
Currently Offline

Reputation: 0 (0%)




#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
//declared values/strings/vectors
int choice;
ifstream inFile;
ofstream outFile;
string strFName, strLName;
string strFileName;
vector<string> vecStudent;
//ask for file name
cout<<"Please enter the data file name (with location): ";
cin >> strFileName;
//open input file
inFile.open(strFileName.c_str());
//error check file name
if (inFile.fail())
{
cout<<"Input file error!"<<endl;
return -1;
}
do{
//main menu
cout<<"----------------------------------------"<<endl;
cout<<"Grade Report Program - Main Menu"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"Enter 1 to display ALL students"<<endl;
cout<<"Enter 2 to add a student name"<<endl;
cout<<"Enter 3 to delete a student name"<<endl;
cout<<"Enter 4 to modify a student name"<<endl;
cout<<"Enter 5 to sort the names by First Name"<<endl;
cout<<"Enter 6 to SAVE and quit the program"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"Enter menu option: ";
cin>>choice;

if(choice == 1 ){
//read the names from input file into vector
while (inFile >> strFName >> strLName)
vecStudent.push_back(strFName+" "+strLName);
inFile.close();
//display the content of the vector
cout<<"Display ALL student names.."<<endl;
for (int i=0; i<vecStudent.size(); i++){
cout <<vecStudent[i]<<endl;
}
cout<<"---- A total of "<<vecStudent.size()<<" names ----"<<endl;
}else if(choice == 2 ){
//add a new name
cout<<endl<<"Enter a new name (First and Last Name): ";
cin>>strFName>>strLName;
vecStudent.push_back(strFName+" "+strLName);
cout<<"---- Name "<<strFName<<" " <<strLName<<" has been added ----"<<endl;
//functions not yet covered IGNORE THEM
}else if(choice == 3 )
cout<<"Function 3 Has Not Yet Been Added"<<endl;
else if(choice == 4 )
cout<<"Function 4 Has Not Yet Been Added"<<endl;
else if(choice == 5 )
cout<<"Function 5 Has Not Yet Been Added"<<endl;
else if(choice == 6 ){
//open output file for writing/saving
outFile.open(strFileName.c_str());
if (outFile.fail())
{
cout<<"Output file error!"<<endl;
return -1;
}
cout<<"Thanks for using the program. Program terminated"<<endl;
//save vector to output file
for (int i=0; i<vecStudent.size(); i++)
outFile <<vecStudent[i]<<endl;
outFile.close();
return 0;
}else
cout<<"Invalid. Choose again"<<endl;
}while(choice != 6);
}

This post has been edited by Mstoochn: Nov 9, 2009 - 10:28 PM

Posts in this topic


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: December 4th, 2024 - 8:10 PM