Detecting
a keypress in C++ code
#include
#include
using
namespace std;
void reverse_array(int array[],int size)
{
int temp;
size--;
int loop_count=0;
for(int i=0;size>=i;size--,i++)
{
loop_count++;
temp=array[i];
array[i]=array[size];
array[size]=temp;
}
cout<<"Number of iterations: "<
}
int
main()
{
int array[5],i;
cout<<"\nEnter 5 integer values in array\n"<
for(i=0;i<5 i="" span="">5>
{
cout<<"Enter value for index number array [
"< ";
cin>>array[i];
}
reverse_array(array,5);
cout << "\n\n\t\t\tReversed Array Values" << endl;
for(i=0;i<=4;i++)
{
cout<<"\t\t\tarray
["<
}
return 0;
}
Cpp tutorial to reverse an
array elements
#include
#include
using namespace std;
int main()
{
char key_press;
int ascii_value;
cout<<"\n\t\t\tPress any
key to check its asci value\n\n\t\t\tPress esc to exit\n\n\n";
while(1)
{
key_press=getch();
ascii_value=key_press;
if(ascii_value==27)
break;
cout<<"\t\t\tKey pressed->
\" "<
}
return 0;
}
Cpp tutorial to insert, update and delete interger value
in array
#include
#include
#include
using
namespace std;
int
array[10];
void
displayarray()
{
for
(int i=0;i<10 i="" span="">10>
cout<< "Array [ "<
}
void
setdefaultvalues()
{
cout<<"Defalult Values :"<
for(int
i=0;i<10 i="" span="">10>
{
array[i]=-1;
cout<<"array ["<
}
}
void
insertvalues()
{
cout<<"Enter 10 Values "<
for(int
i=0;i<10 i="" span="">10>
{
cin>>array[i];
}
cout<<"\n\t\t\tArray Values Inserted... Successfully
"<
}
void
deletevalues()
{
cout<<"Enter the Index Number To Delete Value :";
int index;
cin>>index;
if(index>9||index<0 span="">0>
{
cout<<"Invalid Index Entered-> Valid
Range(0-9)"<
deletevalues();
}
else
{
array[index]=-1;
}
cout<<"\n\t\t\tArray Value Deleted... Successfully
"<
}
void
updatevalues()
{
cout<<"Enter Index Number to Update Value :";
int index;
cin>>index;
if(index>9||index<0 span="">0>
{
cout<<"Invalid Index Entered-> Valid
Range(0-9)"<
updatevalues();
}
else
{
cout<<"Enter
the New Value For Index array[ "<
cin>>array[index];
cout<<"\n\t\t\tArray Updated... Successfully
"<
}
}
int
main()
{
char option;
setdefaultvalues();
do
{
cout<<"\t\t\tEnter 1 to Enter Values\n\t\t\tEnter 2 to Update
Values\n\t\t\tEnter 3 to Delete Values\n\n\t\t\t or Enter E to Exit\n\n\t\t\t
Enter Option: -> ";
cin>>option;
if(option=='1')
{
cout<<"Insert Function Called"<
insertvalues();
cout<<"Inserted Values :"<
displayarray();
}
else if(option=='2')
{
updatevalues();
cout<<"Updated Array :"<
displayarray();
}
else if(option=='3')
{
deletevalues();
cout<<"Array After Deleting Values :"<
displayarray();
}
else if(option!='e'&&option!='E')
{
cout<<"\n\n\t\t\tSelect a valid option from below\n\n";
}
}
while(option!='e'&&option!='E');
system("cls");
cout<<"\n\n\n\n\n\n\n\n\n\n\t\tProgram ended press any key to exit Screen.....\n\n\n\n\n\n\n\n\n\n\n\n"<
return 0;
}
No comments:
Post a Comment