Você está na página 1de 45

INDEX

SR.N O.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

ASSIGNMENT
Assignment No. 1 Assignment No. 2 Assignment No. 3 Assignment No. 4 Assignment No. 5 Assignment No. 6 Assignment No. 7 Assignment No. 8 Assignment No. 9 Assignment No. 10 Assignment No. 11 Assignment No. 12 Assignment No. 13 Assignment No. 14 Assignment No. 15 Assignment No. 16 Assignment No. 17 Assignment No. 18 Assignment No. 19

DATE
04-112011 04-112011 04-112011 04-112011 04-112011 04-112011 04-112011 05-112011 05-112011 05-112011 25-122011 25-122011 25-122011 26-122011 26-122011 26-122011 27-122011 27-122011 27-122011

SIGNATURE

20 21 22 23 24 25 26 27

Assignment No. 20 Assignment No. 21 Assignment No. 22 Assignment No. 23 Assignment No. 24 Assignment No. 25 Assignment No. 26 Assignment No. 27

28-122011 28-122011 28-122011 29-122011 29-122011 29-122011 03-012012 04-012012

ASSIGNMENT -1
Q. Rewrite the following program after removing syntactical errors (if any):
#include<iostream.h> const int MAX 10; void main() { cout<<endl; int Numbers[MAX]; Numbers={20,50,10,30,40}; For(Loc=MAX-1; Loc>=0; Loc--) Cout>>Numbers[Loc]; } Answer . Correct code is: #include<iostream.h> const int MAX=10; void main() { int Numbers[MAX]; Numbers={20,50,10,30,40}; for(int Loc=MAX-1; Loc>=0; Loc--) cout<<Numbers[Loc]; }

Q. What will be the output of following compiled program code? #include<iostream.h> #include<ctype.h> void main() { char Text[]="Mind@Work"; for(int l=0; Text[l]!='\0'; l++) { if(!isalpha(Text[l])) Text[l]='*'; else if(isupper(Text[l])) Text[l]=Text[l]+1; else Text[l]=Text[l+1]; } cout<<Text; } ANS. Output will be: Nnd@*Xrk

ASSIGNMENT-2

ASSIGNMENT-3
Q. Find the output of following program: #include<iostream.h> void Withdef(int HisNum=30) { for(int l=20; l<=HisNum; l+=5) cout<<l<<","; cout<<endl; } void Control(int &MyNum) { MyNum+=10; Withdef(MyNum); } void main() { int YourNum=20; Control(YourNum); Withdef(); cout<<"Number= "<<YourNum<<endl; }

ANS. Output will be:


20,25,30,

22,25,35, Number= 20

ASSIGNMENT-4
Q. What will be the expected output of the following program? #include<iostream.h> #include<stdlib.h> void main() { randomize(); int Marks[]={99,92,94,96,93,95}, MyMarks; MyMarks=Marks[1+random(2)]; cout<<MyMarks<<endl; } ANS. Output will be: 92 or 94

ASSIGNMENT-5
Q. What will be the output of the following program? #include<iostream.h> #include<stdlib.h> const int LOW=25; void main() { randomize(); int Point=5, Number; for(int l=1; l<=4; l++) { Number=LOW+random(Point); cout<<Number<<":"; Point--; } } ANS. The possible outputs could be: 25:28:27:26:

28:28:26:25: 29:25:27:26: 26:26:26:26: etc ..

ASSIGNMENT-6
Q. What will be the output of the following program? #include<iostream.h> #include<string.h> class Retail { char Category[20]; char Item[20]; int Qty; float Price; public:Retail() //Function1 { strcpy(Category,"Cereal"); strcpy(Item,"Rice"); Qty=100; Price=25;

} void Show() { cout<<Category<<"-"<<Item<<":"<<Qty<<"@" <<Price<<endl; } }; void main() { Retail R; //Statement1 R.Show(); //Statement2 } ANS. Output will be: Cereal-Rice:100@25

ASSIGNMENT-7
Q. Define a class CRICKET with following description: Private members: Target_score (integer) Overs_bowled (integer) Extra_time (integer) penalty (integer) A member function calc_penalty( ) to calculate penalty as follows: If Extra_time <= 10, penalty = 1 If Extra_time > 10, but <= 20, penalty =2 Otherwise, penalty = 5 Public members A member function extdata( ) to allow user to enter values for Target_score, Overs_bowled & Extra_time

A member function dspdata( ) to call calc_penalty( ) function and display all the data members. ANS. The required class should be: class CRICKET { int Target score, Overs bowled, Extra time, penalty; void calc penalty() { if(Extra time<=10) penalty=1; if(Extra time>10&&Extra time<=20) penalty=2; else penalty=5; } public:void extdata() { cout<<"Enter Target Score: "; cin>>Target score; cout<<"Enter Overs Bowled: "; cin>>Overs bowled; cout<<"Enter Extra Time: "; cin>>Extra time; } void dspdata() { calc penalty(); cout<<"Target Score: "<<Target score<<endl; cout<<"Overs Bowled: "<<Overs bowled<<endl; cout<<"Extra Time: "<<Extra time<<endl; cout<<"Penalty: "<<penalty; } };

ASSIGNMENT-8
Q. Define a class Tour with the description below: Private Members: TCode(as string), NoofAdults(as integer), NoofKids(as integer), Kilometers(as integer) & Totalfare(as float). Public Members: A constructor to assign initial values as follows: * TCode with the word NULL * NoofAdults, NoofKids, Kilometers & TotalFare as 0 A function AssignFare( ) which calculates and assigns the value of the data members TotalFare as follows: For each Adult Fare(Rs) For Kilometers

500 >= 1000 300 < 1000 & >= 500 200 < 500 For each Kid the above Fare will be 50% of the Fare mentioned in the above table A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids & Kilometers; and invoke the AssignFare( ) function. A function ShowTour( ) which displays the content of all the data members for a Tour. ANS. The required class should be: class Tour { char *TCode[50]; int No of Adults, No of Kids, Kilometers; float Total Fare; public: Tour() { *TCode="NULL"; NoofAdults=NoofKids=Kilometers=TotalFare=0; } void AssignFare() { if(Kilometers>=1000) Total Fare=No of Adults*500+NoofKids*250; else if(Kilometers<1000&&Kilometers>=500) Total Fare=No of Adults*300+NoofKids*150; else if(Kilometers<500) Total Fare=No of Adults*200+NoofKids*100; } void EnterTour() { cout<<"Enter TCode: "; gets(*TCode); cout<<"Enter No. of Adults: "; cin>>NoofAdults;

cout<<"Enter No. of Kids: "; cin>>NoofKids; cout<<"Enter distance in Kilometers: "; cin>>Kilometers; AssignFare(); } void ShowTour() { cout<<"TCode: "<<*TCode<<endl<<"No.of Adults: "<<NoofAdults<<endl<<"No. of Kids: "; cout<<NoofKids<<endl<<"Distance:"<<Kilometers< <endl<< "Total Fare:"<<TotalFare ; } };

ASSIGNMENT-9
Q. Write a declaration for a class Person which has the following: Data members name, phone, set and get function for every data member A display function, a destructor For the Person class above, write each of the constructors, the assignment operator, and the getName member function. Use member

initialization lists as often as possible. In the Person class above, write the declaration for a class Spouse that inherits from Person & does the following: o Has an extra data member spouseName & Redefines the display member function ANS. Required classes should be: class Person { char name[50]; long phone; public: void set Name(char * n) { strcpy(name, n); } char* get Name() { return name; } void set Phone(long p) { phone = p; } long get Phone() { return phone; } void display() { cout<<"Name: "<<name<<endl<<"Phone: "<<getPhone()<<endl; } ~Person() { cout<<"In destruction mode..."; }

}P; class Spouse : public Person { char spouse Name[50]; public: void set Spouse Name(char * spname) { strcpy(spouseName, spname); } char* getSpouse Name() { return spouse Name; } void display() { P.display(); cout<<"SpouseName:"<<getSpouseName(); } }SP;

ASSIGNMENT-10
Q.Define a class employee with the following specifications: Private members of class employee empno integer ename 20 characters

basic, hra, da float netpay float calculate ( ) A function to find basic + hra + da with float return type public member function of class employee havedata ( ) function to accept values for empno, ename, basic, hra, da and invoke calculate ( ) to calculate netpay. dispdata ( ) function to display all the data members on the screen. ANS. Required class should be: class employee { int empno; char ename[20]; float basic, hra, da, netpay; float calculate() { return basic+hra+da; } public: void have data() { cout<<"Enter Employee number: "; cin>>empno; cout<<"Enter Employee name: "; gets(ename); cout<<"Enter Basic: "; cin>>basic; cout<<"Enter H.R.A.: "; cin>>hra; cout<<"Enter D.A.: "; cin>>da; netpay=calculate();

} void disp data() { cout<<"Employee number: "<<empno<<"\nEmployee name: "<<ename; cout<<"\nBasic: "<<basic<<"\nH.R.A.: "<<hra<<"\nD.A.: "; cout<<da <<"\nNet pay: "<<netpay; } };

ASSIGNMENT-11
Q.Write a program for linear search. ANS. Required program should be: #include<iostream.h> Void lsearch(int a[], int l, int s) { int p=-1; for(int i=0; i<l; i++) { if(a[i]==s) p=i; } if(p!=-1) { cout<<Element found at position: <<p+1; } else cout<<Element not in array!!; } void main() { int in[50],n,o; cout<<Enter the length of the array (Max 50): ; cin>>n; cout<<Enter the arrays element: ; for(int i=0; i<n; i++) cin>>in[i]; cout<<\nEnter the element to be searched: ; cin>>o; lsearch(in ,n ,o); }

ASSIGNMENT-12
Q.Write a program for binary search. ANS. Required program should be: #include<iostream.h> void search(int a[], int l, int s) { int b = 0, l = l-1, m, p=-1; while(b<=l) { m = (b+l)/2; if(s == a[m]){p = m; break;} else if(s>a[m]) b = m+1; else l = m-1; } if(p!= -1) cout<<Element found at position <<p+1; else cout<<Element not in index!!; } void main() { int ar[50],n,o; cout<<Enter length of array (Max 50): ; cin>>n; cout<<Enter elements of array in ascending order: ; for(int i=0; i<n; i++) cin>>ar[i]; cout<<Enter element to be searched: ; cin>>o; search(ar,n,o); }

ASSIGNMENT-13
Q. Write a program for bubble sort . ANS. Required program should be: #include<iostream.h> void sort(int a[], int l) { ; for(int i = 0; i<l; i++) for(int j=0; j<((l-1)-i); j++) if(a[j]>a[j+1]) { int t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } } void main() { int ar[50],n; cout<<Enter the length of array (Max 50): ; cin>>n; cout<<Enter array element: \n; for(int i = 0; i<n; i++) cin>>ar[i]; sort(ar,n); cout<<Array after sorting is: \n; for(i = 0; i<n; i++) cout<<ar[i]<< ; }

ASSIGNMENT-14
Q. Write a program for merge sort. ANS. Required program should be: #include<iostream.h> void merge(int A[],int m, int B[],int n, int C[]) { int a,b,c; for(a = 0, b = n-1, c = 0; a<m && b>=0;) { if(A[a]<=B[b]) C[c++] = A[a++]; else C[c++] = B[b--]; } if(a<m) { while(a<m) C[c++] = A[a++]; } else{ while(b>=0) C[c++] = B[b--];} } void main() { int A[50], B[50], C[50], MN=0, M, N; cout<<Enter length of first array: ; cin>>M; cout<<Enter elements of first array: ; for(int i = 0; i<M; i++) cin>>A[i]; cout<<\nEnter length of second array: ; cin>>N; for(i = 0; i<N; i++) cin>>B[i]; MN=M+N; merge(A,M,B,N,C); cout<<\n\nThe merged array is as shown bellow..\n; for(i = 0; i<MN; i++) cout<<C[i];

ASSIGNMENT-15
Q. Write a program to enter two matrices & to print the sum of these two matrices ANS. Required program should be: #include<iostream.h> void main() { int A[50][50], B[50][50], C[50][50],m,n,p,q; cout<<Enter the no. of rows and columns of first matrix: ; cin>>m>>n; cout<<Enter elements of first matrix:\n; for(int i=0; i<m; i++) {for(int j=0; j<n; j++) cin>>A[i][j];} cout<<\n\nEnter the no. of rows and columns of second matric: ; cin>>p>>q; if(m == p && n == q) { cout<<Enter elements of second matric:\n; for(i=0;i<p;i++) {for(int j=0;j<q;j++) cin>>B[i][j];} cout<<\n\nSum of both matrices is:\n; for(i=0;i<m;i++) { for(int j=0;j<n;j++) { C[i][j]=A[i][j]+B[i][j]; cout<<C[i][j]<< ; }cout<<endl; } } else cout<<\n\nBoth matrices should be of same size!!; }

ASSIGNMENT-16
Q.Write a program for insertion sort. ANS. Required program should be: #include<iostream.h> #include<limits.h> void InsSort(int AR[], int n) { int t, j; AR[0] = INT_MIN; for(int i = 1; i<=n; i++) { t = AR[i]; j = i-1; while(t<AR[j]) {AR[j] = AR[j+1]; j--;} AR[j] = t; } } void main() { int AR[50], N; cout<<Enter the length of array: ; cin>>N; cout<<Enter Array elemnts:\n; for(int i = 1;i<=N;i++) cin>>AR[i]; InsSort(AR,N); cout<<\n\nThe Sorted array is:\n; for(i = 1;i<=N;i++) cout<<AR[i]; }

ASSIGNMENT-17
Q.Write a program for selection sort. ANS. Required program should be: #include<iostream.h> void SelSort(int AR[], int n) { int s, p, t; for(int i = 0; i<n; i++) { s = AR[0]; for(int j = i+1; j<n; j++) { if(AR[j]<s) {s = AR[j]; p = j;} } t = AR[i]; AR[i] = AR[p]; AR[p] = t; } } void main() { int AR[50], N; cout<< Enter the length of the array: ; cin>>N; cout<<Enter array elements: ; for(int i = 0; i<N; i++) cin>>AR[i]; SelSort(AR, N); cout<<\n\nSorted array is:\n; for(i = 0; i<N; i++)

cout<<AR[i]<< ; }

ASSIGNMENT-18
Q.Write a program to insert a node at beginning and end of a link list. ANS. Required program should be: #include<iostream.h> #include<process.h> #include<conio.h> struct Node{ int info; Node * next; } *start,*newptr, *save, *ptr, *rear; Node * Create_New_Node(int); void Insert _Beg(Node *); void Insert _End(Node *); void Display(Node *); void main() { int opt; option: clrscr(); cout<<What do you want to do?\n1.\tInsert node at beginning\n2.\tInsert node at end\n; cout<<3.\tExit\nEnter your option: ; cin>>opt; switch(opt) { case 1: start=NULL; int inf; char ch = y; while(ch == y | | ch ==Y)

{ clrscr(); cout<<Enter information for the new node: ; cin>>inf; cout<<Creating new node!!\n\n; newptr = Create_New_Node(inf); if(newptr != NULL) { cout<<New node created successfully!!;} else { cout<<Cannout create new node!! Aborting.!!; getch(); exit(1); } cout<<\n\nNow inserting this node in the beginning of the list!; Insert_Beg(newptr); cout<<\nNow the list is:\n; Display(start); cout<<Press Y to enter more nodes, N to exit\n; cin>>ch; }goto option; case 2: start = rear = NULL; int inf; char ch = y; while(ch == y | | ch == Y) { clrscr(); cout<<Enter information for the new node: ; cin>>inf; cout<<Creating new node!!\n\n; newptr = Create_New_Node(inf); if(newptr != NULL) { cout<<New node created successfully!!;} else { cout<<Cannout create new node!! Aborting.!!; getch(); exit(1); } cout<<\n\nNow inserting this node in the end of the

list!; Insert_End(newptr); cout<<\nNow the list is:\n; Display(start); cout<<Press Y to enter more nodes, N to exit\n; cin>>ch; }goto option; case 3: cout<<Byee!!; getch(); exit(0); default:cout<<Wrong option!!!!; getch(); goto option; } } Node * Create_New_Node(int n) { ptr = new Node; ptr -> info = n; ptr->next=NULL; return ptrl } void Insert_Beg(Node * np) { if(start == NULL) start = np; else { save = start; start = np; np->next=save; } } void Inster_End(Node * np) { if(start == NULL) start = rear = np; else { rear -> next = np; rear = np; } } void Display(Node * np) { while(np != NULL) { cout<<np -> info << -> ;

np=np -> next; } cout<<!!!\n; }

ASSIGNMENT-19
Q.Write a program to delete a node from the beginning of a link list ANS. Required program should be: #include<iostream.h> #include<conio.h> #include<process.h> struct Node { int info; Node * next; } *start, *newptr, *save, *ptr, *rear; Node * Create_New_Node(int); void Insert(Node *); void Display(Node *); void Del Node( ); void main( ) { start = rear = NULL; int inf; char ch = y; while(ch == y | | ch== Y) { clrscr(); cout<<\nEnter information for the new node: ; cin>>inf; newptr = Create_New_Node(inf); if(newptr = NULL)

{ cout<<\nCannot create new node!!; getch(); exit(1);} Insert(newptr) cout<<\nPress Y to enter mode nodes, N to exit; } clrscr(); do { cout<<\nThe list now is:\n; Display(start); getch(); cout<<Want to delete first node? (y/n): ; cin>>ch; if(ch == y | | ch == Y) DelNode(); }while(ch == y | | ch == Y); } Node * Create_New_Node(int n) { ptr = new Node; ptr -> info = n; ptr->next=NULL; return ptr; } void Insert(Node * np) { if(start == NULL) start = rear = np; else {rear -> next = np; Rear=np;} } void DelNode() { if(start == NULL) cout<<UNDERFLOW!!!\n; else {ptr = start;start=start->next; delete ptr;} } void Display(Node * np) { while(np != NULL) { cout<<np -> info <<->; np = np -> next;} cout<<!!!\n;

ASSIGNMENT-20
Q. Write a program for traversal in a link list.
ANS. Required program should be: #include<iostream.h> #include<process.h> struct Node { int info; Node * next; } *start,*newptr, *save, *ptr, *rear; Node * Create New Node(int); void Insert(Node *); void Traversal(Node *); void main() { start = rear = NULL; int inf; char ch = y; while(ch == y || ch == Y) { cout<<\nEnter information of the node: ; cin>>inf; newptr = Create_New_Node(inf); if(newptr == NULL) { cout<<\nCannot create new node!!!; exit(1);} Insert(newptr); cout<<\nPress Y to enter more nodes, N to exit: ;

cin>>ch; } cout<<\nThe list is now:\n; Traversal(start); } Node * Create_New_Node(int n) { ptr = new Node; ptr -> info = n; ptr->next=null; return ptr; } void Insert(Node * np) { if(start = NULL) start = rear = np; else { rear -> next = np; Rear=np;} } void Traversal(Node * np) { while(np != NULL) { cout<<np -> info<< -> ; np = np -> next; } cout<<!!!\n; }

ASSIGNMENT-21
Q. Write a program for insertion in linked queue
ANS. Required program should be: #include<iostream.h> #include<process.h> struct Node { int info; Node * next; } *front, *newptr, *save, *ptr, *rear; Node * Create_New_Node(int); void Insert_End(Node *); void Display(Node *); void main() { front = rear = NULL; int inf; char ch = y; while(ch == y || ch == Y) { cout<<\nEnter information for the new node: ; cin>>inf; newptr = Create_New_Node(inf); if(newptr == NULL) { cout<<\nCannot create new node!!!; exit(1)} Insert_End(newptr);

cout<<\nNow the Queue(FronttoRear) is:\n; Display(front); cout<<\nPress Y to enter more nodes, N to exit: ; cin>>ch; } } Node * Create_New_Node(int n) { ptr = new Node; ptr -> info = n; ptr->next=null; return prt; } void Insert_End(Node * np) { if(front == NULL) front = rear = np; else { rear -> next = np; rear=np;} } void Display(Node * np) { while(np != NULL) { cout<<np -> info<< -> ; np = np -> next; } cout<<!!!\n; }

ASSIGNMENT-22
Q. Write a program for deletion in linked queue. ANS. Required program should be: #include<iostream.h> #include<process.h> #include<conio.h> struct Node { int info; Node * next; } *front,*newptr, *save, *ptr, *rear; Node * Create New Node(int); void Insert(Node *); void Display(Node *); void DelNode_Q(); void main() { front = rear = NULL; int inf; char ch = y; while(ch == y || ch == Y) { cout<<\nEnter information for the new node: ; cin>>inf; newptr = Create_New_Node(inf); if(newptr == NULL)

{ cout<<\nCannot create new node!!!; exit(1)} Insert(newptr); cout<<\nPress Y to enter more nodes, N to exit: ; cin>>ch; } clrscr(); do { cout<<\nThe Linked-Queue now is (Frontto Rear):\n; Display(front); cout<<Want to delete first node? (y/n): ; cin>>ch; if(ch == y || ch == Y) DelNode_Q(); }while(ch == y || ch == Y); } Node * Create_New_Node(int n) { ptr = new Node; ptr -> info = n; ptr-> next=NULL; return prt; } Void Insert(Node * np) { if(front == NULL) front = rear = np; else { rear -> next = np; rear =np;} } Void DelNode_Q() { if(front == NULL) cout<<UNDERFLOW!!!\n; else { ptr = front; front = front -> rear; delete ptr; } } Void Display(Node * np) { while(np != NULL)

{ cout<<np -> info<< -> ; np = np -> next; } cout<<!!!\n;

ASSIGNMENT-23
Q. Write a program for array insertion.
ANS. Required program should be: #include <iostream.h> #include <conio.h> void main() { clrscr(); int range[100], N, num, loc, prev, i; clrscr(); cout << "Enter the length of your array : "; cin >> N; cout << "Enter the array values \n"; for (i = 0; i < N; i++) { cout << "Value " << i + 1 << ". "; cin >> range[i]; } cout << "Enter the inserted value : "; cin >> num; cout << "Enter the location to insert in array : ";

cin >> loc; cout << "\n"; if (loc <= N) { prev = N; while (prev >= loc) { range[prev] = range[prev-1]; prev = prev - 1; } range[prev] = num; N = N + 1; cout << "The resulted output is :\n"; for (i = 0; i < N; i++) cout << range[i] << endl; } else cout << "Your location is not in the array range"; getch(); }

ASSIGNMENT-24
Q. Write a program for array deletion. ANS. Required program should be: #include <iostream.h> #include <conio.h> void main() { clrscr(); int range[100], N, loc, prev, i, num; clrscr(); cout << "Enter the length of your array : "; cin >> N; cout << "Enter the array values \n"; for (i = 0; i < N; i++) { cout << "Value " << i + 1 << ". "; cin >> range[i]; } cout << "Enter the location to delete from the array : ";

cin >> loc; cout << "\n"; loc = loc - 1; if (loc < N) { num = range[loc]; prev = loc; while (prev < N) { range[prev] = range[prev + 1]; prev = prev + 1; } N = N - 1; // Decrease the length of array by 1. cout << "The resulted output is :\n"; for (i = 0; i < N; i++) cout << range[i] << endl; cout << "\nThe deleted value is : " << num; } else cout << "Your location is not in the array range to delete"; getch(); }

ASSIGNMENT-25
Q. Write a program for array traversal. ANS. Required program should be: #include<iostream.h> void main() { int AR[50], N; cout<<Enter length of array (Max 50.): ; cin>>N; cout<<\nEnter array elements:\n; for(int i=0; i<N; i++) cin>>AR[i]; cout<<\nArray with doubled elements is as follows..\n; for(i=0; i<N; i++) { AR[i]*=2; cout<<AR[i]<< ;} cout<<endl;

ASSIGNMENT-26
Q. Consider the following tables Consignor and Consignee. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Table: CONSIGNOR CnorID CnorName CnorAddres City s ND01 R Singhal 24, ABC New Delhi Enclave ND02 Amit Kumar 12, New Delhi Palmvenue MU15 R Kohli 5/A,SouthStre Mumbai et MU50 S Kaur 27-K, Mumbai Westend

Table: CONSIGNEE CneeID CnorID CneeNam CneeAddress e MU05 ND01 Rahul 51Park Avenue Kishore ND08 ND02 P Dhingra 16/JMoore Enclave CO19 MU15 A.P. Ray 2ACentral Avenue MU32 ND02 S Mittal P 245, AB Colony ND48 MU50 B.P. Jain B Block D, A Vihar

CneeCit y Mumbai New Delhi Kolkata Mumbai New Delhi

(i) To display the names of all Consignors form Mumbai. (ii) To display the CneeID, CnorName, CnorAddress, CneeName, CneeAddress for every Consignee. (iii) To display consignee details in ascending order of CneeName. (iv) To display number of consignors from each city. (v) SELECT DISTINCT City FROM Consignee; (vi) SELECT A.CnorName, B.CneeName FROM Consignor A, Consignee B WHERE A.CnorID=B.CnorID AND B.CneeCity=Mumbai; (vii) SELECT CneeName, CneeAddress FROM Consignee WHERE CneeCity NOT IN (Mumbai, Kolkata); (viii) SELECT CneeID, CneeName FROM Consignee WHERE CnorID=MU15 OR CnorID=ND01; ANSWERS.
i)

SELECT Cnor Name FROM Consignor WHERE City = Mumbai;

SELECT CneeID, CnorName,cnoraddress,CneeName, CneeAddress FROM Consignee A, Consignor B WHERE Consignor.CnorID =Consignee.CnorID; iii) SELECT * FROM Consignee ORDER BY CneeName ASC; iv) SELECT CneeCity, Count(Cneecity) FROM Consignee GROUP BY CneeCity v) CneeCit y Mumbai New Delhi Kolkata CnorName CneeName vi) R Singhal Rahul Kishore Amit Kumar S Mittal vii) CneeName CneeAddress
ii)

P Dhingra B.P. Jain CneeID MU05 KO19

16/JMoore Enclave 13,Block D, A Vihar CneeName Rahul Kishore A.P. Roy

viii)

ASSIGNMENT-27
Q. Consider the following tables Consignor and Consignee. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii). Table: Product
P_ID
TP01 FW05

ProductName
Talcum Powder Face Wash

Manufacturer
LAK ABC

Price
40 45

BS01 SH06 W12

Bath Soap Shampoo F Face Wash

ABC XYZ XYZ

55 120 95

Table: Client
C_ID
01 06 12 15 16

ClientName
Cosmetic Shop Total Health Live Life Pretty Woman Dreams

City
Delhi Mumbai Delhi Delhi Bangalore

P_ID
FW05 BS01 SH06 FW12 TP01

(i) To display the details of those Clients whose City is Delhi. (ii) To display the details of Products whose Price is in the range of 50 to 100 (Both values included). (iii) To display the ClientName, City from table Client, and ProductName and Price from table Product, with their corresponding matching P_ID. (iv) To increase the Price of all Products by 10. (v) SELECT DISTINCT City FROM Client; (vi) SELECT Manufacturer, MAX(Price), Min(Price), Count(*) FROM Product GROUP BY Manufacturer; (vii) SELECT ClientName, ProductName FROM Product, Client WHERE Client.P_ID = Product.P_ID; (viii) SELECT ProductName, Price*4 FROM Product; ANSWERS. SELECT * FROM Client WHERE City= Delhi; ii) SELECT * FROM Product WHERE Price BETWEEN 50 to 100; iii) SELECT ClientName, City, ProductName, Price FROM Client, Product WHERE Client P_ID = Product P_ID;
i)

iv)

UPDATE Product SET Price = Price + 10; v) City Delhi Mumbai Banglor e Manufactur MAX(Pric er e) LAK 40 ABC XYZ 55 120 MIN(Price Count ) 40 1 45 95 2 2

vi)

ClientName Cosmetic Shop Total Health Live Life Pretty Woman Dreams vii)

ProductName Face Wash Bath Soap Shampoo Face Wash Talcum Powder

ProductName Talcum Powder Face Wash Bath Soap Shampoo Face Wash viii)

Price 160 180 220 480 380

Você também pode gostar