C++ help needed

Started by
3 comments, last by Anurag Banerjee 18 years, 9 months ago
Im preety new to the whole programming thing and need help with a text based menu system. The trouble is that i need the menu to let the user see 10 names and choose weather to cycle through the next ten or just choose one from the list that is displayed on the screen. The array is a size of 300 student names and i need a loop that will be able to do the above problem.
Advertisement
How are the names stored? std::string, char *, char, ...?
If they(the names) are stored in a .txt file, you can read it one and one with

FILENAME.getline(anarray,300);


And one last thing:

You shouldn't be using arrays(they are EVIL, i think) use std::string instead.

Good luck!
Hope I was helpful. And thank you if you were!
hi tommy,
doing this is pretty simple using the MFC or VC++ , where in a form you can have a text box and display all the name in that , you can adjust the size of the box to show only 10 names and than with the help of a slider you can scroll through the rest of the names at will, this will look good and is pretty simple also.

But if you wanna do it via a normal C++ code than you have to manage all those things which the MFC was going to manage, anyways i am giving you the algo of the loop you want assuming that you know about selecting an object , you will write a diffrent function of select which will return true if selected and false if not.

char* students[300];

int start = 0;
int end = 10;

void NamesFunction()
{

for(int i=start;i<end;i++)
{
cout<<students<<endl;
}
if ( select() == true)
{
exit(0);
}
else
{
if(PressedButton == A)
{
start = start - 10; end = end -10;
}
if(PressedButton == B)
{
start = end ;
end = end + 10;
}
}

}

Here i havent gone into the details of how to select or check for some exception cases like if we are showing the first 10 names , than the previous button cannot be pressed, and the PressedButton variable should be set by you through any process input loop , which will run through the Code always.

Hope it helps.... :-)
And samsonite is correct about that arrays are evil but when you know the class is of 300 students only and not more than its always wise to use arrays as they save time and are quicker provided you have that much sucessive memory available, but i think 300 names string shouldt be a problem , but use std::string if possible , as they are always better and make sure you dont use my code directly as it would some errors regarding input and other stuff, which needs to be filled by you

This topic is closed to new replies.

Advertisement