![]() |
![]() |
![]() |
|
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 |
![]() |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Feb 15, '08 From Royal Oak, MI Currently Offline Reputation: 7 (100%) ![]() |
its been a while... i only remember printf and scanf and arrays...
-------------------- God made man....
Everything else... Made in China ![]() |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() Joined Jan 10, '09 From Burtonsville, Maryland Currently Offline Reputation: 1 (100%) ![]() |
its been a while... i only remember printf and scanf and arrays... I believe thats Java statements -------------------- THIS IS WHERE WE HOLD THEM!
Still trying to find the cure for ST205 asthma.. 6gc.net's outlaw vigilante because im a LEADER not a follower. ![]() |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Feb 15, '08 From Royal Oak, MI Currently Offline Reputation: 7 (100%) ![]() |
its been a while... i only remember printf and scanf and arrays... I believe thats Java statements my mistake its just plain turbo C -------------------- God made man....
Everything else... Made in China ![]() |
![]() ![]() |
Lo-Fi Version | Time is now: July 12th, 2025 - 2:33 PM |