Sei sulla pagina 1di 12

SAMPLE CS2013

1.

PAPER

(SOLUTION-

MARKING

SCHEME

(BASED ON NEW PATTERN) COMPUTER SCIENCE [CODE083]CLASS XII


Max Time : 3 hours Max Marks : 70

(a) Write the prototype of a function named Percent, which takes (2) an integer as value parameter and return a float type value. The parameter should have a default value 10.

AAns:-

float Percent (int x=10);


are NOT necessary to(1)

1(b) Write the names of header files, which run the following program: #include <iostream.h> #include <stdio.h> #include <string.h> #include <math.h> void main() { char STR[80]; gets(STR); puts(strrev(STR)); }

Ans:- <iostream.h> <math.h>


1(c) Tarunaj has just started working as programmer in the JAGAT WORLD SOFTWARE company. In the company, he has got his first assignment to develop a small C++ module to find the biggest number out of a given set of numbers stored in a one dimensional array. Somehow he has committed a few logical mistakes while writing this code and so he is not getting the desired result from the code. Find out the mistakes and correct this C++ code so that it provides the desired result (do not add any new statement in the code). Underline each correction made: int BIGFIND(int ARR[],int Size) { int BIG=ARR[1]; for (int C=2;C<Size;C++) if (ARR[C]<BIG) ARR[C]=BIG; return BIG; } //Statement 1 //Statement 2 //Statement 3 //Statement 4 //Statement 5

Ans: int BIG=ARR[0]; //Statement 1 //in C++ FIRST ELEMENT has index

0,

and

//second element has 1 for (int C=1;C<Size;C++) if (ARR[C]> BIG) BIG= ARR[C]

//Statement 2 //Statement 3 //Statement 4

1(d) Find output of the following program segment: int A[][3] = {{1,2,3}, {5,6,7}}; for (int i = 1; i<2; i++) for (int j = 0; j<3; j++) cout<<A[i][j]<<"*\n";
Ans:- 5* 6* 7*

1(e) Find output of the following program segment: int a = 3; void demo(int x, int y, int &z) // z is call by reference { a += x+y;//in first call a =8, in second call a =18 z = a+y; // in first call z=10 , in second call z =20 y += x; // in first call y=5 , in second call y =10 cout<<x<<'*'<<y<<'*'<<z<<endl; // in first call 3<<5<<10 // in second call 8<< 10<<20 } void main() { int a = 2, b = 5; demo(::a,a,b); //3,2,5 ::a means global main())of a will be reffered demo(::a,a,b);//8,2,10 }

version

(declared

out

of

Answer:

3*5*10 8*10*20

2.(a) What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable C++ code to illustrate both.

Data Encapsulation: Data Encapsulation combines data and functions into a single unit called Class. Data Encapsulation enables the important concept of data

hiding possible. Define a class having both data and functions as members make all data members private to hide its visibility/accessibility from outside the class. Make some member function as public that will be used to interact with the outside world from main function. Data Encapsulation: Wrapping up of data and functions together in a single unit is known as Data Encapsulation. In a class, we wrap up the data and functions together in a single unit. Data Hiding: Keeping the data in private visibility mode of the class to prevent it from accidental change is known as Data Hiding.

class Computer {char CPU[10];int RAM; public: Data Encapsulation void STOCK(); void SHOW(); }; ( Mark each for appropriate definitions) (1 Mark for appropriate example showing both) (2)(b) What is constructor overloading? Give an example to illustrate the same. ..ANSWEREXAMPLE.. class Exam {char Subject[20] ; int Marks ; public : Exam() // Function 1 { strcpy(Subject, Computer ) ; Marks = 0 ; } Exam(char P[ ]) // Function 2 { strcpy(Subject, P) ; Marks=0 ; } Exam(int M) // Function 3 { strcpy(Subject, Computer) ;

Marks = M ; } Exam(char P[ ], int M) { strcpy(Subject, P) ; Marks = M ; } }; // Function 4

(2)(c) Define a class HandSet in C++ with following description: Private members: Make- of type string Model- of type string Price- of type long int Rating- of type char Public Members: Function Read_Data to read an object of HandSet type. Function Display() to display the details of an object of HandSet type. Function RetPrice() to return the value of Price of an object of HandSet type. (4) --------------------------------- ANSWER 2(C)------------------------------------------------------------------class HandSet { private : char Make[20]; char Model[20]; long int Price; char Rating; public: void Read_Data() {cout<<\n Enter Make , Model ,Price and Rating : \n ; gets(Make); gets(Model); cin>>Price; cin>>Rating;} void Display() {cout<<\n Make : <<Make<<\n Model : <<Model<<\n Price<< Price<<\n Rating : <<Rating;} long int RetPrice() { return Price;} 2(d) Consider the following class counter: class counter { protected : unsigned int count; public : counter() { count = 0; } void inc_count() { count++; } int get_count()

{ return count; } }; Write code in C++ to publically derive another class new_counter from class counter. Class new_counter should have the following additional function members in the public visibility mode: (i) A parameterized constructor to initialize the value of count to the value of parameter. (ii) dec_count() to decrease the value of data member count by 1. (iii) Reset() to set the value of data member count to 0.

ANSWER

2(D ) .. class new_counter : public counter { public: new_counter(unsigned int x) { count=x; } void dec_count(){count--;} void Reset() {count=0;} };
3 (a) Write a function TRANSFER(int A[], int B[], int Size) in C++ to copy the elements of array A into array B in such a way that all the negative elements of A appear in the beginning of B, followed by all the positive elements, followed by all the zeroes maintaining their respective orders in array A. For example: If the contents of array A are: 7, -23, 3, 0, -8,-3,4, 0 The contents of array B should be -23 , -8, -3, 7, 3, 4, 0 ------------------------------------------------ANSWER 3(a)--------------------------------------------------#include<iostream.h> #include<conio.h> void transfer(int a[],int b[],int size); void main() { int a[]= {7, -23, 3, 0, -8,-3,4, 0},b[8]; transfer(a,b,8); for(int i=0;i<8;i++) cout<<b[i]<<'\t'; getch(); }

void transfer(int a[],int b[],int size) { int k=0; for(int i=0;i<size;i++) if(a[i]<0) { b[k]=a[i]; k++; } for(int i=0;i<size;i++) if(a[i]>0) { b[k]=a[i]; k++; } for(int i=0;i<size;i++) if(a[i]==0) { b[k]=a[i]; k++; } } 3(b) Each element of the array A[8][6] is stored using 4 bytes of memory. If the element A[2][4] is stored at location 936, find the address of A[5][1]. Assume that the array is stored column-wise. ----------------------------------------------------------ANSWER 3(b)-------------------------------------------------------------------Given : Size of each element (w) = 4, No of colums (Nc) = 6, No. of rows(Nr) =8 Actual Physical Address of A[2][4] in Column Major scheme =Base Address + w * [(i -0) +Nr * (j-0)] Here, i=2 and j=4; Actual Physical Address of A[2][4] in Column Major scheme =936 So, using formula we calculate Basic Address (BA)-936= BA+4(2+8*4) 936=BA+4*34 BA=936-136 BA=800 Actual Physical Address of Element A[5][1] in Column Major scheme =

j=1; in Column Major scheme

Base Address + w * [(i -0) +Nr * (j-0)] Here, i=5 and BA=800 Actual Physical Address of Element A[5][1] =800+4[5+8*1]

=800+4*13 =852 (Answer) 3(c) Write a function in C++ to perform Insert operation in a circular Queue containing Players information (represented with the help of an array of structure PLAYER). -----------------------------ANSWER 3 ( c ) ---------------------------------------------------------#include<iostream.h> #include<conio.h> struct PLAYER { long PID; //Player ID char Pname[20]; //Player Name } p[3]; int rear=-1, front=-1; void insert( PLAYER p1, int size) { if((front==0 && rear==size-1)||front==rear+1) { cout<<"\n over flow" ; return; } else if(front==-1) front=rear=0 ; else if(rear==size-1) rear=0; else rear++; p[rear]=p1; cout<<"\n player successfully added"; } Note: Here , main program is given only four output testing purpose. Please dont write main program in examination..write only the definition of function asked. void main() { PLAYER P; long id; char name[10],ch='y'; while(ch=='y') { cout<<"\n enter id of player";\ cin>> P.PID;

cout<<"\n enter name of player"; cin>>P.Pname; insert(P,3); cout<<"\n press y to continue"; cin>>ch; } getch(); } 4.(a) A binary file Students.dat contains data of 10 students where each students data is an object of the following class: class Student { int Rno;char Name[20]; public: void EnterData() {cin>>Rno; cin.getline(Name,20); void ShowData() {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); // it sets the Read File pointer at the end of filelast char in file Cout<<File.tellg(); //it displays how far is the READ FILE POINTER from the beginning of file (in terms of bytes) ----------------------------------- ANSWER -4 (a)---------------------------------------------------------Cout<<File.tellg(); //it displays how far is the READ FILE POINTER from the beginning of file (in bytes)here in the Current situation it displays total no. of bytes/char present in the file. Total no. of records (i.e. objects of class student ) present in the STUDENTS.DAT = 10 Size of each record= sizeof(student object)= sum of size of each data member=sizeof(int)+sizeof(Name)=4+20=24

NOTE : SIZE OF INT For BORLAND C++ it is Size of file=position stored in file * Size =10 * 24 =240 Bytes

is different in different compilers. 4 Bytes of last char in file= No of Records of each Record (In BC++)--- Answer = 240

4(b) Write a function in C++ to count the number of lines starting with a digit in a text file DIARY.TXT. ----------------------------------- ANSWER -4 (B)---------------------------------------------------------#include<fstream.h> #include<conio.h> #include<stdio.h>

#include<ctype.h>

void countLines() { ifstream f; f.open("DIARY.TXT"); int count=0; char line[200]; while(f) { f.getline(line,100); if (isdigit(line[0])) count++; } cout<<"\n No of lines starting "<<count; f.close(); }
void main () { countLines(); getch(); }

with

digit

4 (c) Given a binary file STUDENT.DAT, containing records of the following class Student type: class student { char S_admno[10]; //Admission no. of student char S_Name[20]; //Name of student int Percentage; //Marks percentage of student public: void EnterData() { gets(S_admno); gets(S_Name); cin>>Percentage; } void DisplayData() { cout<<setw(12)<<S_admno; cout<<setw(32)<<S_Name; cout<<setw(3)<<Percentage<<endl; } int Ret_Per() {return Percentage;} }; Write a function in C++ that would read contents of the file STUDENT.DAT and display the details of those students whose percentage is above 75.

. ANSWER 4 ( c ) . #include<fstream.h> #include<conio.h> #include<stdio.h> #include<iomanip.h> class student { char S_admno[10]; //Admission no. of student char S_Name[20]; //Name of student int Percentage; //Marks percentage of student public: void EnterData() { gets(S_admno); gets(S_Name); cin>>Percentage; } void DisplayData() { cout<<setw(12)<<S_admno; cout<<setw(32)<<S_Name; cout<<setw(3)<<Percentage<<endl; } int Ret_Per() {return Percentage;} }p; void main() { void EnterFile(); void DisplayFile(); EnterFile(); DisplayFile(); getch(); } void EnterFile() { ofstream f; f.open("STUDENT.DAT ",ios::binary); char flag='y'; do{ cout<<"\n Enter admissin no , name and percentage of student \n"; p.EnterData(); f.write((char*)&p,sizeof(p)); cout<<"\n Do you want to continue.... press 'y' ..."; cin>>flag; }while(flag=='y'); f.close(); }

void DisplayFile() { ifstream f;

f.open("STUDENT.DAT ",ios::binary); while(1) { f.read((char*)&p,sizeof(p)); if(f.eof()==1) break; else if(p.Ret_Per()>75) p.DisplayData(); } f.close(); }
5. (a)-(i)- (ANSWER) NO, MNo column cannot be made as Primary Key because valus in this column are not UNIQUE, value 102 is repeated more than one time. It is violating the Primary Key constraints so cannot act as Primary Key. (Same member can purchase many different type of products, hence respective MNO can be repeated.) 5. (a)-(ii)- (ANSWER) Degree=No. of columns= 4 , Cardinality=No. of rows = 5 5.(b)-(i)-SELECT TITLE FROM SUBJECT WHERE MARKS_PRAC=0; (II) SELECT COUNT(TCODE),SUB_CODE FROM TEACHER GROUP BY SUB_CODE; (III) SELECT NAME FROM TEACHER ORDER BY SUB_CODE; (IV) SELECT CODE , TITLE, (MARKS_THEORY+MARKS_PRAC) AS TOTAL MARKS FROM SUBJECT ; 5.(C) SELECT SUBJECT.TITLE , TEACHER.NAME FROM SUBJECT , TEACHER where SUBJECT.CODE=TEACHER.SUB_CODE ; 5.(d)-(i) output : 100 70 (ii)output : 4 Shabnam 5 Rashika 6 Vidushi 7 Yash 5.(e) In subject table code can be made PRIMARY KEY. In TEACHER table TCode can be made PRIMARY KEY 7.(a) RADIO WAVE 7.(b) SMTP protocol is used to receive emails. 7.(c)COOKIE S -Information sent by webserver to the web browser. 7.(d) client-side script 7.(e) Free Software: The S/Ws is freely accessible and can be freely used changed improved copied and distributed by all and payments are needed to make for free S/W. Freeware: Freeware are the software freely available , which permit redistribution but not modification (and their source code is not available). Freeware is distributed in Binary Form (ready to run) without any licensing fees. Note- Crossed line which are marked green are not part of the solution, only yellow colored lines are the actual solution to be

written in exam. I have tried my best to avoid any mistakes while preparing the solution, but still there might be few chances that errors might exist... so, please feel free to post your comments / suggestions or mail me at hsyadav.kvs@gmail.com . Your suggestions will be most welcomed and appreciated. ****************************THE END**********************************

Potrebbero piacerti anche