Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Third Quiz




Test 1
Name: FunkeyTime: 1 - 2 hrs
Create a menu which contains - Item1, Item2, Item3, Exit. It should have an arrow pointing at the selected Item and should look something like this
Item 1 <
Item 2
Item 3
Exit
For each item, when a certain key is pressed, it should call the respective function. To give you a start the statement - gotoxy(x,y); goes to the x,y position on the screen. eg: gotoxy(79,24); goes to the bottom right of the screen. This should make it easier I hope.





Answers
Drag the cursor over the white space to highlight the answer.
Test 1Funkey Program , Source code


#include <conio.h>
#include <iostream.h>

void My_item1();
void My_item2();
void My_item3();

void main()
{
	int Item=1;		
	char Key;
	bool quit=false,Menu=false;
	gotoxy(30,1);cout << "Press W & S to move, e to select.";gotoxy(1,1);
	cout << "Item1<\n"
	     << "Item2\n"
	     << "Item3\n"
	     << "Exit ";
	gotoxy(7,1);
	Key = getch();
	while(quit==false)
	{
		if(Menu==true)
		{
			clrscr();
			Item=1;
			cout << "Item1<\n"
	     		     << "Item2\n"
	    		     << "Item3\n"
	     		     << "Exit ";
			gotoxy(6,1);
			Menu=false;
		}
		if(((Key=='e')||(Key=='E'))&&(Item==1))
		{
			My_item1();
			Menu=true;
		}
		else if(((Key=='e')||(Key=='E'))&&(Item==2))
		{
			My_item2();
			Menu=true;
		}
		else if(((Key=='e')||(Key=='E'))&&(Item==3))
		{
			My_item3();
			Menu=true;
		}
		else if(((Key=='e')||(Key=='E'))&&(Item==4))
		{
			quit=true;
		}
		else if(((Key=='s')||(Key=='S'))&&(Item<=3))	//Go down
		{

			gotoxy(6,Item);
			cout << " ";				//Clear selection
			Item++;
			gotoxy(6,Item);
			cout << "<";			//Put new selection
		}
		else if(((Key=='w')||(Key=='W'))&&(Item>=2))	//Go up
		{
			gotoxy(6,Item);
			cout << " ";
			Item--;
			gotoxy(6,Item);
			cout << "<";
		}
		else if(((Key=='w')||(Key=='W'))&&(Item<=1))	//Skip from top to bottom
		{
			gotoxy(6,Item);
			cout << " ";
			Item=4;
			gotoxy(6,Item);
			cout << "<";
		}
		else if(((Key=='s')||(Key=='S'))&&(Item>=4))	//Skip from bottom to top
		{
			gotoxy(6,Item);
			cout << " ";
			Item=1;
			gotoxy(6,Item);
			cout << "<";	
		}
		if(quit==false)
		{
			Key = getch();
		}
	}
}

void My_item1()
{
	clrscr();
	cout << "Item 1 has been selected.";
}
void My_item2()
{
	clrscr();
	cout << "Item 2 has been selected.";
}
void My_item3()
{
	clrscr();
	cout << "Item 3 has been selected.";
}



Back Home Next