Sign in to follow this  
tommy_07

C++ help needed

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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[i]<<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.... :-)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this