Wednesday, August 18, 2010

How to change array in c++?

i am supposed to write a program which is able to show someones schedule and able to drop and add some classes and i understand how to make it show the classes but i cant figure out how make a funtion to change the .txt file which shows the schedule in order to add and or drop classes. please help in any way thank you. here is my program so far..





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cctype%26gt;


using namespace std;





void displayMenu();


void showSchedule();





int main()





{





CharRange input ('A', 'D');





char choice;





cout %26lt;%26lt; fixed %26lt;%26lt; showpoint %26lt;%26lt; setprecision (2);





do





{


displayMenu ();





choice = input.getChar();








{





case 'A': cout %26lt;%26lt; ';this is your schedule';;


cout %26lt;%26lt; showShedule () %26lt;%26lt; endl;


break;











case 'B': dropClass() %26lt;%26lt; endl;


break;





case 'C': addClass() %26lt;%26lt; endl;


break;














}





} while (choice ! = 'D');





return 0;








void displayMenu()





{





cout %26lt;%26lt; ';\n menu\n\n';;


cout %26lt;%26lt; ';a) View scheduel\n';;


cout %26lt;%26lt; ';b) Drop class\n';;


cout %26lt;%26lt; ';c) Add class\n';;





cout %26lt;%26lt; ';Enter your choice:';;


}





void showSchedule()


{


string array[20]; // creates array to hold names


short loop=0; //short for loop for input


string line; //this will contain the data read from the file





ifstream myfile (';data.txt';); //opening the file.





if (myfile.is_open()) //if the file is open


{


while (! myfile.eof() ) //while the end of file is NOT reached


{


getline (myfile,line); //get one line from the file


array[loop] = line;


cout %26lt;%26lt; array[loop] %26lt;%26lt; endl; //and output it


loop++;


}











myfile.close(); //closing the file


}


else cout %26lt;%26lt; ';Unable to open file';;//if the file is not open output











}How to change array in c++?
Please check out this code, which is still close to your logic


http://pastebin.com/VDsvyZst


and this version 2 code, which removes some coding overhead


by introducing vector logic and the copy algorithm from the stl


http://pastebin.com/H94PFD66

No comments:

Post a Comment