Computer Science, asked by puklitdhamija9578, 10 months ago

Write a program to perform various list operations after displaying menu.

Answers

Answered by abhilashbhoi16
2

class check():

def __init__(self):

self.n=[]

def add(self,a):

return self.n.append(a)

def remove(self,b):

self.n.remove(b)

def dis(self):

return (self.n)

obj=check()

choice=1

while choice!=0:

print("0. Exit")

print("1. Add")

print("2. Delete")

print("3. Display")

choice=int(input("Enter choice: "))

if choice==1:

n=int(input("Enter number to append: "))

obj.add(n)

print("List: ",obj.dis())

elif choice==2:

n=int(input("Enter number to remove: "))

obj.remove(n)

print("List: ",obj.dis())

elif choice==3:

print("List: ",obj.dis())

elif choice==0:

print("Exiting!")

else:

print("Invalid choice!!")

print()

Answered by dikshaverma4you
2

PROGRAM

This is a user-defined C++ program to carry out the operations. The program displays a menu, asking the user to enter the values and the type of operation he/she wants to perform on those values.

Program is as follows :-

#include<iostream.h>

#include<conio.h>

#include<process.h>

void main()

{

clrscr();

int x,y,a=0,s=0,d=0,m=0;

char ch;

A:

cout<<"Welcome to my calculation world \n";

cout<<"Enter any two integer values. \n";

cin>>x>>y;

cout<<"Now :- \n";

cout<<" 1. Press 'a' for addition. \n";

cout<<" 2. Press 's' for subtraction. \n";

cout<<" 3. Press 'd' for division. \n";

cout<<" 4. Press 'm' for multiplication. \n";

cin>>ch;

if(ch=='a')

{

  a = x+y;

  cout<<"The sum is "<<a<<endl;

}

else if(ch=='s')

{

  s = x-y;

  cout<<"The difference is "<<s<<endl;

}

else if(ch=='d')

{

 d = x/y;

 cout<<"The quotient is "<<d<<endl;

}

else if(ch=='m')

{

 m = x*y;

 cout<<"The product is "<<m<<endl;

}

cout<<"Want to calculate again ? \n";

cin>>ch;

if(ch=='y')

{

goto A;

}

else if(ch=='n')

{

exit(0);

}

getch();

}

Similar questions