You are on page 1of 45

Kendriya Vidyalaya Sangathan Lucknow Region

Study Material
Subject : Computer Science Class - XII

Prepared under supervision of


Sh. M.S. Chauhan Astt. Commissioner KVS (LR)

Under Guidance of
Sh. B.K. Gupta Principal Kendriya Vidyalaya No. 3 AFS Chakeri Kanpur
Prepared By Ms. Jayati PGT(Comp. Sc.) KV No. 3 AFS Chakeri, Kanpur Ms. Neetu Saxena PGT(Comp. Sc.) KV Cantt, Kanpur (I Shift)

Mr. Ratnesh Jain PGT(Comp. Sc.) KV Cantt, Kanpur (II Shift) Mr. A. K. Joshi PGT(Comp. Sc.) KV No. 1 AFS Chakeri, Kanpur Ms. Preeti Sharma PGT(Comp. Sc.) KV No.1 Armapur, Kanpur

Index
Unit 1 : Programming in C++ Concept Name Flow Chart of concepts under Unit 1 1.1 C++ Revision Tour 1.2 Object Oriented Programming 1.3 Function overloading 1.4 Classes and objects 1.5 Constructors & Destructors 1.6 Inheritance : Extending Classes 1.7 Data file handling 1.8 Pointers Flow Chart of concepts under Unit 2 2.1 Static representation 2.2 Linked representation Flow Chart of concepts under Unit 3 3.1 Definitions and terms used in DBMS 3.2 Working with DDl Commands 3.3Working with DML commands 3.4 Writing SQL Select command 3.5 Working with aggregate functions Flow Chart of concepts under Unit 4 4.1 Verification of laws of associativity 4.2 Verification of laws using Truth Table 4.3 Working with SOP and POS forms of expressions 4.4 Reducing Boolean Expression 4.5 Design of logic circuits Flow Chart of concepts under Unit 5 5.1 Terminologies in Data Communication 5.2 Use of various transmission medias in data communication 5.3 Bus, Star & Tree topologies & LAN, MAN, WAN 5.4 Setting up a LAN 5.5 Network protocol, Security concepts, Web Server 5.6 Open source terminologies 5.7 Abbreviations Page No. 3-5 6 11 11 13 15 18 21 27 31 32 33 34 35 35 37 37 37 38 39 39 39 39 40 41 42 42 42 43 45 45 45 2

2 : Data Structure 3: Database & SQL

4 : Boolean Algebra

5: Communicati on & Open Source Concepts

Unit 1 : Programming with C++ C++ Revision Tour


Tokens, Fundamental Data types, Variables, Operators, Type Conversion, Header files, Type of errors. Flow of Control: ifelse, switch, for loop, while loop and do while loop. One Dimensional Array and character array: Declaration, Initialization and Access to the array members. User Defined Function: Prototype Declaration, Function Definition, Passing and returning values, calling function: call by value and call by reference. Library Functions: Character and random functions Structure: Definition, variable declaration, access to the members using structure variable, passing structure type variable to function.

Object Oriented Programming


Comparison between Object Oriented Programming and Procedural Programming

Constructors And Destructors Object, Class, Data Abstraction, Inheritance, Data Encapsulation,
Polymorphism, Modularity.

Object Oriented Programming Concepts and their implementation:

Function Overloading Classes And Objects

Constructor and Its Type: Declaration and Definition Constructor Overloading

Define Function Overloading, Declaration and Definition, How Class Specification: Class definition: Visibility modes, Class compiler resolve the call to the overloaded function or Steps Involved method definitions: Inside theDefinition, Characteristics the Class in Finding theDeclaration Calling Overloaded function Destructor: Best Match, and Class Definition, Outside of

Definition, Referencing Class Members, Array as class member. Destructors

Data File Handling


Stream class: Class hierarchy, functions belongs to stream classes, Opening and Closing files, File Modes. Sequential Input/Output with Files: get( ), getline( ) and put( ) functions, and checking end of file using EOF. Reading and Writing Class objects

Inheritance: Extending Classes


File Pointers and Random Access: seekg( ), seekp( ), tellg( ), tellp( ).
Inheritance: Definition, Uses/Advantages, Base and Derived Classes, public and private derivation, visibility/Accessibility of Inherited Base Basic Operations on Binary Files: inheritance, Objects byte class Member in Derived class, Type of Searching, Appending, size.

Inserting, Modifying, Deleting records

Pointers

Pointer Declaration and Initialization


Dynamic allocation Operators: new and delete, creating dynamic array, array pointer, pointer arithmetic.

String Pointer Const Pointer, Structure Pointer, this Pointer

CHAPTER-1

C++ Revision Tour


1. Tokens, Fundamental Data types, Variables, Operators, Expressions and Type Conversion,

Header files, Type of errors.


Q.1. What is an identifier? List the rules of naming an identifier of C++. Q.2. Name the header file, to which following built-in functions belong to: (i) strcpy( ) (ii) gets( ) (iii) abs( ) (iv) isalnum (v) sqrt( ) (vi) write( ) (vii) strcmp( ) (viii) exit( ) Q.3. Name the header file(s) that shall be needed for successful compilation of the following C++ code: void main ( ) { char Text [40]; strcpy (Text, AISSCE); puts (Text); } Q.4. Differentiate between i. Logical and Syntax Error ii. Run Time and Syntax Error Also give suitable example of each. Q.5. Why main function is special? Give two reasons. Q.6. Write two advantages of using include compiler directive. Q.7. What is the difference between type casting and automatic type conversion? Explain with suitable example. Q.8. Given the following code fragment: int ch = 20; cout << ch << ++ ch << ch << \n; i. The output of the code fragment. ii. What is the effect of replacing ++ ch with ch + 1? Q.9. What will be the output of following: void main( ) { int val = 10; cout<< val++ <<val<< ++val; } 2. Flow of Control: ifelse, switch, for loop, while loop and dowhile loop. Q.1. What is wrong with the following while loop: (a) int counter = 1; (b) int counter = 1; while ( counter < 100 ) while ( counter < 100) { cout<<counter << \n; cout<<counter<<\n; counter - -; counter + +; } Q.2. Find the output of the following program: #include <iostream.h> void main( ) { int A = 5, B = 10; for (int I = 1 ; I <= 2 ; I++) { cout<< Line1 << A++ << & << B 2 << endl; cout<< Line2 << ++B<< & << A + 3 << endl; } } 6

Q.3. Find the output of the following program: #include <iostream.h> void main( ) { long Number = 7583241; int First = 0, Second = 0; do { int R = Number%10; if (R %2 = = 0) First += R; else Second += R; Number /= 10; }while(Number > 0); cout<<First Second; } 3. One Dimensional Array and character array: Declaration, Initialization and Access to the

array members.
Q.1. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction. #include <iostream.h> const int Size 5; void main( ) { int Array [Size] ; Array = { 50, 40, 30, 20, 10 } ; for (Ctr = 0 ; Ctr < Size; Ctr++) cout>>Array [Ctr]; } Q.2. Rewrite the following program after removing all the syntax error(s), if any. Underline each correction. i. #include (iostream.h) void main( ) { int X[ ] = { 60,50,30,40}, Y; Count = 4; cin >> Y ; for ( I = Count 1 ; I >= 0, I - -) switch( I ) { case 0 : case 2 : cout<<Y * X [I ] << endl; break; case 1 : case 3 : cout >> Y + X [I] ; } }

#include <iostream.h> Void main ( ) { int P[ ] = {90, 10, 24, 15} : Q, Number = 4 ; Q = 9; For [ int I = Number 1 ; I >= 0, I--] Switch ( I ) { Case 0 : Case 3 : cout >> P [ I ] * Q << endl ; break ; Case 1 : Case 2 : cout << P [ I ] + Q ; } } Q.3. In the following program, find the correct possible output(s) from the options: #include <stdlib.h> #include <iostream.h> void main ( ) { randomize( ); char Area[][10]= {NORTH, SOUTH, EAST, WEST}; int ToGo; for(int I = 0; I <3, I++) { ToGo = random (2) +1; Cout<<Areaa[ToGo]<<:; } } 4. User Defined Function: Prototype Declaration, Function Definition, Passing and returning

ii)

values, calling function: call by value and call by reference.


Q.1. Find the output of the following program: #include <iostream.h> void Changethecontent(int Arr[], int Count) { for (int C = 1;C < Count; C++) Arr[C-1] += Arr[C]; } void main() { int A[] = {3,4,5}, B[]={10,20,30,40}, C[]={900,1200}; Changethecontent(A, 3); Changethecontent(B, 4); Changethecontent(C, 2); for (int L = 0;L < 3;L++) cout<<A[L]<< #; cout<<endl; for (L = 0;L < 4;L++) cout << B[L] << #; cout << endl; for (L = 0;L < 2;L++) cout<<C[L] << #; } 8

Q.2.

Find the output of the following program : 3 #include<iostream.h> void Indirect(int Temp=20) { for (int 1=10; I<=Temp; I+=5) cout<<I<<, ; cout<<endl; } void Direct (int &Num) { Num+=10; Indirect(Num); } void main() { int Number=20; Direct(Number); Indirect(); cout<< Number= <<Number<<endl ; } Write a C++ function SUMFUN( ) having two parameters X (of type double) and n (of type integer) with a result type as double to find the sum of the series given below:
X + X2 X3 Xn + + 3! 5! ( 2n 1)!

Q.3.

Q.4. Q.5.

Write a function called zero_Small( ) that has two integer arguments being passed by reference and sets the smaller of the two numbers to 0. Write the main program to access this function. What is the difference between call by value and call by reference? Give an example in C++ to illustrate both.

5. Library Functions: Character and random functions Q.1. In the following C++ program what is the expected value of Myscore from Options (i) to (iv) given below. Justify your answer.
#include<stdlib.h> #include<iostream.h> void main( ) { randomize(); int Score[] = {25,20,34,56, 72, 63}, Myscore; Myscore = Score[2 + random(2)]; cout<<Myscore<<endl; }

(i) 25 (ii) 34 (iii) 20 (iv) None of the above 9

Q.2. In the following program, if the value of N given by the user is 15, what maximum and minimum values the program could possibly display?
#include <iostream.h> #include <stdlib.h> void main() { int N,Guessme; randomize(); cin>>N; Guessme=random(N)+10; cout<<Guessme<<endl; }

Q.3.

Find the output of the following program: #include <iostream.h> #include <ctype.h> void main() { char Text[ ]= Mind@Work!; for (int I=0; Text[I] != \0; I++) { if ( ! isalpha(Text[I])) Text[I]=*; else if (isupper (Text[I])) Text[I]=Text[I]+1; else Text[i]=Text[I=1]; } cout<<Text; }

6. Structure: Definition, variable declaration, access to the members using structure variable,

passing structure type variable to function


Q.1. Find the output of the following program: #include <iostream.h> struct PLAY { int Score, Bonus;}; void Calculate(PLAY &P, int N=10) { P.Score++; P.Bonus += N; } void main() { PLAY PL={10,15}; Calculate(PL, 5); cout<<PL.Score<<:<<PL.Bonus<<endl; Calculate(PL); 10

cout<<PL.Score<<:<<PL.Bonus<<endl; Calculate(PL,15); cout<<PL.Score<<:<<PL.Bonus<<endl; } Q.2. Give the output of the following program: #include <iostream.h> struct Pixel { int C, R; }; void Display (Pixel P) { cout << Col << P.C << Row << P.R << endl; } void main ( ) { Pixel X={40, 50}, Y, Z; Z = X; X . C += 10 ; Y=Z; Y . C += 10 ; Y . R += 20 ; Z . C -= 15 ; Display ( X ) ; Display ( Y ) ; Display ( Z ) ; }

11

CHAPTER-2 Object Oriented Programming


1. Comparison between Object Oriented Programming and Procedural Programming.
Q.1. Q.2. Q.3. Write two major differences between Object Oriented Programming and Procedural Programming. What is procedural programming paradigm and what are its limitations? Write any two advantages and two disadvantages of Object Oriented Programming.

2. Object Oriented Programming Concepts and their implementation: Object, Class, Data Abstraction, Inheritance, Data Encapsulation, Polymorphism, Modularity.
Q.1. Q.2. Q.3. Q.4. Q.5. Q.6. Q.7. What do you understand by Polymorphism? Give an example in C++ to show its implementation in C++. What do you understand by Data Encapsulation and Data Hiding? What is Inheritance? Give an example in C++ to show its implementation in C++. Illustrate the concept of Inheritance with the help of an example. Encapsulation is one of the major properties of OOP. How is it implemented in C++? Reusability of classes is one of the major properties of OOP. How is it implemented in C++? Define the term Data Hiding in the context of Object Oriented Programming. Give a suitable example using a C++ code to illustrate the same.

CHAPTER-3 Function Overloading


1. Define Function Overloading, Declaration and Definition, How compiler resolve the call to the

overloaded function or Steps Involved in Finding the Best Match, Calling Overloaded function.
Q.1. Q.2. Q.3. What is function overloading? Illustrate the concept of function overloading with the help of an example. What do you understand by function overloading? Give an example illustrating its use in a C++ program.

12

CHAPTER-4

Classes And Objects


1. Class Specification: Class definition: Visibility modes, Class method definitions: Inside the

Class Definition, Outside the Class Definition, Referencing Class Members, Array as class member.
Q.1. Define a class TEST in C++ with following description: Private Members a. TestCode of type integer b. Description of type string c. NoCandidate of type integer d. CenterReqd (number of centers required) of type integer e. A member function CALCNTR() to calculate and return the number of centers as (NoCandidates/100+1) Public Members A function SCHEDULE() to allow user to enter values for TestCode, Description, NoCandidate & call function CALCNTR() to calculate the number of Centres A function DISPTEST() to allow user to view the content of all the data members Define a class Tour in C++ with the description given below : Private Members : TCode of type string NoofAdults of type integer NoofKids of type integer Kilometres of type integer TotalFare of type float Public Members : A constructor to assign initial values as follows : TCode with the word NULL NoofAdults as 0 NoofKids as 0 Kilometres as 0 TotalFare as 0 A function AssignFare ( ) which calculates and assigns the value of the data member TotalFare as follows For each Adult Fare(Rs) For Kilometres 500 >=1000 300 <1000 &>=500 200 <500 For each Kid the above Fare will be 50% of the Fare mentioned in the above table For example : If Kilometres is 850, NoofAdults = 2 and NoofKids = 3 Then TotalFare should be calculated as NumofAdults * 300 + NoofKids * 150 i.e. 2*300 + 3*150=1050 13

Q.2.

A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and Kilometres; and invoke the Assign Fare( ) function. A function ShowTour( ) which displays the content of all the data members for a Tour. Q.3. Define a class named HOUSING in C++ with the following descriptions: Private Members: REG_NO integer (Ranges 10- 1000) NAME Array of characters (String) TYPE Character COST Float Public Members: Function Read_Data() to read an object of HOUSING type. Function Display() to display the details of an object. Function Draw_Nos() to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING. Use random function to generate the registration nos. to match with REG_NO from the array. Q.4. Q.5. Differentiate between private and protected visibility modes in context of Object Oriented Programming using a suitable example illustrating each. What do you understand by visibility modes in class derivations? What are these modes?

14

CHAPTER-5

Constructors And Destructors


1. Constructor and Its Type: Declaration and Definition
Q.1. What is the use of a constructor function in a class? Give a suitable example of a constructor function in a class. Q.2. What do you understand by default constructor and copy constructor functions used in classes? How are these functions different form normal constructors? Q.3. Differentiate between default constructor and copy constructor, give suitable examples of each. Q.4. What is copy constructor? Give an example in C++ to illustrate copy constructor. Q.5. Answer the questions (i) and (ii) after going through the following program: #include <iostream.h> #include<string.h> class Bazar { char Type[20]; char Product[20]; int Qty; float Price; Bazar( ) //Function 1 { strcpy (Type, Electronic); strcpy(Product, Calculator); Qty = 10; Price = 225; } public : void Disp( ) //Function 2 { cout << Type << - << Product << : << Qty << @ << Price << endl; } }; void main( ) { Bazar B ; //Statement 1 B. Disp( ); //Statement 2 } a. Will Statement 1 initialize all the data members for object B with the values given in the Function 1 ? (Yes OR No). Justify your answer suggesting the correction(s) to be made in the above code. (Hint: Based on the characteristics of Constructor declaration) b. What shall be the possible output when the program gets executed? (Assuming, if required the suggested correction(s) are made in the program).

15

Q.6. Answer the questions (a) and (b) after going through the following class: Class Interview { Int Month: Public: Interview(int y) { Month=y;} Interview(Interview & t); }; (a) Create an object, such that it invokes Constructor 1. (b) Write complete definition for Constructor 2.

2. Constructor Overloading
Q.1. Answer the questions (i) and (ii) after going through the following program: class Match { int Time; public: Match() //Function 1 { Time=0; cout<<Match commences<<end1; } void Details() //Function 2 { cout<<Inter Section Basketball Match<<end1; } Match(int Duration) { Time=Duration; cout<<Another Match begins now<<end1; } Match(Match &M) { Time=M.Duration; cout<<Like Previous Match <<end1; } }; i) ii) Q.2. Which category of constructor - Function 4 belongs to and what is the purpose of using it? Write statements that would call the member Functions 1 and 3. What is a copy constructor? What do you understand by constructor overloading? //Function 3

//Function 4

16

3. Destructor: Declaration and Definition , Characteristics of Destructors


Q.1. What is default constructor? How does it differ from destructor? Q.2. Why is a destructor function required in classes? Illustrate with the help of an example. Q.3. Answer the questions (i) and (ii) after going through the following class:
class Science { char Topic[20]; int Weightage; public: Science ( ) //Function 1 { strcpy (Topic, Optics ); Weightage = 30; cout<<Topic Activated; } ~Science( ) //Function 2 { cout<<Topic Deactivated; } };

(i) Name the specific features of class shown by Function 1 and Function 2 in the above example. (ii) How would Function 1 and Function 2 get executed?

17

CHAPTER-6

Inheritance: Extending Classes


1. Inheritance: Definition, Uses/Advantages, Base and Derived Classes, public and private derivation, visibility/Accessibility of Inherited Base class Member in Derived class, Type of inheritance, Objects byte size.
Q.1. Q.2. Q.3. Differentiate between Protected and Private members of a class in context of Inheritance using C++. Define Multilevel and Multiple inheritances in context of Object Oriented Programming. Give suitable example to illustrate the same. Answer the questions (i) to (iv) based on the following code : class Teacher { char TNo[5], TName[20], DeptflO]; int Workload; protected: float Salary; void AssignSal(float); public: Teacher( ) ; void TEntry( ) ; void TDisplay( ); }; class Student { char Admno[10], SName[20], Stream[10]; protected: int Attendance, TotMarks; public: Student( ); void SEntry( ); void SDisplay( ); }; class School : public Student, public Teacher { char SCode[10], SchName[20]; public: School ( ) ; void SchEntry( ); void SchDisplay( ); }; (i) Which type of Inheritance is depicted by the above example ? (ii) Identify the member functiion(s) that cannot be called directly from the objects of class School from the following : TEntry( ) SDisplay( ) SchEntry( ) (iii) Write name of all the member(s) accessible from member functions of class School. 18

(iv) If class School was derived privately from class Teacher and privately from class Student, then, name the member function(s) that could be accessed through Objects of class School. Q.4. Answer the questions (i) to (iv) based on the following: class CUSTOMER { int Cust_no; char Cust_Name[20]; protected: void Register(); public: CUSTOMER(); void Status(); }; class SALESMAN { int Salesman_no; char Salesman_Name[20]; protected: float Salary; public: SALESMAN(); void Enter(); void Show(); }; class SHOP : private CUSTOMER , public SALESMAN { char Voucher_No[10]; char Sales_Date[8]; public: SHOP(); void Sales_Entry(); void Sales_Detail(); }; (i) Write the names of data members which are accessible from objects belonging to class CUSTOMER. (ii) Write the names of all the member functions which are accessible from objects belonging to class SALESMAN. (iii) Write the names of all the members which are accessible from member functions of class SHOP. (iv)How many bytes will be required by an object belonging to class SHOP? Q. 5. Answer the questions (a) to (d) based on the following: class PUBLISHER { class Pub[12]; double Turnover; protected: void Register(); 19

public: PUBLISHER(); void Enter(); void Display(); }; class BRANCH { char CITY[20]; protected: float Employees; public: BRANCH(); void Haveit(); void Giveit(); }; class AUTHOR: private BRANCH, public PUBLISHER { int Acode; char Aname[20]; float Amount; public: AUTHOR(); void Start(); void Show(); a. AUTHOR. b. Write the names of all the member functions which are accessible from objects belonging to class BRANCH. c. Write the names of all the members which are accessible from member functions of class AUTHOR. d. How many bytes will be required by an object belonging to class AUTHOR? }; Write the names of data members, which are accessible from objects belonging to class

20

CHAPTER-7

Data File Handling


1. Stream class: Class hierarchy, functions belongs to stream classes, Opening and Closing files, File Modes.
Q.1. Q.2. Q.3. Q.4. Q.5. Q.6. Write two member functions belonging to fstream class. Differentiate between ifstream class and ofstream class. Name two member functions of ofstream class. Name the stream classes supported by C++ for file input and output. Distinguish between ios::out and ios::app. Read the code given below and answer the question: void main( ) { char ch = A; fstream outFile (data.dat, ios::out); outFile<<ch<<ch; } If the file contains GOOD before execution, what will be the contents of the file after execution of this code?

2. Sequential Input/Output with Files: get( ), getline( ) and put( ) functions, and checking end of file using EOF.
Q.1. Differentiate between getline( ) and getc( ) functions. Q.2. Write a function in C++ to count the number of lowercase alphabets present in a text file NOTES.TXT. Q.3. Write a function in C++ to count the number of lines present in a text file STORY.TXT. Q.4. Write a function in C++ to print the count of the word the as an independent word in a text file STORY.TXT. For example, if the content of the file STORY.TXT is There was a monkey in the zoo. The monkey was very naughty. Then the output of the program should be 2. Hint: Note that in the example, the word is present as a part of word There but this occurrence of the is not counted as it is not independent word. Q.5. Write a function COUNT_TO( ) in C++ to count the presence of a word 'to' in a text file "NOTES.TXT". Example: If the content of the file "NOTES.TXT" is as follows: It is very important to know that smoking is injurious to health. Let us take initiative to stop it. The function COUNT_TO( ) will display the following message: Count of -to- in file : 3 Note. In the above example, 'to' occurring as a part of word stop is not considered. Q.6. Write a function in C++ to count and display the number of lines not starting with alphabet A present in a text file STORY.TXT. Example : If the file STORY.TXT contains the following lines : The rose is red. A girl is playing there. 21

Q.7.

There is a playground. An aeroplane is in the sky. Numbers are not allowed in the password. The function should display the output as 3. Write a C++ program, which reads one line at a time from the disk file TEST.TXT, and displays it to a monitor. Your program has to read all the contents of the file. Assume the length of the line not to exceed 80 characters. You have to include all the header files if required.

Q.3.

Q.4.

3. Reading and Writing Class objects Q.1. Differentiate between functions read( ) and write( ). Q.2. Assuming the class STOCK, write functions in C++ to perform following: i. Write the objects of STOCK to a binary file. ii. Reads the objects of STOCK from binary file and display them on screen: class STOCK { int ITNO; char ITEM[10]; public: void GETIT( ) { cin >>ITNO ; gets(ITEM); } void SHOWIT( ) { cout << ITNO << ~~ <<ITEM<<endl; } }; Assuming the class EMPLOYEE given below, write functions in C++ to perform the following: i. Write the objects of EMPLOYEE to a binary file. ii. Read the objects of EMPLOYEE from binary file and display them on screen. class EMPLOYEE { int ENO; char ENAME[0]; public : void GETIT ( ) { cin >> ENO; gets(ENAME); } void SHOWIT( ) { cout << ENO << ENAME << endl;} }; Assuming the class Computer as follows: Class computer { char chiptype[10]; Int speed; Public: Void getdetails( ) { gets(chiptype); Cin >> speed; } Void showdetails( ) { cout << Chip << chiptype << Speed = << speed; } };
Write a function readfile( ) to read all the records present in an already existing binary file SHIP.DAT and display them on the screen, also count the number of records present in the file.

22

4. File Pointers and Random Access: seekg( ), seekp( ), tellg( ), tellp( ).


Q.1. Observe the program segment given below carefully, and answer the question that follows: class PracFile { intPracno; char PracName[20]; int TimeTaken; int Marks; public: // function to enter PracFile details void EnterPrac( ); // function to display PracFile details void ShowPrac( ): // function to return TimeTaken int RTime() {return TimeTaken;} // function to assign Marks void Assignmarks (int M) { Marks = M;} }; void AllocateMarks( ) { fstream File;
File.open(MARKS.DAT,ios::binary|ios::in|ios::out); PracFile P; int Record = 0; while (File.read(( char*) &P, sizeof(P))) { if(P.RTime()>50) P.Assignmarks(0) else P.Assignmarks(10) ______________ //statement 1 ______________ //statement 2 Record + + ; } File.close(); }

If the function AllocateMarks () is supposed to Allocate Marks for the records in the file MARKS.DAT based on their value of the member TimeTaken. Write C++ statements for the statement 1 and statement 2, where, statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record. Q.2. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required task. #include <fstream.h> class Item { int Ino;char Item[20]; public: 23

//Function to search and display the content from a particular //record number void Search(int ); //Function to modify the content of a particular record number void Modify(int); }; void Item::Search(int RecNo) { fstream File; File.open(STOCK.DAT,ios::binary|ios::in); ______________________ //Statement 1 File.read((char*)this,sizeof(Item)); cout<<Ino<<==><<Item<<endl; File.close(); } void Item::Modify(int RecNo) { fstream File; File.open(STOCK.DAT,ios::binary|ios::in|ios::out); cout>>Ino;cin.getline(Item,20); ______________________ //Statement 2 File.write((char*)this,sizeof(Item)); File.close(); } Observe the program segment carefully and answer the question that follows: class item { int item_no; char item_name[20]; public: void enterDetail( ); void showDetail( ); int getItem_no( ){ return item_no;} }; void modify(item x, int y ) { fstream File; File.open( item.dat, ios::binary | ios::in | ios::out) ; item i; int recordsRead = 0, found = 0; while(!found && File.read((char*) &i , sizeof (i))) { recordsRead++; if(i . getItem_no( ) = = y ) { _________________________//Missing statement File.write((char*) &x , sizeof (x)); found = 1; } } if(! found) cout<<Record for modification does not exist ; 24

.3.

File.close() ; } If the function modify( ) is supposed to modify a record in the file item.dat , which item_no is y, with the values of item x passed as argument, write the appropriate statement for the missing statement using seekp( ) or seekg( ), whichever is needed, in the above code that would write the modified record at its proper place.

5. Basic Operations on Binary Files: Searching, Appending, Inserting, Modifying, Deleting records.
Q.1. Write a function in C++ to search for a BookNo from a binary file BOOK.DAT, assuming the binary file is containing the objects of the following class. class BOOK { int Bno; char Title[20]; public: int RBno(){return Bno;} void Enter(){cin>>Bno;gets(Title);} void Display(){cout<<Bno<<Title<<endl;} }; Given the binary file STUDENT.DAT , containing the records of the following class: class student { int roll_no; char name[20]; float percent; public: void getData( ); void show( ); float returnPercent( ) { return percent; } }; Write a function BELOW75( ) in C++ , that would count and display the records of those students whose score is below 75 percent. Q.3. Given a binary file GAME.DAT, containing records of the following structure type
struct Game { char GameName [20]; char Participant [10] [30]; };

.2.

Write a function in C++ that would read contents from the file GAME.DAT and creates a file named BASKET.DAT copying only those records from GAME.DAT where the game name is Basket Ball Q.4. 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. class STUD { 25

int Rno; char Name[20]; public: void Enter(){cin>>Rno;gets(Name);} void Display(){cout<<Rno<<Name<<endl;} }; void Addnew() { 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; } } Q.5. A file named as STUDENT.DAT contains the student records, i.e. objects of class student. Write the command to open the file to update a student record. ( Use suitable stream class and file mode(s). Q.6. Assuming a binary file BOOK.DAT contains objects belonging to class book, write a user defined function to add more records to the beginning of it. Q.7. Assuming a binary file BOOK.DAT contains ten objects belonging to class book, write a user defined function to add a record as fifth record to this file. After the execution of your code, the file BOOK.DAT should contain eleven records Q.8. A librarian maintains the record of books in a file named as STOCK_BOOK.DAT. Write a function in C++ to delete a record for book_no 10. Observe the program segment carefully and answer the question that follows: class student { int student_no; char student_name[20]; int mark; public: void enterDetails( ) { cin>> student_no >> mark ; gets(student_name); } void showDetail( ); int get_mark( ){ return mark;} }; Assuming a binary file RESULT.DAT contains records belonging to student class, write a user defined function to separate the records having mark (i) Greater than 79 into EXCELLENT.DAT file (ii) Greater than 59 but less than 80 into AVERAGE.DAT file. (iii) Remaining records should be in RESULT.DAT file. 26

.9.

CHAPTER-8 Pointers
1. Pointer Declaration and Initialization
Q.1. Q.2. Distinguish between int * ptr = new int(5); int * ptr = new int[5]; Give the output of the following program: #include<iostream.h> void main( ) { int a =32, *ptr = &a; char ch = A, &cho = ch; cho += a; *ptr += ch; cout << a << << ch << endl; }

2. Dynamic allocation Operators: new and delete, creating dynamic array, array pointer, pointer arithmetic.
Q.1. Find the output of the following program :
#include<iostream.h> void main() { int Numbers[] = {2,4,8,10}; int *ptr = Numbers; for (int C = 0; C<3; C++) { cout<< *ptr << @; ptr++; } cout<<endl; for(C = 0; C<4; C++) { (*ptr)* = 2; --ptr; } for(C = 0; C<4; C++) cout<< Numbers [C]<< #; cout<<endl; }

Q.2.

Find the output of the following program: #include <iostream.h> void main( ) { int x[ ] = { 10, 25, 30, 55, 110}; int * p = x; while (* p< 110) { if (* p % 3 != 0) * p = * p + 1; else * p = * p + 2; p++; 27

} for (int i = 4; i >= 1; i --) { cout << x[i] << *; if ( i % 3 = = 0) cout<<endl; } cout << x[0] * 3 << endl; } Q.3. program): void main( ) { int array [ ]={ 2, 3, 4, 5}; int *arptr = array; int value =*arptr; value = *arptr++; cout << value <<\t; Value = *arptr; Cout << value <<\t; value = * ++arptr;
}

Give the output of the following program (Assuming all required header files are included in the

3. String Pointer:
Q.1. Find the output of the following program: #include <iostream.h> #include <string.h> class state { char *state_name; int size; public: state() { size=0; state_name = new char [size+1]; } state (char *s) { size = strlen(s); state_name = new char[size + 1]; strcpy(state_name, s); } void display( ) { cout<<state_name<<endl; } void Replace (state & a, state & b) { size = a.size + b.size; delete state_name; state_name = new char[size + 1]; strcpy(state_name, a.state_name); 28

strcat(state_name, b.state_name); } }; void main( ) { char * temp = Delhi; state state1 (temp), state2(Mumbai), state3(Nagpur), S1, S2; S1.Replace(state1, state2); S2.Replae(S1, State3); S1.display(); S2.display(); } Q.2. Find the output of the following program: #include<iostream.h> #include<string.h> class country { char *country name; int length; public:. country ( ) {length =0; country_name=new char [length+1];} country (char *s) { length = strlen(s); country_name=new char [length +1]; strcpy (country_name, s); } void display ( ) { cout<< country_name <<endl; } void Replace (country & a, country & b) { length a.length + b.length; delete country_name; country_name=new char [length + 1]; strcpy (country_ name, a.country_name); strcat (country_name, b.country name); } }; void main ( ) { char * temp = India; country country1 (temp), country2 (Nepal), country3 (China), S1,S2; S1.Replace (country1, country2); S2.Replace (S1,country3); S1.display( ); S2.display ( ); }

29

Q.3.

What will be the output of the following program #include<iostream.h> #include<ctype.h> #include<conio.h> #include<string.h> void changestring(char text[], int &counter) { char *ptr = text; int length=strlen(text); for(;counter<length-2;counter+=2,ptr++) { *(ptr+counter) = toupper(*(ptr+counter)); } } void main() { clrscr(); int position = 0; char message[]= Mouse Fun; changestring (Message, position); cout<<message<< @ <<position; }

4. Const Pointer, Structure Pointer, this Pointer:


Q.1. Rewrite the following codes after removing errors, if any, in the following snippet. Explain each error. void main() { const int i = 20; const int * const ptr = &i; (*ptr)++; int j = 15; ptr = &j; } Q.2. Illustrate the use of self referential structures with the help of an example. Q.3. What is this pointer? Give an example to illustrate the use of it in C++.

30

Unit 2 : Data Structure


1. STATIC REPRESENTATION

1.1 Operations on one dimensional arrays (Includes Stack & Queue) (A) Insertion of an element ( B) Deletion of an element ( C) Searching of an element

(D) Sorting of Array

(E) Traversal

(F) Evaluation of a Postfix expression 1.2 Operations on Two Dimensional Arrays

2. LINKED REPRESENTATION

2.1 Insertion of nodes in a Stack & Queue

2.2 Deletion of nodes from Stack & Queue

31

1. STATIC REPRESENTATION

1.1 Operations on one dimensional arrays (Includes Stack & Queue) (A) Insertion of an element Write a function to insert an element in an integer array at the specified location. Write a function to insert an element in a Stack. Write a function to insert an element in a Queue ( B) Deletion of an element (i) Write a function to delete a user given element from an array. (ii) Write a function to perform pop operation in a stack (iii) Write a function to delete an element from a Queue. ( C) Searching of an element

Write a function to search an element using Linear Search Write a function to search an element using Binary Search. (D) Sorting of Array (i) (ii) (iii) Write a function using Bubble sort method Write a function using Selection sort method Write a function using Insertion sort method

(E) Traversal

Write a function to display the content of an Array. Write a function to display the content of a Stack. Write a function to display the contents of a Queue. (F) Evaluation of a Postfix expression

50,40,+,18,14,-, 4,*,+ True,False,AND,Trua,True,NOT,OR,AND 100,40,8,+,20,10,-,+,* 32

1.2 Operations on Two Dimensional Arrays (i) Write a function in c++ which accepts a 2D array of integers, number of rows and number of columns as arguments and assign the elements which are divisible by 3 or 5 into a one dimensional array of integers.
12 24 19 11 3 25 32 5 9 16 45 28 14 31 27 18

If the 2D array is

The resultant 1D arrays is

12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18

Write a function to multiply two matrices Write a function to find Transpose of a Matrix 2. LINKED REPRESENTATION

2.1 Insertion of nodes in a Stack & Queue

1. Write a function to perform a Push operation in a dynamically allocated stack considering the following description struct node { int data; struct node * next; }; 2. Write a function in C++ to perform Insert operation in a dynamically allocated Queue containing names of students. 2.2 Deletion of nodes from Stack & Queue 1. 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; }; 2. Write a insert function in c++ in a dynamically allocated Queue containing Phonno and names of customer. 33

Unit 3 : Database and SQL


1. Definitions and terminologies used in DBMS

2. Working with DDL Commands 2.1 Creation of a database using DDL commands

2.2. Modification in the existing Database

2.3

Deletion of a table or view

3.

Working with DML Commands

3.1 To insert records in a table

3.2 To delete records from a table

3.3

To update records in a table

4.

Writing SQL SELECT command

5. Working with Aggregate functions

34

1. Definitions and terminologies used in DBMS

1. 2. 3. 4.

What do you understand by Degree and Cardinality of a table? What do you understand by Primary Key and Candidate Keys? What is Data Abstraction? What is an Alternate Key? 2. Working with DDL commands Commands

Consider the following tables while working with SQL commands Table : Item No 1 2 3 4 5 6 7 ItemName Computer Printer Scanner Camera Switch UPS Router CostPerItem 60000 15000 18000 21000 8000 5000 25000 Quantity 9 3 1 2 1 5 2 Dateofpurchase 21/5/96 21/5/97 29/8/98 13/10/96 31/10/99 21/5/96 11/1/2000 Warranty 2 4 3 1 2 1 2 Operational 7 2 1 1 1 4 5

Table : Book Book_id Book name C0001 Fast Cook F0001 T0001 T0002 F0002 Table : issued Book_Id T0001 C0001 F0001

Author_name Lata Kapoor William The Tears Hopkins Brain & My First c++ Brooke C++ Brain A.W. works Rossaine Thunderbolts Anna Roberts

Publisher EPB First Publi. FPB TDH First Publ.

Price 355 650 350 350 750

Type Quantity Cookery 5 Fiction Text Text Fiction 20 10 15 50

Quantity Issued 4 5 2

35

2.1

Creation of a database using DDL commands

1. Create table Lab with the following specificationsColumn Name No Itemname CostperItem Quantity Dateofpurchase Warranty Optional Data type Number Varcahr2 Number Number Date Number Varchar2 Size 2 50 7,2 3 2 50 Constraint Primary Key NOT Null

Create a view Bookview which includes the details of Book_id, Author_name, Price. 2.2. Modification in the existing Database Consider the following structure exists. Column Name Data type Book_ id Number Book_name Varcahr2 Price Number Author_name Varchar2 1. Write command to add columns Publisher varchar2 50 Type varcahr2 20 Quantity Number 3 Size 2 50 7,2 80 Constraint Primary Key NOT Null

2. Write commands to change the size of Itemname from 50 to 60. 3. Write command to delete a column warranty from Item table. 2.3 Deletion of a table or view

1.Write command to physically remove itam table 2. Write command to delete Bookview.

36

3.

Working with DML Commands

3.1 To insert records in a table 1. Write commands to insert two records in Item table 2. Write commands to insert records in issued table 3.2 To delete records from a table 1. Write command to delete all the records from item table where warranty is less than 3 years. 2. Write command to delete all the record from issued table. 3. Write command to delete records from Book table where type is Cookery 3.3 To update records in a table

1. Write command to increase the price in book table by 10% 2. Write command to update the publisher name from TDH to TMH 3. Write command to update the value of quantity as 6 in issued table for book_id T001. 4. Writing SQL SELECT command

(a) (b) (c) (d) (e) (f)

To show book name, Author name and price of books of First Pub. Publisher To list the names from books of text type To Display the names and price from books in ascending order of their prices. To display the Book_Id, Book_name and quantity issued for all books which have been issued To show No, Item name , Quantity and warranty where cost per item is less than 20000 To show the details of items whose date of purchase is before 31 october 97.

5. Working with Aggregate functions Give the output of the following a) Select Count(*) from Books b) Select Max(Price) from books where quantity >=15 c) Select book_name, author_name from books where publishers=first publ. d) Select count(distinct publishers) from books where Price>=400 e) Select Min(costperitem) from Item f)Select Sum( Quantity) from item where warranty is more than 3 g) Select count(*) from issued h) Select Avg( costperitem) from Item where Operational=1 37 4. Working with Aggregate functions

Unit 4 : Boolean Algebra


1. Verification of Laws Algebrically

2. Verification of Laws using Truth Table 3. Working with S-O-P and P-O-S forms of expressions 4. To reduce a Boolean Expression

4.1 Algebraic Method

4.2 Using Karnaugh Map

5. Design of circuit using Logic gates

5.1 Basic Logic Gates 5.2 Universal Logic Gates

38

1. Verification of Laws Algebrically

1. 2. 3.

State DeMorgans Laws . Verify one of them State & verify Associative Property State Absorption Laws and verify one of the Laws 2. Verification of Laws using Truth Table

1. 2. 3.

State Distributive Laws and verify same using Truth table State DeMorgans Law and verify one of them using truth table. Verify commutative Properties using Truth Table 3. Working with S-O-P and P-O-S forms of expressions

1.

Write the S-O-P form of the function F(A,B,C) for the given truth table A 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 C 0 1 0 1 0 1 0 1 F 1 1 0 1 0 1 0 0

2.

Write the P-O-S form of the function F(A,B,C) for the given truth table A 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 C 0 1 0 1 0 1 0 1 F 1 1 0 1 0 1 1 0

4. To reduce a Boolean Expression 4.1 Algebraic Method 1. 2. Reduce AB+ (AC) +ABC( AB+C) AB+(A+B)B 39

4.2 Using Karnaugh Map 1. Obtain a simplified form for a Boolean expression F( U,V,W,Z)= (0,1,3,4,5,6,7,9,10,11,13,15) using K-Map 2. Reduce the following Boolean Expression using K- map F(A,B,C,D) = (0,2,4,6,8,10,13,14) 3. Reduce the following Boolean Expression using K-Map: F(U,V,W,Z)= (0,1,2,4,5,6,8,10) 5. Design of circuit using Logic gates

5.1 Basic Logic Gates 1. Write the equivalent Boolean Expression for the following Logic Circuit

U V

2. Design circuit diagram for given expressions i)- XYZ+XYZ+XYZ ii)- (A+B) (A+B) 5.2 Universal Logic Gates

1. 2.

Draw circuit diagram for X(Y+Z) using NAND gates only Represent the Boolean expression (X+Y)(Y+Z)(X+Z) with the help of NOR Gates only

40

UNIT 5 : COMMUNICATION AND OPEN SOURCE CONCEPTS


1. Terminologies in Data Communication

2. uses of various transmission Medias in Data Communication.

3. Bus, star and tree topologies LAN, WAN, MAN 4. Settling Up A LAN Placement of various networking devices in a network, i.e, Switch, gateway, repeater 5. Network protocol, security concepts, web server.

6. Open source terminologies

7. Abbreviations

41

1. Terminologies in Data Communication

1. Define the term Bandwidth. Give unit of Bandwidth. 2. Explain the terms nodes and server 3. Diffrentiate between Circuit switching and Message switching. 4. What do you understand by Data transfer rate? 5. Explain the function of Modem and Switch.

2. Uses of various transmission Medias in Data Communication. 1. Give two advantages ans two disadvantages of Coaxial cables. 2. How is Radiowave transmission different from Microwave transmission ?
3. What is the difference between baseband and broadband transmission? 4. Give the advantages of using optical fibre cables.

3. Bus, star and tree topologies , LAN MAN WAN

1. Give two advantages of star topology as compared to Bus topology . 2. Differentiate between Tree and Bus topologies of Network. 3. What is the difference between LAN and MAN?

42

4. Setting Up A LAN Placement of various networking devices in a network, i.e, Switch, gateway, repeater

1. ABC Carporation has set up its new center at Delhi for its office and web based activities. It has 4 blocks of buildings as shown in the diagram below:

Block A

Block B

Block C

Block D

Center to center distances between various blocks Black A to Block B 50 m Block B to Block C 150 m Block C to Block D 25 m Block A to Block D 170 m Block B to Block D 125 m Block A to Block C 90 m Number of Computers Black A 25 Block B 50 Block C 125 Block D 10 a) b) c) Suggest a cable layout of connections between the blocks. Suggest the most suitable place (i.e. block) to house the server of this organization with a suitable reason. Suggest the placement of the following devices with justification (i) Repeater (ii) Hub/Switch 43

d)

The organization is planning to link its front office situated in the city in a hilly region where cable connection is not feasible, suggest an economic way to connect it with reasonably high speed? 2. A company in Reliance has 4 wings of buildings as shown in the diagram:

W1

W2

Center to center distances between various Buildings: W3 to W1 50m W1 to W2 60m W2 to W4 25m W4 to W3 170m W3 to W2 125m W1 to w4 90m

Number of computers in each of the wing: W1 150 W2 15 W3 15 W4 25 Computers in each wing are networked but wings are not networked. The company has now decided to connect the wings also. i) Suggest a most suitable cable layout & topology of the connection between the wings. ii) The company wants internet accessibility in all the wings. Suggest an economic technology . iii) Suggest the placement of the following devices with justification if the company wants minimized network traffic : 1)Repeater 2) Hub 3) Switch 3. What is the difference between Bridge and Router?\ 4. Discuss the role of Gateway in Networking. 44

W3

W4

5. Network protocol, security concepts, web server.

1. Name different layer of the ISO OSI Model. 2. What is the differences between POP3 and IMAP Mail Server? 3. Name different layer of the ISO OSI Model. 4. Give the advantages and disadvantages of e-mail. 5. What do you understand by uploading and downloading of files? 6. What is the difference between XML and HTML? Write two differences. 7. Differentiate between Hackers and crackers. 8. What kind of security are available to Internet users? 9. What is URL? 10. Discuss about firewall. 6. Open source terminologies

1. 2. 3. 4. 5.

What do you understand by the term Freeware and Shareware? Write a note on Apache server. Write the components of Mozilla software suite. Write down any two applications of PHP. Explain W3C.

7. Abbreviations

1. Give fullforms of the following: A) CDMA B) GSM C) FTP D) SLIP E) TCP/IP F) WLL G) EDGE H) FLOSS I) GNU J) FSF K) POP L) SMTP M) NTP N) IMAP O) PPP P) NFS 45

You might also like