Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Operators and File Handling, Schemes and Mind Maps of English Language

Various c++ operators and file handling concepts. It includes questions and answers on logical, relational, and arithmetic operators, as well as examples of header file usage, array manipulation, and circular queue implementation. The document also discusses converting infix expressions to postfix, searching and displaying details from a binary file, and sql queries related to a database schema. This comprehensive material could be useful for students preparing for exams, assignments, or university essays in computer science or programming-related courses.

Typology: Schemes and Mind Maps

2020/2021

Uploaded on 06/16/2022

Priyanka_V_2
Priyanka_V_2 🇮🇳

1 document

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SAMPLE QUESTION PAPER 2018-19
Marking Scheme
COMPUTER SCIENCE (Code: 083)
CLASS:-XII
Time:3 Hrs.
M.M.:70
Q. No. Part Question Description Marks
1 (a) Write the type of C++ Operators (Arithmetic, Logical, and Relational 2
Operators) from the following:
(i) !(ii) !=(iii) &&(iv) %
Ans. (i) Logical (ii) Relational (iii)Logical (iv) Arithmetic
(1/2 Mark for each correct Operator Type)
(b) Observe the following program very carefully and write the name of those 1
header file(s), which are essentially needed to compile and execute
thefollowing program successfully:
void main()
{
char text[20], newText[20];
gets(text);
strcpy(newText,text);
for(int i=0;i<strlen(text);i++)
if(text[i]==’A’)
text[i]=text[i]+2;
puts(text);
}
Ans. stdio.h
string.h
(½ Mark for writing each correct header file)
NOTE: Any other header file to be ignored
(c) Rewrite the following C++ code after removing any/all Syntactical Error(s) (2)
with each correction underlined.
Note: Assume all required header files are already being included in the
program.
#define float PI 3.14
void main( )
{
float R=4.5,H=1.5;
A=2*PI*R*H + 2*PIpow(R,2);
cout<<‘Area=’<<A<<endl;
}
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download C++ Operators and File Handling and more Schemes and Mind Maps English Language in PDF only on Docsity!

SAMPLE QUESTION PAPER 2018-

Marking Scheme COMPUTER SCIENCE (Code: 083) CLASS:-XII Time:3 Hrs. M.M.: Q. No. Part Question Description Marks 1 (a) Write the type of C++ Operators (Arithmetic, Logical, and Relational 2 Operators) from the following: (i) !(ii) !=(iii) &&(iv) % Ans. (i) Logical (ii) Relational (iii)Logical (iv) Arithmetic (1/2 Mark for each correct Operator Type) (b) Observe the following program very carefully and write the name of those 1 header file(s), which are essentially needed to compile and execute thefollowing program successfully: void main() { char text[20], newText[20]; gets(text); strcpy(newText,text); for(int i=0;i<strlen(text);i++) if(text[i]==’A’) text[i]=text[i]+2; puts(text); } Ans.  stdio.h  (^) string.h (½ Mark for writing each correct header file) NOTE: Any other header file to be ignored (c) Rewrite the following C++ code after removing any/all Syntactical Error(s) (2) with each correction underlined. Note: Assume all required header files are already being included in the program. #define float PI 3. void main( ) { float R=4.5,H=1.5; A=2PIRH + 2PIpow(R,2); cout<<‘Area=’<<A<<endl; }

#define PI 3.14//Error 1 void main( ) { float R=4.5,H=1.5; floatA=2PIRH + 2PIpow(R,2); //Error 2, 3 cout<<“Area=”<<A<<endl; //Error 4 } (½ Mark for each correction) OR (1 mark for identifying the errors, without suggesting corrections) (d) Find and write the output of the following C++ program code: (3) Note: Assume all required header files are already being included in the program. void main( ) { int Ar[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ; int Ptr = Ar , I ; cout<<++Ptr++ << '@' ; I = Ar[3] - Ar[2] ; cout<<++(Ptr+I)<<'@'<<"\n" ; cout<<++I + Ptr++ << '@' ; cout<<Ptr++ <<'@'<< '\n' ; for( ; I >=0 ; I -=2) cout<<Ar[I] << '@' ; } Ans 7@11@ 6@8@ 11@3@ (½ Mark for writing each correct value) OR (Only ½ Mark for writing all ‘@’ at proper places) Note: ● Deduct only ½ Mark for not considering any or all correct placements of @ ● Deduct only ½ Mark for not considering any or all line break (e) Find and write the output of the following C++ program code: (2) typedef char STRING[80]; void MIXNOW(STRING S) { int Size=strlen(S); for(int I=0;I<Size;I+=2) { char WS=S[I];

2 (a) What is a copy constructor? Illustrate with a suitable C++ example. (2) 3 Ans. A copy constructor is an overloaded constructor in which an object of the same class is passed as reference parameter. class X { int a; public: X() { a=0; } X(X &ob) //copy constructor { a=ob.a; } }; (Full 2 Marks to be awarded if the copy constructor is explained with an appropriate example) OR (1 Mark for correct explanation of copy constructor only without an example) (b) Write the output of the following C++ code. Also, write the name of (2) feature of Object Oriented Programming used in the following program jointly illustrated by the Function 1 to Function 4. void My_fun ( ) // Function 1 { for (int I=1 ; I<=50 ; I++) cout<< "-" ; cout<<end1 ; } void My_fun (int N) // Function 2 { for (int I=1 ; I<=N ; I++) cout<<"" ; cout<<end1 ; } void My_fun (int A, int B) // Function 3 { for (int I=1. ;I<=B ;I++) cout <<AI ; cout<<end1 ; } void My_fun (char T, int N) // Function 4 { for (int I=1 ; I<=N ; I++) cout<<T ; cout<<end1;

void main ( ) { int X=7, Y=4, Z=3; char C='#' ; My_fun (C,Y) ; My_fun (X,Z) ; } OR Write any four differences between Constructor and Destructor function with respect to object oriented programming Ans. #### 71421 Polymorphism OR Function Overloading OR Constructor Destructor Name of the constructor function is Name of the destructor function is same as that of class same as that of class preceded by ~ Constructor functions are called Destructor functions are called automatically at the time of automatically when the scope of creation of the object the object gets over Constructor can be overloaded Destructor ca not be overloaded Constructor is used to initialize the Destructor is used to de- initialize data members of the class the data members of the class (½ Mark for writing each correct line of output) (1 Mark for writing the feature name correctly) OR (½ Mark for writing each correct difference) (c) Define a class Ele_Bill in C++ with the following descriptions: (4) Private members: Cname of type character array Pnumber of type long No_of_units of type integer Amount of type float. Calc_Amount( ) This member function should calculate the amount asNo_of_units*Cost.

gets(Cname); cin>Pnumber>>No_of_units; Calc_Amount( ); } void Ele_Bill :: Display( ) { cout<<Cname<<Pnumber<<No_of_units<<Amount; } (½ Mark for declaring class header correctly) (½ Mark for declaring data members correctly) (1 Mark for defining Calc_Amount() correctly) (½ Mark for taking inputs of Cname, Pnumber and No_of_units in Accept()) (½ Mark for invoking Calc_Amount() inside Accept()) (½ Mark for defining Display() correctly) (½ Mark for correctly closing class declaration with a semicolon ; ) NOTE: Marks to be awarded for defining the member functions inside or outside the class (d) Answer the questions (i) to (iv) based on the following: (4) class Faculty { int FCode; protected: char FName[20]; public: Faculty(); void Enter(); void Show(); }; class Programme { int PID; protected: char Title[30]; public: Programme(); void Commence(); void View(); }; class Schedule: public Programme, Faculty { int DD,MM,YYYY; public: Schedule();

void Start(); void View(); }; void main() { Schedule S; //Statement 1 ___________ //Statement 2 } OR Consider the following class State : class State { protected : int tp; public : State( ) { tp=0;} void inctp( ) { tp++;}; int gettp(); { return tp; } }; Write a code in C++ to publically derive another class ‘District’ with the following additional members derived in the public visibility mode. Data Members : Dname string Distance float Population long int Member functions : DINPUT( ) : To enter Dname, Distance and population DOUTPUT( ) : To display the data members on the screen. (i) Write the names of all the member functions, which are directly accessible by the object S of class Schedule as declared in main() function. Ans. Start(), Schedule::View(), Commence(), Programme::View() (1 Mark for writing all correct member names ) NOTE: ● Ignore the mention of Constructors (ii) Write the names of all the members, which are directly accessible by the memberfunction Start( ) of class Schedule. Ans. DD,MM,YYYY, Schedule::View() Title, Commence( ), Programme::View() Fname, Enter(), Show() (1 Mark for writing all correct member names )

(a) Write a user-defined function AddEnd4(int A[][4],int R,int C) in C++ to (2) Ans. find and display the sum of all the values, which are ending with 4 (i.e., unit place is 4). For example if the content of array is: 24 16 14 19 5 4 The output should be 42 OR Write a user defined function in C++ to find the sum of both left and right diagonal elements from a two dimensional array. void AddEnd4(int A[ ][4], int R, int C) { int I,J,sum=0; for(I=0;I<R;I++) { for(J=0;J<C;J++) if(A[I][J]%10 ==4) sum=sum+A[I][J]; } cout<<sum; } OR void Diagsumboth(int A[][4], int n) { int sumLt=0,sumRt=0; for(int i=0;i<n;i++) { sumLt+=A[i][i]; else sumRt+=A[n-1-i][i]; } cout<<”sum of left diagonal”<<sumlt<<endl; cout<<”sum of right diagonal”<<sumRt<<endl; } (½ Mark for correct loops) (½ Mark for correct checking values ending with 4) ( ½ Mark for finding sum of values) ( ½ Mark for displaying the sum ) OR (1/2 Mark for correct loop) (1/2 Mark each for calculating sum of left or right diagonals) (1/2 Mark for displaying)

(b) Write a user-defined function EXTRA_ELE(int A[ ], int B[ ], int N) in C++ (3) to find and display the extra element in Array A. Array A contains all the elements of array B but one more element extra. (Restriction: array elements are not in order) Example If the elements of Array A is 14, 21, 5, 19, 8, 4, 23, 11 and the elements of Array B is 23, 8, 19, 4, 14, 11, 5 Then output will be 21 OR Write a user defined function Reverse(int A[],int n) which accepts an integer array and its size as arguments(parameters) and reverse the array. Example : if the array is 10,20,30,40,50 then reversed array is 50,40,30,20, Ans. void EXTRA_ELE(int A[], int B[],int N) { int i,j,flag=0; for(i=0;i<N;i++) { for(j=0;j<N;j++) { if(A[i]==B[j]) { flag=1; break; } } if(flag==0) cout<<"Extra element"<<A[i]; flag=0; } } OR void Reverse( int A[ ] , int n) { int temp; for(int i=0;i<n/2;i++) { temp=A[i]; A[i]=A[n-1-i]; A[n-1-i]=temp; } } (1 Mark for correct loops) (1 Mark for checking array elements which are equal) ( ½ Mark for display the extra element)

1 Mark for writing correct formula (for column major) OR substituting formula with correct values) (1 Mark for correct step calculations) (1 Mark for final correct address) OR 1 Mark for writing correct formula (for Row major) OR substituting formula with correct values) (1 Mark for correct step calculations) (1 Mark for final correct address) (d) Write the definition of a member function Ins_Player() for a class (4) CQUEUE in C++, to add a Player in a statically allocated circular queue of PLAYERs considering the following code is already written as a part of the program: struct Player { long Pid; char Pname[20]; }; const int size=10; class CQUEUE { Player Ar[size]; int Front, Rear; public: CQUEUE( ) { Front = -1; Rear=-1; } void Ins_Player(); // To add player in a static circular queue void Del_Player(); // To remove player from a static circular queue void Show_Player(); // To display static circular queue }; OR Write a function in C++ to delete a node containing Books information ,from a dynamically allocated stack of Books implemented with the help of the following structure: struct Book { int BNo; char BName[20]; Book *Next; };

Ans. void CQUEUE : : Ins_Player( ) { if((Front==0 && Rear==size-1) || (Front==Rear+1) { cout<< “Overflow”; return; } else if(Rear = = -1) { Front=0; Rear=0; } else if(Rear= =size-1) { Rear=0; } else { Rear++; } cout<< “Enter Player Id=”; cin>>Ar[Rear].Pid; cout<< “Enter Player Name=”; gets(Ar[Rear].Pname); } OR struct Book { int BNo; char BName[20]; Book Next; }temp,*top; void pop() { temp=new Book ; temp=top; top=top->next; delete temp; } (1 Mark for checking if Queue is Full) (1 Mark for checking if Queue is Empty) ( ½ Mark for checking Rear is at size-1) ( ½ Mark for incrementing Rear) ( ½ M ark for assigning Values to the Rear location of the Queue)

Ans. void RevText( ) { ifstream Fin(“Input.txt”); char Word[20]; while(!Fin.eof()) { Fin>>Word; if(Word[0]==’I’) strrev(Word); cout<<Word<< “ ”; } Fin.close( ); } OR int Countalpha() ifstream ifile ("BOOK.txt"); char ch; int count =0; while (! ifile.eof()) { ifile.get(ch); if(isfower(ch)) count ++; } ifile.close(); return (count) } (½ Mark for opening Input.txt correctly) (½ Mark for reading each Word from the file) (½ Mark for checking the word starting with ‘I’ ) (½ Mark for reversing and displaying the word) OR (½ Mark for opening Input.txt correctly) (½ Mark for reading each character from the file) (½ Mark for checking the lower character ) (½ Mark for displaying the count) (b) Write a function in C++ to search and display details, whose destination is (3) “Cochin” from binary file “Bus.Dat”. Assuming the binary file is containing the objects of the following class: class BUS { int Bno; // Bus Number char From[20]; // Bus Starting Point

char To[20]; // Bus Destination public: char * StartFrom ( ); { return From; } char * EndTo( ); { return To; } void input() { cin>>Bno>>; gets(From); get(To); } void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; } }; OR Write a function in C++ to add more new objects at the bottom of a binary file "STUDENT.dat", assuming the binary file is containing the objects of the following class : class STU { int Rno; char Sname[20]; public: void Enter() { cin>>Rno;gets(Sname); } void show() { count << Rno<<sname<<endl; } }; Ans. void Read_File( ) { BUS B; ifstream Fin; Fin.open(“Bus.Dat”, ios::binary); while(Fin.read((char *) &B, sizeof(B))) { if(strcmp(B.EndTo(), “Cochin”)==0) { B.show( ) ; } } Fin.close( ); } OR void Addrecord() { ofstream ofile; ofile.open("STUDENT.dat", ios ::out); STU S; char ch='Y'; while (Ch=='Y' || Ch = = 'y') {

fstream/ ifstream (½ Mark for each correct value of In.tellg()/sizeof(P) as 500 and 73 respectively) OR ( 1 Mark for correct stream) 5 (a) Observe the following table and answer the parts(i) and(ii) accordingly (2) Table:Product Pno Name Qty PurchaseDate 101 Pen 102 12-12- 102 Pencil 201 21-02- 103 Eraser 90 09-08- 109 Sharpener 90 31-08- 113 Clips 900 12-12- (i) Write the names of most appropriate columns, which can be considered as candidate keys. Ans. Candidate Key: Pno, Name (1 Mark for writing correct Candidate Keys) (ii) What is the degree and cardinality of the above table? Ans. Degree: Cardinality: (½ Mark for writing correct value of degree) (½ Mark for writing correct value of cardinality) (b)Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (4+2) (viii), which are based on the tables. TRAINER TID TNAME CITY HIREDATE SALARY 101 SUNAINA MUMBAI 1998-10-15 90000 102 ANAMIKA DELHI 1994-12-24 80000 103 DEEPTI CHANDIGARG 2001-12-21 82000 104 MEENAKSHI DELHI 2002-12-25 78000 105 RICHA MUMBAI 1996-01-12 95000 106 MANIPRABHA CHENNAI 2001-12-12 69000

COURSE

CID CNAME FEES STARTDATE TID

C201 AGDCA 12000 2018-07-02 101

C202 ADCA 15000 2018-07-15 103

C203 DCA 10000 2018-10-01 102

C204 DDTP 9000 2018-09-15 104

C205 DHN 20000 2018-08-01 101

C206 O LEVEL 18000 2018-07-25 105

(i) Display the Trainer Name, City & Salary in descending order of their Hiredate. Ans. SELECT TNAME, CITY, SALARY FROM TRAINER ORDER BY HIREDATE; (½ Mark for SELECT TNAME, CITY, SALARY FROM TRAINER) (½ Mark for ORDER BY HIREDATE) (ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of December 2001. Ans. SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE BETWEEN ‘2001-12-01’ AND ‘2001-12-31’; OR SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE

= ‘2001-12-01’ AND HIREDATE<=‘2001-12-31’; OR SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE LIKE ‘2001-12%’; (½ Mark for SELECT TNAME, CITY FROM TRAINER) (½ Mark for WHERE HIREDATE BETWEEN ‘2001-12-01’ AND ‘2001-12-31’ OR WHERE HIREDATE >= ‘2001-12-01’ AND HIREDATE<=‘2001-12- OR WHERE HIREDATE LIKE ‘2001-12%’ (iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE of all those courses whose FEES is less than or equal to 10000. Ans. SELECT TNAME,HIREDATE,CNAME,STARTDATE FROM TRAINER, COURSE WHERE TRAINER.TID=COURSE.TID AND FEES<=10000;