(b) Rewrite the following program after removing the syntactical errors (if any). Underline each correction. 2

Similar documents
CBSE Sample Paper for Computer Science Class XII.

Sample Paper 2012 Class XII Subject COMPUTER SCIENCE (Theory)

KENDRIYA VIDYALAYA IIT CAMPUS CHENNAI 36 COMPUTER SCIENCE. Half Yearly

CBSE GUESS PAPER. Roll No. Computer Sc. XII(083)/

KUWAIT SAHODAYA EXAMINATION FIRST TERM SUBJECT : COMPUTER SCIENCE (083) : CLASS - XII SET - 3 Time : 3 Hours


void main() { int global=7 ; func( ::global,global) ; cout<<global<<, <<::global<< \n ; func(global,::global) ; cout<<global<<, <<::global<< \n ; }

ASSIGNMENT CLASS : XII ( ) COMPUTER SCIENCE

ITL Public School First Term( )

KENDRIYA VIDYALAYA SANGATHAN TINSUKIA REGION PRE BOARD EXAMINATION SUBJECT COMPUTER SCIENCE

KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST COMMON PRE BOARD EXAMINATION

CLASS XII COMPUTER SCIENCE(083) TimeAllowed : 3 HrsMax Marks : 70

KE DRIYA VIDYALAYA SA GATHA,CHE AI REGIO. COMMO PRE-BOARD EXAMI ATIO COMPUTER SCIE CE CLASS- XII Time allowed : 3 hours Maximum Marks : 70

COMPUTER SCIENCE Sample Paper I

PRINCE PUBLIC SCHOOL PRE-BOARD EXAMINATION ( ) SAMPLE PAPER-1 COMPUTER SCIENCE XII TIME ALLOWED: 3 HOURS

(a) Differentiate between a call by value and call by reference method.

JB Academy, Faizabad Half Yearly Examination Subject: Computer Science (083) Class XII

After going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file

void Add() { cin >> trainnumber; gets(trainname); } void display() { cout<<trainnumber <<":"<<TrainName<<end;

Computer Science (Code 083) Sample Paper with Solution Set II

Computer Science (Code 083) Sample Paper with Solution Set II

CLASS XII SECOND TERM EXAMINATION SUBJECT : COMPUTER SCIENCE SET A2 (SOLUTIONS)

COMPUTER SCIENCE(083) SAMPLE QUESTION PAPER CLASS XII

KENDRIYA VIDYALAYA PANGODE MONTHLY TEST I JUNE 2015 CLASS XII COMPUTER SCIENCE Time allowed: 1 1/2 Hours Max. Marks: 50

KENDRIYA VIDYALAYA SANGATHAN (KOLKATA REGION) Second Pre Board Examination ( ) COMPUTER SCIENCE (Theory) Class-XII Marking Scheme

Kendriya Vidyalaya Sangathan MODEL QUESTION PAPER - 2 Class-XII Subject: Computer Science (083) Time 3 hrs MM 70

KENDRIYA VIDYALAYA SANGATHAN, COMPUTER SCIENCE (THEORY) I PRE-BOARD TIME 3 HRS CLASS XII M. Marks 70

DELHI PUBLIC SCHOOL BOKARO STEEL CITY

Chapte t r r 9

CLASS XII SECOND TERM EXAMINATION SUBJECT : COMPUTER SCIENCE SET A1(SOLUTIONS)

SECTION A [Only for candidates, who opted for C++]

Write the names of the header files to which the following belong :

CLASS XII GUESS PAPER COMPUTER SCENCE (083)

Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on

Unit-V File operations

SAMPLE PAPER. Class: XII SUBJECT COMPUTER SCIENCE. Time: 3 Hours MM: 70

DELHI PUBLIC SCHOOL BOKARO STEEL CITY ASSIGNMENT FOR THE SESSION

(d) Rewrite the following program after removing all the syntax error(s), if any. [2] include <iostream.h> void main ( )

void display(){ cout << trainno.<< :>>Description<<endl; }; void main() {TRAIN T; Entry.(); Display.(); d) 410 e) i) south:east:south f) temttoe

KENDRIYA VIDYALAYA SANGATHAN BHUBANESWAR REGION SECOND PREBOARD EXAMINATION FOR CLASS XII SUBJECT: COMPUTER SCIENCE

ios ifstream fstream

Sample Paper COMPUTER SCIENCE (Theory) Class-XII Time Allowed: 3hours Maximum Marks: 70

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

COMPUTER SCIENCE

List of Practical for Class XII Computer Science


Object Oriented Programming Using C++ UNIT-3 I/O Streams

COMMON PRE-BOARD EXAMINATION COMPUTER SCIENCE

Sample Paper 2013 SUB: COMPUTER SCIENCE GRADE XII TIME: 3 Hrs Marks: 70

Guru Harkrishan Public School, Karol Bagh Pre Mock Class XII Sub: COMPUTER SCIENCE Allowed :3 hrs

Mock Test Paper-3. Computer Science. Duration : 3hrs Max Marks : 70

Mock Test Paper-2. CBSE XII : Computer Science. Duration : 3hrs Max Marks : 70

HOLIDAYS HOMEWORK CLASS : XII. Subject : Computer Science

Assignment 3 Class XII (Computer Science 083) Topic Array

KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST COMMON PRE BOARD EXAMINATION CLASS:XII - (COMPUTER SCIENCE )

KendriyaVidyalayaSangathan Kolkata Region

Computer Science 2006 (Outside Delhi)


DATA FILE HANDLING FILES. characters (ASCII Code) sequence of bytes, i.e. 0 s & 1 s

I Mid Semester May 2012 : Class XII : Computer Science Max Mark 50 : Time 2 Hrs. 1. a) What is macro in C++? Give example 2

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION COMPUTER SCIENCE (083)

COMMON PRE-BOARD EXAMINATION COMPUTER SCIENCE

SPLIT-UP SYLLABUS ----CHENNAI REGION COMPUTER SCIENCE (Code: 083) Class-XII Academic Session

KENDRIYA VIDYALAYA NO.02 AFS HINDAN G.BAD Holiday Homework Class XII Computer Science

MOCK PRE-BOARD EXAMINATION 2017_18 Class : XII Computer Science ( Answer Key)

CLASS-XI COMPUTER SCIENCE

ITL Public School Pre-Board( ) Computer Science (083) Time:3 hrs M. M: 70

C++ Binary File I/O. C++ file input and output are typically achieved by using an object of one of the following classes:

BHARATIYA VIDYA BHAVAN S V.M.PUBLIC SCHOOL, VADODARA. Class : XII SAMPLE PAPER Max Marks : 70

COMPUTER SCIENCE 1998 (Delhi Board)

BRAIN INTERNATIONAL SCHOOL. Computer Science Assignment CLASS XII OCTOBER 2018 Chapter-7. Data File Handling in C++ Text Files

Sample Paper Class XII SUBJECT : COMPUTER SCIENCE

Question Bank Class XII Subject : Computer Science

COMPUTER SCIENCE (Theory) - Class XII Marking Scheme

Model Sample Paper 2015

Sample Paper, Subject: Computer Science Class 12 th Time Allowed : 3 Hr. M.M.: 70

KENDRIYA VIDYALAYA SANGATHAN (CHANDIGARH REGION) MARKING SCHEME (Ist Pre Board )

KENDRIYA VIDYALAYA SANGATHAN, VARANASI REGION

Sample Paper, 2015 Subject: Computer Science Class 12 th

Downloaded from

(i) case (ii) _delete (iii) WHILE (iv) 21stName

DATA FILE HANDLING. The function should create another file OUT.TXT with the text

Series SHC COMPUTER SCIENCE. Code No. 91. Roll No.

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

EAS 230 Fall 2002 Section B

COMPUTER SCIENCE (Theory) Class XII - Code : 083 Blue Print

SAMPLE PAPER-2015 CLASS-XII COMPUTER SCIENCE. Sample paper-i. Time allowed: 3 hours Maximum Marks: 70 Name : Roll No.:

Study Material for Class XII. Data File Handling

SAMPLE PAPER 2015 SUB - COMPUTER SCIENCE - (Theory) CLASS XII Time allowed: 3 hours Maximum marks: 70

C++ Programming Lecture 10 File Processing

KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST PRE-BOARD EXAMINATION COMPUTER SCIENCE

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Computer Science 2006 (Delhi)

Subject - Computer Science (Code-083)

Downloaded from

SUBMITTED AS A PART OF C.B.S.E. CURRICULUM FOR THE YEAR

Padasalai.Net Half Yearly Exam Model Question Paper

Kendriya Vidyalaya Sangathan Model Question Paper-1 Class XII Subject - Computer Science (083) Max. Marks: 70. Blue Print

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch - 7. Data File Handling

(d) Observe the following C++ code very carefully and rewrite it after removing any/all syntactical errors: [2] Include < iostream.

Transcription:

HALF-YEARLY EXAMINATION-2017-2018 COMPUTER SCIENCEMARKING SCHEME CLASS XII 1. (a) Write any two differences between procedural programming and object oriented programming. 2 Ans. Procedural oriented programming Object oriented programming Function oriented Object oriented No data security Data security Not extensible extensible Do not model the real world problems very well Model real world problems Addition of new data and function is difficult Addition of new data and functions is easy Top down approach Bottom to top approach (b) Which C++ header file(s) will be essentially required to be included to run /execute the following C++ code: 1 void main() charmsg[ ]="Sunset Gardens"; for (int I=5;I<strlen(Msg);I++) puts(msg); Ans. string.h, stdio.h (b) Rewrite the following program after removing the syntactical errors (if any). Underline each correction. 2 #include <iostream.h> struct Pixels intcolor,style; voidshowpoint(pixels P) cout<<p.color,p.style<<endl; void main() Pixels Point1=(5,3); ShowPoint(Point1); Pixels Point2=Point1; Color.Point1+=2; ShowPoint(Point2); Answer: #include <iostream.h> struct Pixels intcolor,style;; voidshowpoint(pixels P) cout<<p.color<<p.style<<endl; void main() Pixels Point1=5,3; ShowPoint(Point1); Pixels Point2=Point1; Point1.Color+=2; ShowPoint(Point2); (1/2 Mark for correcting each error) OR (1 Mark for identifying all the 4 errors with no correction) Page 1 of 14

(d) Find the output of the following program: 2 #include <iostream.h> void Secret(char Str[ ]) for (int L=0;Str[L]!='\0';L++); for (int C=0;C<L/2;C++) if (Str[C]=='A' Str[C]=='E') Str[C]='#'; else char Temp=Str[C]; Str[C]=Str[L-C-1]; Str[L-C-1]=Temp; void main() char Message[ ]="ArabSagar"; Secret(Message); cout<<message<<endl; Ans. #agasbarr (e) Find the output of the following program: 3 #include <iostream.h> struct GAME int Score, Bonus;; void Play(GAME &g, int N=10) g.score++; g.bonus+=n; void main() GAME G=110,50; Play(G,10); cout<<g.score<<":"<<g.bonus<<endl; Play(G); cout<<g.score<<":"<<g.bonus<<endl; Play(G,15); cout<<g.score<<":"<<g.bonus<<endl; 111:60 112:70 113:85 (f) In the following program, find the correct possible output(s) from the options: Justify. 2 #include<stdlib.h> #include<iostream.h> void main ( ) randomize() ; char Area [] [10] = NORTH, SOUTH, EAST, WEST ; inttogo; for (int I=0; 1<3; 1++) ToGo = random(2) +1; cout<<area [ToGo]<< : ; Page 2 of 14

(i) SOUTH:EAST:SOUTH: (ii) NORTH:SOUTH:EAST: (iii) SOUTH:EAST:WEST: (iv) SOUTH:EAST:EAST: Ans. (i) justify with proper random value and 2D character array 2. (a) What do you understand by constructor and destructor functions used in a class? How are these functions different from other member functions? 2 Answer: Constructors: These are the special member functions of class which are used to initialize the object with suitable value. These are automatically invoked when a new object will be created Destructors: These are special member functions which are used to deinitialize the object. They will automatically invoked when the object will out of scope. WE need to invoke the general functions when we need it but these functions will automatically invoked. (1 Mark each for definition) (b) Answer the questions (i) and (ii) after going through the following class. 2 class wholesale floatpr; intqty; charcateg[20], item[30]; wholesale() // function 1 strcpy(categ, food ); strcpy( item, biscuits ); pr=150; qty=10; void show() // function 2 ; void main() cout<<categ<< # <<item<< : <<pr<< @ <<qty<<endl; wholesaleob; // statement 1 ob.show(); // statement 2 (i) Will statement 1 initialize all the data members for object ob with the values given in function 1 (Y/N)? Justify your answer suggesting the corrections to be made in the above code. (ii) What shall be the possible output when the program gets executed? (Assuming if required the suggested correction(s) are made in the program). (i) No, constructor is given in private access specifier group. It should be in public. (ii) Food # Biscuit- 150 @ 10 Page 3 of 14

(c) Define a class patient in C++ with following description: 4 Private members: Pidno integer patient id Pname string patient name Charges float charges per day Noofdays int number of days Totcharge float total charge Calcharge() Public Members: In_data() A function to calculate total charges due( charges * noofdays) With return value float to accept values for pidno, pname, charges, noofdays and invoke Calcharge() to calculate total charges Out_data() to display all data members class patient intpidno; charpname[20]; float charges; intnoofdays; floattotcharge; floatcalcharge(); voidin_data(); voidout_data(); ; void patient::in_data() cout<< enter id ; cin>>pidno; cout<< enter name ; gets(pname); cout<< charges per day ; cin>>charges; cout<< enter number of days ; cin>>noofdays; totcharges=calcharge(); float patient:: calcharge() return ( charges * noofdays); void patient:: out_data() cout<< id <<pidno; cout<< name ; puts(pname); cout<< charges per day <<charges; cout<< number of days <<noofdays; cout<< total charge <<totcharge; (d) Consider the following c++ declarations and answer the questions given below4 class vehicle protected: int passenger; int wheels; Page 4 of 14

voidinputdata( int, int); voidoutputdata(); ; classheavy_vehicle: protected vehicle intdiesel_petrol; protected : int load; voidreaddata( int, int); voidwritedata(); ; class bus: private heavy_vehicle char make[20]; voidfetchdata( char); voiddisplaydata(); (i) (ii) (iii) (iv) Name the base class and derived class of the class heavy_vehicle; Name the data members that can be accessed from function displaydata() Name the data members that can be accessed by object of class bus. Is the member function outputdata() accessible to the object of class heavy_vehicle. (i) base class : vehicle (ii) make, load, passenger (iii) none (iv) no derive class : bus 3. (a) Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement2 using seekg() and tellg() functions for performing the required task. 2 #include <fstream.h> class Employee inteno;charename[20]; //Function to count the total number of records intcountrec(); ; int Employee::Countrec() fstream File; File.open( EMP.DAT,ios::binary ios::in); //Statement 1 int Bytes = //Statement 2 int Count = Bytes / sizeof(employee); File.close(); Page 5 of 14

return Count; Answer: File.seekg(0, ios::end); File.tellg(); (b) A binary file Students.dat contains data of 10 students where each student s data is an object of the following class: 1 class Student intrno;char Name[20]; voidenterdata() cin>>rno; cin.getline(name,20); voidshowdata() cout<<rno<< - <<Name<<endl; ; With reference to this information, write output of the following program segment: ifstream File; Student S; File.open( STUDENTS.DAT,ios::binary ios::in); File.seekg(0, ios::end); cout<<file.tellg(); Ans. 220 (c) Write a function in C++ to count the number of words starts with t or f present in a text file NOTES.TXT.( both cases considered) 2 Answer: voidcountwords() ifstream FIL("NOTES.TXT"); int count=0; charstr[80]; FIL>>str; while (FIL) if( (toupper(str[0])== t ) (toupper(str[0])== f )) count++; FIL>>str; cout<<"no. of Words:"<<count<<endl; FIL.close(); ( ½ mark for opening the file in correct mode) ( ½ mark for checking eof) ( ½ mark for reading each word) ( ½ mark for correct increment) (d) Write a function in C++ to add new objects at the bottom of a binary file STUDENT.DAT, assuming the binary file is containing the objects of the following class. 2 class STUD intrno; char Name[20]; void Enter()cin>>Rno;gets(Name); void Display()cout<<Rno<<Name<<endl; Page 6 of 14

intreturn_rno() return Rno; voidmodirec( int r) rno=r; cout<< Enter changed name ; gets(name); ; Answer: voidaddnew() fstream FIL; FIL.open( STUDENT.DAT,ios::binary ios::app); STUD S; char CH; do S.Enter(); FIL.write((char*)&S,sizeof(S)); cout<< More(Y/N)? ;cin>>ch; while(ch == Y ); FIL.close(); ( ½ mark for opening the file in app mode) ( ½ mark for calling the member function Enter correctly) ( 1/2 mark for writing the content of object to the binary file) ( ½ mark for forming the appropriate loop) (e) Write a function in C++ to modify an object from a binary file STUDENT.DAT, assuming the binary file is containing the objects of the class STUD (given above 3(d) part). The Rno of the object to be modified will be passed as an argument. 3 Answer. voidmodify_record(int RNO) ifstream FIL1; FIL1.open("STUDENT.DAT",ios::binary); ofstream FIL2; FIL2.open("TEMP.DAT",ios::binary); STUD S; while(fil1.read((char*)&s,sizeof(s))) if (RNO == S.Return_Rno()) S.modirec( RNO); FIL2.write((char*)&S,sizeof(S)); FIL1.close(); FIL2.close(); remove("student.dat"); rename("temp.dat","student.dat"); ( 1/2 mark for opening the files in correct modes) ( ½ mark for declaration of desired object) ( ½ mark for correct loop) ( 1/2 mark for checking & writing the content of object to the binary file) Page 7 of 14

( 1 mark for writing remove & rename functions) (f) Given a binary file directory.dat containing records of the phone details with following class members 3 classphonelist char name[20]; char address[30]; char phone[10]; voidphone_input(); voidshow_data(); intcheckno( char tno[]) if(tno[0] == 2 ) return 1; else retun 0; ; // to input data members // to display all data members // checks the number Write a function shift_mtnl() in c++ that would display and copy all those records which are having phone number starting with digit 2 from directory.dat to mtnl.dat voidcopyphonelist() ifstream if1; if1.open( directory.dat, ios::binary); ofstream of1; of1.open( mtnl.dat, ios::binary); phonelist p; while(if.read((char *) &p, sizeof(p))) if(p.checkno(p.phone)==1) p.show_data(); of1.write((char *)&p, sizeof(p)); if1.close(); of1.close(); 4. (a) Find the output: 3 # include <iostream.h> void main ( ) int Track [] = 10,20,30,40,, *Striker ; Striker=Track ; Track [1] += 30 ; cout<<"striker"<<*striker<<endl ; *Striker -=10 ; Striker++; Page 8 of 14

cout<<"next @"<<*Striker <<endl ; Striker +=2 ; cout<<"last @"<<*Striker<<endl ; cout<<"reset To"<<Track [0] <<endl ; Striker10 Next @50 last @40 Reset To0 (b) Find the output: 3 #include<iostream.h> #include<conio.h> int a=3; void demo(int&x, int y, int *z) a +=x; y *=a; *z = a+y; cout<<x<<y<<*z<<endl; void main() int a=2, b=5; demo(::a, a, &b); cout<<::a<<a<<b<<endl; 61218 6 218 ( c) What do you mean by self-referential structure? Explain with a suitable c++ code. 2 It is a normal structure where one of the data member is a pointer type points to structure type. It is used to create node in a linked list. structstd int roll; char name[20]; std * next; ; Here roll and name stores normal data where next will store address of any variable of std type. 5. (a) Write a function SORTPOINTS() in C++ to sort an array of structure GAME in descending order of Points using Selection Sort. The function will have two arguments - array of structure GAME & size of array. Also assume the following definition of structure GAME: 3 struct GAME long PNO; // Player Number charpname[20]; long Points; ; ; Answer. void SORTPOINTS(GAME a[], int n) intlargest,pos,temp; for ( inti = 0; i< n; i++) pos = i; largest = a[i].pno; Page 9 of 14

for ( int j = i+1; j< n; j++) if ( a[j].pno > largest) largest = a[j].pno; pos = j; temp = a[i].pno; a[i].pno = a[pos].pno; a[pos].pno = temp; (1/2 Mark for function header with desired parameters) (1 Mark for correct formation of outer loop) (1 Mark for correct formation of inner loop) (1/2 Mark for swapping) (b) Write a function in C++ to display the product of every alternate elements( starting from (0,0) ) of a two dimensional integer array passed as the argument of the function. Number of rows and number of columns will also be passed as arguments. 2 Answer. void PRODUCTELEMENT( int a[][5], int r, int c) int p=1, flag=1; for (inti = 0; i< r; i++) for (int j = 0; j < c; j++) If( flag % 2!=0) p = p * a[i][j]; flag++; cout<<"\nproduct of elements "<<p; (1/2 Mark for function header with desired parameters) (1/2 Mark for correct formation of loop) (1/2 Mark for the formula) (1/2 Mark for displaying output) (c) An array P[20][30] is stored in the memory along the column with each of the element occupying 4 bytes, find out the memory location for the element P[5][15], if an element P[2][20] is stored at the memory location 5000. 3 Answer: Given, W=4 N=20 M=30 Loc(P[2][20])=5000 Column Major Formula: Loc(P[I][J]) =Base(P)+W*(N*J+I) Loc(P[2][20]) =Base(P)+4*(20*20+2) 5000 =Base(P)+4*(400+2) Base(P) =5000-1608 Base(P) =3392 Loc(P[5][15]) =3392+4*(20*15+5) Page 10 of 14

=3392+4*(300+5) =3392+1220 =4612 (1 Mark for correct formula/substitution of values in formula) (1 Mark for correctly calculating Base Address) (1 Mark for correctly calculating address of desired location) (d) Convert the following infix expression to its equivalent postfix expression showing the stack contents for the conversion.a / ( B + C ) * D E 3 element operation stack status postfix operation ( push ( A print A / push ( / A ( push ( / ( A B print ( / ( AB + push ( / ( + AB C print ( / ( + ABC ) pop and print ( / ( ABC + Pop and cancel ( / ABC + * pop and print ( ABC + / Push ( * ABC + / D print (* ABC + / D - pop and print ( ABC + / D * push ( - ABC + / D * E print ( - ABC + / D * E ) pop and print ( ABC + / D * E - pop and cancel ABC + / D * E - ; stop ABC + / D * E - (e) Evaluate the following postfix notation of expression: 2 F T NOT AND F OR T AND ITEM SCANNED OPERATION STACK F PUSH F T PUSH F T NOT POPT EVALUATE NOT T PUSH F F FF AND POP F POP F EVALUATE F AND F PUSH F F # F F PUSH F F OR POPF, POPF EVALUATE F OR F PUSH F F # F T PUSH F T Page 11 of 14

AND POPT, POPF EVALUATE F AND T PUSH F F ; POP AND PRINT F (f) Write a function to delete an element from static circular queue. 2 voidcqueuedelete() if(front==-1) cout<<"\n Circular Queue is empty";return; cout<<data[front]<<" deleted"<<endl; if(front==rear) front=-1;rear=-1; else if(front==size-1) front=0; else front++; (g) Write the function to insert an element into a dynamic queue ( queue represented by link list). Represent queue by linked class where each node is is represented by given structure 3 struct node char name[20]; int age; node * link; ; class queue node *rear,*front; queue() rear=null; front=null; void qinsert(); void qdelete(); void qdisplay(); ~queue(); ; void queue::qinsert() node *temp; temp=new node; cout<<"data :"; cin>>temp->data; temp->next=null; if(rear==null) F # Page 12 of 14

rear=temp; front=temp; else rear->next=temp; rear=temp; 7. (a) Observe the following Table and answer the parts (i) and (ii) accordingly 2 Table: MEMBER Mno Name Qty PurchaseDate 101 Pen 102 12-12-2011 102 Pencil 201 21-02-2012 102 Eraser 90 09-08-2010 109 Sharpener 90 31-08-2012 113 Clips 900 08-08-2011 (i) In the above table, can we take Mno as Primary Key? (Answer as [YES/NO] only). Justify your answer with a valid reason. Ans. Yes, Mno is unique for each item. (ii) What are the degree and the cardinality of the above table? Ans. Degree = 4 cardinality = 5 Consider the following tables SUBJECT and TEACHER and answer (b)part of this question: Table: SUBJECT Code Title Marks_Theory Marks_Prac 301 English 100 0 041 Maths 100 0 083 Computer 70 30 042 Physics 70 30 043 Chemistry 70 30 Table: TEACHER TCode Name Sub_Code 1 P.Jain 301 2 RNagpal 301 3 Supatra 041 4 Shabnam 083 5 Rashika 042 6 Vidushi 041 7 Yash 043 (b) Write SQL commands for the flowing statements: 5 (i) To display the names of all the subjects for which practical marks are 0. (ii) To display the total number of teachers in each subject separately. (iii) To display the names of all the teachers in the ascending order of the Sub_Code. (iv) To display each subject s details along with Total_Marks in each subject from the table SUBJECT. (Total_Marks = Marks_Theory + Marks_Practical). (v) Write SQL statement to display each teacher s name along with his/her respective subject name from the tables TEACHER and SUBJECT. Ans. (i) SELECT TITLE FROM SUBJECT WHERE MARKS_PRAC = 0; (ii) SELECT SUB_CODE, COUNT(*) FROM TEACHER GROUP BY SUB_CODE; (iii) SELECT NAME FROM TEACHER ORDER BY SUB_CODE; Page 13 of 14

(iv) SELECT CODE,TITLE, (Marks_Theory + Marks_Practical) FROM SUBJECT ; (v)select NAME, TITLE FROM TEACHER, SUBJECTWHERE TEACHER.SUB_CODE = SUBJECT.CODE; Give the output of the following SQL queries: (vi) SELECT DISTINCT(Marks_Theory) from SUBJECT; (vii) SELECT TCode, Name from Teacher where Sub_Code like 0% ; Ans. (vi) 2 (vii) Supatra 041 Shabnam 083 Rashika 042 Vidushi 041 Yash 043 (c) What do you mean by candidate key? 1 The key or combination of keys which can be primary key for the relation if called candidate key. In an relation more than one candidate key possible. Page 14 of 14