Click here to Download Assignment#3 | Click here to Download Cover Page
ONLINE PREVIEW:
STATEMENT:A PROGRAM TO IMPLEMENT THE OPERATIONS ON A SINGLE DIMENSION SUCH AS INSERTION, DELETION, TRAVERSE, AND SEARCH USING MENU AND EXECUTE ON THE BASIS OF SELECTION FROM THE MENU
SOURCE CODES:
ALGORITHM:
Step1
|
Start
|
Step2
|
Declare constant value 20 for x
|
Step3
|
Declare a global array ma[x]
|
Step4
|
Set Choice=0
|
Step5
|
Call userdefined function showmenu()
|
Step6
|
Call userdefined function choice=askuser()
|
Step7
|
Call userdefined function process(choice)
|
Step8
|
Goto Step4
|
Step9
|
Stop
|
Step1
|
Start of userdefined function showmenu()
|
Step2
|
Display
"ARRAY MOD. MENU" “1. INSERT INTEGER”
“2. DELETE VALUE”
“3. TRAVERSE OUTPUT”
“4. SEARCH VALUE”
|
Step3
|
Stop
|
Step1
|
Start of userdefined function askuser()
|
Step2
|
Set choice=0
|
Step3
|
Ask user to select an option as ‘choice’
|
Step4
|
Is choice<1 choice="" or="">4 ?1>
|
YES
|
Display “INVALID CHOICE”
Call userdefined function choice=askuser();
|
NO
|
Goto Step5
|
Step5
|
Return the value of ‘choice’ to the calling function
|
Step6
|
Stop
|
Step1
|
Start of userdefined function process(int choice)
|
Step2
|
Is choice=1?
|
YES
|
Call userdefined function insertit()
Goto Step6
|
NO
|
Goto Step3
|
Step3
|
Is choice=2?
|
YES
|
Call userdefined function deleteit()
Goto Step6
|
NO
|
Goto Step4
|
Step4
|
Is choice=3?
|
YES
|
Call userdefined function showit(1)
Goto Step6
|
NO
|
Goto Step5
|
Step5
|
Is choice=4?
|
YES
|
Call userdefined function showit(2)
|
NO
|
Goto Step6
|
Step6
|
Stop
|
Step1
|
Start of userdefined function askadd()
|
Step2
|
Ask user to specify desired memory address as ‘ask’
|
Step3
|
Is ask<1 ask="" or="">x?1>
|
YES
|
Display “INVALID REQUEST! VALUE OUT OF RANGE”
Goto Step2
|
NO
|
Goto step4
|
Step4
|
Return the value of ‘ask’ to the calling function
|
Step5
|
Stop
|
Step1
|
Start of userdefined function insertit()
|
Step2
|
Set ask=0 and num=0
|
Step3
|
Call userdefined function ask=askadd()
|
Step4
|
Ask user the value ‘num’ for address ‘ask’
|
Step5
|
Store the value of ‘num’ in array ma[ask-1]
|
Step6
|
Stop
|
Step1
|
Start of userdefined function deleteit()
|
Step2
|
Set ask=0
|
Step3
|
Call userdefined function ask=askadd()
|
Step4
|
Set the value of array ma[ask-1]=0
|
Step5
|
Display Value in address ‘ask’ has been deleted successfully
|
Step6
|
Stop
|
Step1
|
Start of the userdefined function showit(int opt)
|
Step2
|
Set i=0, sval=0, found=0
|
Step3
|
Is opt=2?
|
YES
|
Ask user for number to search as ‘sval’
|
NO
|
Goto Step4
|
Step4
|
Is i
|
YES
|
Goto Step5
|
NO
|
Goto Step9
|
Step5
|
Is opt=1 & ma[i]!=0
|
YES
|
Display “Requested value in address ‘i+1’ is ‘ma[i]’ ”
Increase the value of ‘found’ by 1
Goto Step7
|
NO
|
Goto Step6
|
Step6
|
Is opt=2 & ma[i]=sval?
|
YES
|
Display “Requested value found in address ‘i+1’ “
Increase the value of ‘found’ by 1
Goto Step7
|
NO
|
Goto Step7
|
Step7
|
Increase the value of i by 1
|
Step8
|
Goto Step4
|
Step9
|
Is found=0?
|
YES
|
Display “REQUIRED DATA COULD NOT BE FOUND IN THE ARRAY”
|
NO
|
Goto step10
|
Step10
|
Stop
|
SOURCE CODES:
#include <stdio.h>
|
#include <conio.h>
|
#include <process.h>
|
#define x 20
|
int ma[x];
|
void main()
|
{
|
void showmenu();
|
int askuser();
|
void process(int choice);
|
int choice=0;
|
reset:
|
showmenu();
|
choice=askuser();
|
printf("YOUR CHOICE IS=%d",choice);
|
process(choice);
|
goto reset;
|
}
|
void showmenu()
|
{
|
printf("\n\nARRAY MOD. MENU"
|
"\n1. INSERT INTEGER"
|
"\n2. DELETE VALUE"
|
"\n3. TRAVERSE OUTPUT"
|
"\n4. SEARCH VALUE");
|
}
|
int askuser()
|
{
|
int choice=0;
|
printf("\n\nPLEASE SELECT AN OPTION (1-4):");
|
scanf("%d",&choice);
|
if (choice<1 || choice>4)
|
{
|
printf("INVALID REQUEST!");
|
choice=askuser();
|
}
|
return choice;
|
}
|
void process(int choice)
|
{
|
void insertit();
|
void deleteit();
|
void showit(int opt);
|
switch (choice)
|
{
|
case 1:
|
insertit();
|
break;
|
case 2:
|
deleteit();
|
break;
|
case 3:
|
showit(1);
|
break;
|
case 4:
|
showit(2);
|
break;
|
}
|
}
|
int askadd()
|
{
|
int ask;
|
printf("\n\nA total of %d values can be manipulated"
|
"\nIn which address do you want to manipulate value?",x);
|
askagain:
|
printf("\n\nPLEASE SPECIFY YOUR DESIRED ADDRESS(1 to %d)",x);
|
scanf("%d",&ask);
|
if (ask<1 || ask>x)
|
{
|
printf("INVALID REQUEST! VALUE OF OF RANGE!!");
|
goto askagain;
|
}
|
return ask;
|
}
|
void insertit()
|
{
|
int askadd(void);
|
int ask=0,num=0;
|
ask=askadd();
|
printf("\nPLEASE INPUT VALUE FOR ADDRESS=%d",ask);
|
printf("\nYOUR VALUE(ANY INTEGER):");
|
scanf("%d",&num);
|
ma[ask-1]=num;
|
}
|
void deleteit()
|
{
|
int askadd(void);
|
int ask=0,num=0;
|
ask=askadd();
|
ma[ask-1]=0;
|
printf("\n\nVALUE IN ADDRESS %d has been successfully deleted!",ask);
|
}
|
void showit(int opt)
|
{
|
int i=0,sval=0,found=0;
|
if(opt==2)
|
{
|
printf("\n\nPLEASE ENTER NUMBER TO SEARCH:");
|
scanf("%d",&sval);
|
}
|
for(i=0;i<x;i++)
|
{
|
if(opt==1 && ma[i]!=0)
|
{
|
printf("\n\nREQUESTED VALUE IN ADDRESS:%d is %d",i+1,ma[i]);
|
found=found+1;
|
}
|
else if(opt==2 && ma[i]==sval)
|
{
|
printf("\nREQUIRED VALUE FOUND IN ADDRESS:%d",i+1);
|
found=found+1;
|
}
|
}
|
if (found==0)
|
printf("\nREQURED DATA COULD NOT BE FOUND IN THE ARRAY");
|
}
|
RESULT:
The result of this program is a menu display which asks the user for input option and performs required actions based on the results of those actions. The program performs 4 distinct actions namely, insert, delete, traverse and search; all of which manipulate the data in a single dimensional array using various functions.
CONCLUSION:
CONCLUSION:
An array can be used to simply store numerous data of the same data type and such data are very easy to manipulate for recording information of any kind.
Blogger Comments:
Emoticon Emoticon