· web vieweach class describes a possibly infinite set of individual objects; each object is...

204
Unit-1 Strategies in C++ Revision tour questions S.N o Type of question Teaching learning strategy 1 Out of the following, find those identifiers, which cannot be used for naming / can be used for naming Variable, Constants or Functions in a C++ program : OR Difference between identifiers and keywords Explanation about the rules of identifiers like - start with an alphabet, do not start with digit... For keywords students can write names of datatypes, class , struct etc. 2 Write the names of those header files, which are required to be included in the code. void main() { float A,Number,Outcome; cin>>A>>Number; Outcome=pow(A,Number); cout<<Outcome<<endl;} Informing the students to go through the libraries chapter in class XI. 3 Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined. Note : Assume all required header files are already being included in the program. Answer sheet should be divided into two parts, one side c++ code with underlining errors and on the other side corrected code 4 Find and write the output of the following C++ program code : 2 and 3 marks -Program starts from main function -Moving of the control from one part of the program to another - Students should write all the variables and their changing values, so that exact answer can be achieved. 5 Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the -Explaining the students about the randomization. -Random number from 0

Upload: phungkhuong

Post on 07-Mar-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Unit-1

Strategies in C++ Revision tour questions

S.No Type of question Teaching learning strategy1 Out of the following, find those identifiers, which

cannot be used for naming / can be used for namingVariable, Constants or Functions in a C++ program : ORDifference between identifiers and keywords

Explanation about the rules of identifiers like - start with an alphabet, do not start with digit...

For keywords students can write names of datatypes, class , struct etc.

2 Write the namesof those header files, which are required to be included in the code.void main(){float A,Number,Outcome;cin>>A>>Number;Outcome=pow(A,Number);cout<<Outcome<<endl;}

Informing the students to go through the libraries chapter in class XI.

3 Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined.Note : Assume all required header files are already being included in the program.

Answer sheet should be divided into two parts, one side c++ code with underlining errors and on the other side corrected code

4 Find and write the output of the following C++ program code :

2 and 3 marks

-Program starts from main function-Moving of the control from one part of the program to another- Students should write all the variables and their changing values, so that exact answer can be achieved.

5 Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable

-Explaining the students about the randomization.-Random number from 0 to n-1-Options can be one or more than one

1. What is the difference between fundamental data types and derived data types? Explain with examples.

Ans. Fundamental data types Derived data typesThese are the data types that are not composed of These are tha data types that are composed ofany other data type. fundamental data types.

There are fivefundamental data types: char, int,These are: array, function, pointer, reference, constant,

float, double and void. class, structure, union and enumeration.Example: int a=10; float b; Example: float marks[50]; Const int a=5;

Page 2: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

2. What is the purpose of a header file in a program?

Header files provide function prototypes, definitions of library functions, declaration of data types and constants used with the library functions.

3. What main integer types are offered by C++?

C++ offered three types of integers : short, int and long. Each comes in both signed and unsigned versions.

4. Explain the usage of following with the help of an example:

(i) constant (ii) reference

(i)constant: The keyword const can be added to the declaration of an object to make that object a constant rather than a variable. Thus, the value of the named constant cannot be altered during the program run. The general form of constant declaration is asfollows: const type name = value. Example: const int a=10;

(ii) reference: A reference is an alternative name for an object. A reference variable provides an alias for a previously defined variable. The general form of declaring a reference variable is: Type &ref-var = var-name;where type is any valid c++ data type, ref-var is the name of reference variable that will point to variable denoted by var-name.Example:int total;int &sum=total; total=100;cout<<"Sum="<<sum<<"\n";cout<<"Total="<<total<<"\n";

5. The data type double is another floating-point type. Then why is it treatedas a distinct data type? The datatype double istreated as a distinct data typebecause it occupies twice as much memory as type float, and stores floating-point numbers with much larger range and precision. It stands for double precision floating-point. It is used when type float is too small or insufficiently precise.

6. What is the function of increment/decrement operators? How many varieties do they come in? How are these two varieties different from one another?

The increment operator, ++ adds 1 to its operand and the decrement operator -- subtract 1 from its operands.The increment/decrement operator comes in two varieties as following:

(i) Prefix version and (ii) Postfix version:Prefix version Postfix version Performs the increment or decrement operation before using the value of the operand.Example: sum = 10; ctr = 5;sum = sum + (++ctr);First uses the value of the operand in evaluating the expression before incrementing or decrementing the operand’s value.

Page 3: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Example: sum = 10; ctr = 5;sum = sum + (ctr++);

7. Find the errors(i) #include<iostream.h>

main(){int x[5],*y,z[5]for(i=0;i<=5;i++){

x[i]=i;z[i]=i+3;y=z;x=y;

}Will encounter a following syntax error(s):The variable ‘i’ is not declared. There should be semicolon after the declaration statement if int x[5]

(ii) #include<iostream.h> void main(){

int x,y; cin>>x; for(x=0;x<5;++x) cout y else cout<<x<<y; }

There is a syntax error in cout statement. (iii) #include<iostream.h>

void main(){ int R;W=90; while W>60{ R=W-50; switch(W) { 20:cout<<"Lower Range"<<endl; 30:cout<<"Middel Range"<<endl; 20:cout<<"Higher Range"<<endl; } } }

Will encounter a following syntax error(s): There should be a ‘,’ between R and W instead of ‘;’ in declaration statement. There should be a parenthesis in ‘while’ statement. There is missing a use of ‘case’ keyword in switch statement.

(iv) Rewrite the following program after removing all the syntax error(s), if any.#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; case1: case 3:cout>>Y+X[I];

}

#include<iostream.h> void main(){

int X[]={60, 50, 30, 40},Y,Count=4; cin>>Y;for(int I=Count-1;I>=0;I--) switch(I)

{ case 0: case 1: case 2:cout<<Y*X[I]<<endl; break;

Page 4: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

case 3:cout<<Y+X[I];break;}

}

8. Write the names of the header files, which is/are essentially required to run/execute the following C++ code: #include<iostream.h> void main(){

char CH,Text[]="+ve Attitude"; for(int I=0;Text[I]!='\0';I++)

if(Text[I]=='')cout<<endl;

else{

CH=toupper(Text[I]);cout<<CH;

} Ctype.h

9. 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;

Line15&8Line211&9Line1679Line212&10

10. Find the output#include<iostream.h>void SwitchOver(int A[],int N,int split){

for(int K=0;K<N;K++) if(K<Split)

A[K]+=K;else

A[K]*=K;}void Display(it A[],int N){ for(int K=0;K<N;K++)

(K%2==0)?cout<<A[K]

Page 5: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

<<"%":cout<<A[K]<<endl;}void main(){

int H[]={30,40,50,20,10,5}; SwitchOver(H,6,3); Display(H,6); }

30%4152%6040%25

11.Thefollowing code is from a game, which generates a set of 4 random numbers. Praful is playing this game, help him to identifythe correct option(s) out of the four choices given below as the possible set of such numbers generated from the program code so that he wins the game. Justify your answer.

#include<iostream.h>#include<stdlib.h> const int LOW=25; void main(){randomize();int POINT=5,Number; for(int I=1;I<=4;I--){Number=LOW+random(POINT);cout<<Number<<":"; POINT--;}}(i) 29:26:25:28: (ii) 24:28:25:26: (iii) 29:26:24:28: (iv) 29:26:25:26:

iv) 29: 26: 25: 26: is correctThe only option that satisfied the values as per the code is option (iv) because when:

I POINTNumber

Minimum Maximum1 5 25 292 4 25 283 3 25 274 2 25 26

OOP’S CONCEPTS

Objects: An object is a runtime entity in the object-oriented programming language.

Ex: Person, Account, Car, Tree, Book, Clock...etc. ,

Each object contains the data and the functions that are operated on the data.For example consider a Student object; it contains the rgdno, name, marks are data of a student object and the operations are display details, calculate the marks….etc. ,

Object Name AccountAttribute 1Attribute 2 …

AccNo AccType Name

Page 6: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

….Attribute n

Balance

Operation 1Operation 2 …. ….Operation n

Deposite() Withdraw() Enquire()

Objects mainly serve for the following purposes:

Understanding of the real world and a practical base for designers. Decomposition of a problem into objects depends on the judgement and

nature of the problem. Every object will have data structures called attributes and behaviour called

operations. Each and every object will have its own identity though its attributes and

operations are same, the objects will never become equal.

Class:A Class is a user defined data type, which is, used to create the objects. Every object is associated with data and functions, which define meaningful operations on that objects.

(OR)

A Class is a group of objects that have the same properties.A Class holds both the data and functions, the internal data of a class is called data member and the functions are called as member functions.Each class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value for each attribute but shows the attributes name and operations with other instances of the class.

The data and functions can be defined in a class as one of the sections such as private, public, protected. Functions defined within a class have a special relationship to the member to the data members and the member functions.

Syntax:-Class <class name>{ private : type <variable name>; //data member type <function name>(); //member function public : type <variable name>; //data member

type <function name>(); //member function protected : type <variable name>; //data member type <function name>(); //member function

};Ex:

Class Account{ private :

int accno,; char name[20],acctype[10];float balance;

public :int i,j;

void deposite(); void withdrae();

Page 7: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

protected :int e; void enquire();

};

Data Encapsulation:-Data encapsulation is a mechanism of combining the data and function into a single unit.

The use of encapsulation is, it avoids undesired side effects of the data members when it is defined out of the class and also protects the intentional misuse of important data, is a good programming practice and it enables the debugging of program’s easily.

It is very important feature in object-oriented programming language. In OOPL the data m embers which are declared with in the class, those members can be used with the objects only.

Data Abstraction:- Creating new data types using encapsulated items is known as data abstraction.

The data types created by the data abstraction process are known as Abstract Data types (ADTs).In C++ an object can also contains some abstract values such as size, weight, quantity….etc.,It is a powerful technique, and its proper usage will result in optimal, more readable, and flexible programs.

Inheritance:- The mechanism of deriving the properties of one class into another class is called as inheritance. The inheritance is used to avoid the redundancy (duplication of data) i.e. it allows the extension and re-uses the existing code without having to rewrite the code.

Parent class Base or Super class

Child class Derived or Sub class

Polymorphism:-

Parent features

Parent features

Operation

(Function)

Data Structure

Page 8: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

The word Polymorphism is derived from the Greek, the meaning is ‘many forms’ i.e. it allows a single me with many forms, means it allows a function or operation to be used for more than one related purse, which re technically different. There are t types of polymorphisms, they are Static and Polymorphisms.

Message Passing:-

The another important features of object oriented programming language is message passing by using this facility we can interact the objects very easily and it is also possible to transfer the information from one object into another object.In normal programming languages, a function is invoked on a piece of data (function-driven communication), where as in an object – oriented language, a message is sent to an object (message driven communication). Hence, normal programming is based on functional abstraction whereas; object oriented programming is based on data abstraction.

In object-oriented programming, the process of programming involves the following steps:

Create classes for defining objects and their behaviours. Define the required objects. Establish communication among objects through message passing.

Communications among the objects occur in the same way as people exchange messages among themselves. The concept of programming, with the message passing model, is an easy way of modelling real-world problems on computers. A message for an object is interpreted as a request for the execution of a function. A suitable function is invoked soon after receiving the message and the desired results are generated within an object.

OBJECT ORIENTED PROGRAMMING CONCEPTS

4 Marks Solved Problems : Q 1) Define a class TAXPAYER in C++ with following description : Private members : Name of type string PanNo of type string Taxabincm (Taxable income) of type float TotTax of type double

A function CompTax( ) to calculate tax according to the following slab: Taxable Income Tax%Up to 160000 0>160000 and <=300000

5

>300000 and <=500000

10

>500000 15Q 2 : Define a class HOTEL in C++ with the following description: Private Members Rno //Data Member to store

Room No Name //Data Member to store

customer Name Tariff //Data Member to store

per day charge

Page 9: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

NOD //Data Member to store Number of days

CALC //A function to calculate and return amount as NOD*Tariff

and if the value of NOD*Tariff is more than 10000 then as1.05*NOD*Tariff

Q 2 : Define a class HOTEL in C++ with the following description: Private Members Rno //Data Member to store

Room No Name //Data Member to store

customer Name Tariff //Data Member to store

per day charge NOD //Data Member to store

Number of days CALC //A function to

calculate and return amount as NOD*Tariff

and if the value of NOD*Tariff is more than 10000 then as1.05*NOD*Tariff

(c) Define a class in C++ with the following description : A data member TrainNumber of type integer.A data member Destination of type stringA data member Distance of type floatA data member Fuel of type floatA member function CALFUEL( ) to calculate the value of Fuel as per the following criteria :Distance Fuel<=1500 250more than 1500 and <=3000 1000more than 3000 2500Public MembersA function FEEDINFO( ) to allow user to enter values for the Train Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel.A function SHOWINFO( ) to allow user to view the content of all the data

members.

Page 10: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Q. What is constructor overloading? Support your answer with example.               For - 2 MarksAns. CONSTRUCTOR OVERLOADING : When more than one constructor appears inside a single class, it is said to be constructor overloading i.e. if we have two or more constructors inside a class, it is said to be an overloaded constructor. For ex.class ABC{ private:int x;float y;public:ABC( )                   //default constructor{ x=5;y=0.0; }ABC(int p, float q) //parameterized constructor{ x=p;y=q; }ABC(ABC &t)      //Copy constructor{ x=t.p;y=t.q; }void INABC( );void OUTABC( ); };Here in the above written example, we see three constructors one after another. Since all of them share the same class name and are different in their type and number of arguments, therefore supports overloading mechanism of OOP. Q. Answer the questions (i) and (ii) after going through the following class :         For - 2 Marks    class BUS    { private:     char Pname[30],TicktNo[20];     float Fare;      public:      BUS( )                                                              //function 1     { strcpy(Pname,”\0”);        strcpy(TicktNo,”\0”);        Fare=0; }      void Details( )                                                   //function 2      { cout<<Pname<<endl<<TicktNo<<endl<<Fare<<endl; }       BUS(char * name, char *tno, float N);           //function 3       BUS(BUS &F);                                              // function 4     };

1. In OOP, what is function 3 referred to as? Also define this function.2. Define function 4 and write about its purpose?

Ans.i) Function 3  is referred to as parameterized constructor. Its definition is as follows:                 BUS(char * name, char *tno, float N)                  { strcpy(Pname,name);                     strcpy(TicktNo,tno);                     Fare=N; }

1. BUS(BUS &F)                   { strcpy(Pname,F.Pname);                     strcpy(TicktNo,F.TicktNo);                     Fare=F.Fare; }

Page 11: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

COPY CONSTRUCTOR : It is used to initialize an instance/object  using the values of another instance/object of same class type. It takes the reference to an object of the same class as an argument.

2. (a) Differentiate between constructor and destructor function in context of classes and objects using C++

(b) Answer the questions (i) and (ii) after going through the following class :Class maths {

char chapter [20]; int Marks [20] public: Maths ( ) { strcpy (chapter, ``geometery’’ Marks =10; cout <<``chapter Intialised ”; } ~Maths ( ) //member Function 2

{ cout<<`` chapter over ”

}};(i) Name the specific features of class shown by member function1 and member

function 2 in above example?(ii) How would Member Function 1 and Member Function 2 get get executed?

Page 12: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Strategies in Inheritance concept

From last three years it has been noticed that the topics like concept of inheritance, forms of

inheritance and asked for mark and topics like Access Specifiers of Derivation, Size of Derived

Class Objects and put up for ¾ Marks.

Concept of Inheritance

Types of Inheritance

Access Specifiers of Derivation

Constructors and Destructors in Derived Classes

Multiple and Multi Level Inheritance, Access Specifiers of Derivation, Size of Derived Class

Objects are to addressed by the students.

Page 13: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

INHERITANCE

Inheritance is one of the most powerful features of C++ language. Inheritance is the process of creating new classes from an existing class. The existing class is known as the base class or super class and the newly created class is called as a derived class or sub class. The derived class inherits all the capabilities of the base class; it can also add some more features to this class.

The main advantage of Inheritance:

Reusability of the code,To increase the reliability of the code,To add some enhancements to the base class

Inheritance is the one of the major concept of OOP’s, because it allows the creation of hierarchical classifications. The real strength of inheritance comes from the ability to define in the derived class additions; replacements of refinements to the features inherited fro the base class.

General Syntax of Inheritance:

class A {

----------};

class B : visibility mode A{

-----------------};

The Derivation of DerivedClass from the BaseClass is indicated by the colon ( : ). The Visibility mode is optional, because the default visibility mode is private. Visibility mode specifies whether the features of the base class are publicly or privately inherited.

Visibility of Inherited Members

Base Class Visiblity

Derived Class Visiblity

Public Derivation ProtectedDerivation Private Derivation

Private Not inherited directly Not inherited directly Not inherited directlyPublic Public Protected Private

Protected Protected Protected Private

Inheritance is classified into the following forms based on the levels of inheritance and interrelation among the classes invoked in the inheritance process:

Single InheritanceMultiple InheritanceMultilevel InheritanceHierarchical InheritanceHybrid InheritanceMultipath Inheritance

Page 14: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Single Inheritance:A class which is derived from one base class single level inheritance.

Base class or Super class

Derived class or Sun class

Here B has the properties of its own and has all the properties of parent class also. Derived class B inherits the data members and member functions, but not the constructor and destructor from its Base class.

Syntax:class sample{

int a, b, c ;public:

void read( ); void print( );};

class integer: accessspecifier sample{

int x, y;public:

void read1( ); void print1( );};

Multiple Inheritance:

A multiple inheritance means a DerivedClass which inherits the features of more than one BaseClasses.BaseClass1 BaseClass2

DerivedClass

Here the derived class has the properties of both Base Classes and has its own properties.

Syntax:

class Sample1{

------------------};

B

A

B

C

A

Page 15: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

class Sample2{

-------------------------};

class Sample3 : visibility mode Sample1,Sample2 {

---------------------------------------};

Multilevel inheritance:The mechanism of deriving a class from another derived class is known as multilevel inheritance .

Grandfather Base class

Father Intermediate Base class

Son Derived class

Here ‘A’ servers as a base class for the derived class ‘B’ this in turn serves as a base class for the derived class ‘C’. The class ‘B’ is known as Intermediate base class since it provides a link for the inheritance between ‘A’ & ‘C’. the chain ABC is known as inheritance path.

Syntax:class A{

----------------------

};

class B: visibility mode A{

---------------};

class C : visibility mode B { -------------

------------};

Hierarchical Inheritance:

A

B

C

Page 16: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Hierarchical inheritance model follows a top down approach by breaking up a complex class into simpler constituent classes. Hierarchical inheritance resembles the multilevel inheritance, in which only one derived class path is taken into consideration.

A super class includes the features that are common to all the subclasses. A subclass is created by inheriting the properties of the base class and adding and so on.

Here ‘A’ is the base class ‘B’ , ‘C’ are the derived classes , ‘D’ ,’E’ are the derived classes of ‘B’ and ‘F’ , ‘ G’ are the derived classes of ‘C’. i.e.,

If one or more classes are derived form one base class is called hierarchical inheritance.

Syntax:class A{

------------------};

class B: visibility mode A{

---------------};

class C : visibility mode A {

-------------------------};

class D: visibility mode B{

---------------

CB

D GE F

A

Page 17: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

}; class E : visibility mode B {

-------------------------};

class F: visibility mode C{

---------------};

class G : visibility mode C {

-------------------------};

Hybrid Inheritance:Deriving a class involves more than one form of inheritance is known as hybrid inheritance.

Syntax:class A{

-------------------------------};

class B: visibility mode A{

-------------------------};

class C {

-------------------------

C

A

B

D

Page 18: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

};class D: visibility mode B, C{

------------------------};

Constructor and inheritance The compiler automatically calls a base class constructor before executing the derived class constructor. The compiler’s default action is to call the default constructor in the base class. You can specify which of several base class constructors should be called during the creation of a derived class object. This is done by specifying the arguments to the selected base class constructor in the definition of the derived class constructor. class Rectangle { private : float length; float width; public: Rectangle () { length = 0; width = 0; } Rectangle (float len, float wid) { length = len; width = wid; } float area() { return length * width ; } }; class Box : public Rectangle { private : float height; public: Box () { height = 0; } Box (float len, float wid, float ht) : Rectangle(len, wid) { height = ht; } float volume() { return area() * height; } }; int main ( ) { Box bx; Box cx(4,8,5); cout<<bx.volume() <<endl; cout<<cx.volume() <<endl; return 0; } output :0 160

Overriding Base Class Functions

A derived class can override a member function of its base class by defining a derived class member function with the same name and parameter list. It is often useful for a derived class to define its own version of a member function inherited from its base class. This may be done to specialize the member function to the needs of the derived class. When this happens, the base class member function is said to be overridden by the derived class.

class mother { public:

Page 19: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

void display () { cout<< "mother: display function\n"; } }; class daughter : public mother { public: void display () { cout<< "daughter: display function\n\n"; } }; int main ( ) { daughter rita; rita.display(); return 0; }

output: daughter: display function

Gaining Access to an Overridden Function It is occasionally useful to be able to call the overridden version. This is done by using the scope resolution operator to specify the class of the overridden member function being accessed. class daughter : public mother { public: void display () { cout<< "daughter: display function\n\n"; mother::display(); } };

output: daughter: display function mother: display function

Virtual Base Class Multipath inheritance may lead to duplication of inherited members from a grandparent base class. This may be avoided by making the common base class a virtual base class. When a class is made a virtual base class, C++ takes necessary care to see that only one copy of that class is inherited. class A { ..... ..... }; class B1 : virtual public A { ..... ..... }; class B2 : virtual public A { ..... ..... }; class C : public B1, public B2 { .....// only one copy of A .....// will be inherited };

INHERITANCE Questions

Question 1 Consider the following declaration and answer the questions given below :class PPP{

int H: protected :

int S;public :

void INPUT (int);void OUT();

};

Page 20: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

class QQQ : private PPP{

int T;protected :

int U;public :

void INDATA(int, int);void OUTDATA();

};class RRR : public QQQ{

int M;public :void DISP( void );

};(i) Name the base class and derived class of the class QQQ. (ii) Name the data member(s) that can be accessed from function DISP(). (iii) Name the member function(s), which can be accessed from the objects of class RRR. (iv)Is the member function OUT() accessible by the object of the class QQQ?

Question 2 Answer the questions (i) to (iv) based on the following:class PUBLISHER{

char Pub[12];double Turnover;

protected:void Register();

public:PUBLISHER();void Enter();void Display();

};class BRANCH{

char CITY[20];protected:

float Employees;public:

BRANCH();void Haveit();void Giveit();

};

class AUTHOR:privateBRANCH,public PUBLISHER{

intAcode; char Aname[20];

float Amount;public:

AUTHOR();void Start();void Show();

Page 21: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

};

i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.ii) Write the names of all the member functions which are accessible from objects belonging to class BRANCH.iii) Write the names of all the members which are accessible from member functions of class AUTHOR.iv) How many bytes will be required by an object belonging to class AUTHOR?

Question 3 Consider the following declarations and answer the question given below : class vehicle{private:

int wheels;protected :

int passenger:public :

void inputdata (int, int);void outputdata();

};class heavyvehicle : protected vehicle{

intdiesel_petrol;protected :int load;

public:void readdata(int, int);void writedata();

};class bus : private heavyvehicle{

char make[20];public :

void fetchdata(char);void displaydata();

};(i) Name the base class and derived class of the class heavy_vehicle.(ii) Name the data member(s) that can be accessed from function displaydataO.(iii) Name the data member's that can be accessed by an object of bus class.(iv) Is the memberfunction outputdata() accessible to the objects of heavy_vehicle class.

Question 4 Answer the questions (i) to (iv) based on the following code :class Drug{

char Category[10];char Date_of_manufacture[10];char Company[20];

public:Drug();void enterdrugdetails();void showdrugdetails{);

};class Tablet : public Drug

Page 22: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{protected:

char tablet_name[30];char Volume_label[20];

public:float Price;Tablet();void entertabletdetails();void showtabletdetails ();

};class PainReliever : public Tablet{

intDosage_units;char Side_effects[20];intUse_within_days;

public:PainReliever();void enterdetails();void showdetails();

};(i) How many bytes will be required by an object of class Drug and an object of class PainReliever respectively ?(ii) Write names of all the data members which are accessible from the object of class PainReliever.(iii) Write names of all the members accessible from member functions of class Tablet.(iv) Write names of all the member functions which are accessible from objects of class PainReliever.

Consider the following C++ code and answer the questions from (i) to (iv):

class University{

long Id;

char City[20];

protected:

char Country[20];

public:

University();

void Register();

void Display();

};class Department: private University{

long DCode[10];

char HOD[20];

protected:

Page 23: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

double Budget;

public:

Department();

void Enter();

void Show();

};class Student: public Department{

long RollNo;

char Name[20];

public:

Student();

void Enroll();

void View();

};(i) Which type of inheritance is shown in the above example?(ii) Write the names of those member functions, which are directly accessed from the objects of class Student.(iii) Write the names of those data members, which can be directly accessible from the member functions of

class Student.(iv) Is it possible to directly call function Display() of class University from an object of class Department?

SOME IMPORTANT QUESTIONS TO REFRESH THE CONCEPT

Q1. Write the reasons behind the introduction of inheritance in OOP.

Ans. The major reasons behind the introduction of inheritance in OOP are:(i) It ensures the closeness with the real world models, (ii) idea of reusability, (iii) transitive nature of inheritance.

Q2. What are the different forms of inheritance?

Ans. The different forms of inheritance are (i) Single Inheritance, (ii) Multiple Inheritance, (iii) Hierarchical Inheritance, (iv) Multilevel Inheritance, (v) Hybrid Inheritance.

Q3. How does the access of inherited members depend upon their access specifiers and the visibility modes of the base class?Ans.

public member in base class public in derived class protected in private in derivedderived class class

Page 24: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

protected member in base protected in derived protected in private in derivedclass class derived class class

private member in base hidden in derived class hidden in derived hidden in derivedclass class class

Q4. Write the different ways of accessibility of base class members.Ans.

Access Specifier Accessible from Accessible from derived Accessible from objectsown class class (Inheritable) outside class

public Yes Yes Yesprotected Yes Yes Noprivate Yes No No

Q5. How is the size of a derived class object calculated?

Ans. The size of a derived class object is equal to the sum of sizes of data members in base class and the derived class.

Q6. In what order are class constructors and class destructors called when a derived class object is created or destroyed?

Ans. When the object of a derived class is created, firstly the constructor of the base class is invoked and then, the constructor of the derived class is invoked.On the other hand, when the object of a derived class is destroyed, firstly the destructor of the derived class is invoked and then, the destructor of the base class is invoked.

Q1. Answer the questions (i) to (iv) based on the following:

class vehicleclass heavyvehicle : protected vehicle{

int wheels; int diesel_petrol;protected: protected:int passenger; int load;public: public:void inputdata( ); void readdata(int, int);void outputdata( ); void writedata( );}; };

class bus : private heavyvehicle{

char make[20];public:void fetchdata( ); void displaydata( );};

i) Write the member(s) that can be accessed from the object of bus. ii) Write the data member(s) that can be accessed from the function displaydata( ). iii) How many bytes are required by an object of bus and heavyvehicle classes respectively? iv) Is the member function outputdata( ) accessible to the objects of the class heavyvehicle?

Ans : (i) fetchdata(), displaydata() (ii) make, load, passanger(iii) for the object of bus – 28 bytes, for the ob ject of heavyvehicle – 8 bytes (iv) NoQ2. Answer the questions (i) to (iv) based on the following:

class ape : private livingbeing class human : public ape

Page 25: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

class livingbeing{ {

int no_of_organs; char race[20];{

int no_of_bones; char habitation[30];char specification[20];

protected: public:int averageage;

int iq_level; void readhuman();public:

public: void showhuman();void read();

void readape(); };void show();

void showape();};

};

Page 26: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(i) Write the members which can be accessed from the member functions of class human.

(ii) Write the members, which can be accessed by an object of class human. (iii) What is the size of an object (in bytes) of class human? (iv) Write the class(es) which objects can access read() declared in livingbeing class.

Ans : (i) race, habitation, iq_level, readhuman(), showhuman(), readape(), showape() (ii) readhuman(), showhuman(), readape(), showape()(iii) 78 bytes (iv) livingbeing

Q3. Answer the questions (i) to (iv) based on the following:

class parent class father : protected parent{ {char name[20]; int daughter;protected: protected:int son; int baby;public: public:void inputdata(); void readdata();void outputdata(); void writedata();}; };

class mother : public father{int child;public:void fetchdata(); void dispdata();};

(i) In case of the class father, what is the base class of father and what is the derived class of father?

(ii) Write the data member(s) that can be accessed from function dispdata(). (iii) Write the member function(s), which can be accessed by an object of mother class. (iv) Is the member function outputdata() accessible to the objects of father class?

Ans : (i) base class of father – parent, derived class of father mother(ii) child, baby, son (iii) fetchdata(), dispdata(), readdata(), writedata( )

Q4. Answer the questions (i) to (iv) based on the following:class person class client : private

person{

{char name[20], address[20];

int resource;protected:

public:int x;

int get_resource();public:

void free_resource();void enter_person();

};void disp_person();};

(iv) No

class doctor : public person{char speciality[20];

public:void input(); void disp();};

Page 27: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(i) What type of inheritance is depicted by the above example? (ii) Write the member functions, which can be called by the object of class client. (iii)What is the size in bytes of the object of class doctor and client respectively? (iv)Write the data members, which can be used by the member functions of the class

doctor. Ans : (i) Hierarchical Inheritance (ii) get_resource(), free_resource()(iii) size of object of class doctor = 62 and client = 44 (iv) speciality, xQ5. Answer the questions (i) to (iv) based on the following:

class author class personclass employee : private author, public person

{ { {

char name[12];char address[20]; int ecode;

double royalty; protected: char dept[30];protected: float salary; public:void register(); public: employee(){};public: person(){}; void start();author(){}; void havelt(); void show();void enter(); void givelt(); };void display();

};};

(i) Write the names of data members, which are accessible from object of class employee. (ii) Write the names of all the member functions which are accessible from object of

class person. (iii) Write the data members which are accessible from member functions of class

employee. (iv) How many bytes are required by an object belonging to class employee?

Ans : (i) Nil (ii) haveit ( ), giveit ( ) (iii) ecode, dept, salary (iv) 76 bytes

Q6. Answer the questions (i) to (iv) based on the following:

class PUBLISHER class BRANCH

{ char Pub[12]; {char CITY[20];

protected:

double Turnover; protected:

void Register();

float Employees;

public:

public:

PUBLISHER();

BRANCH();void Haveit();

void Enter();void Giveit();

};

void Display(); };

class AUTHOR: private BRANCH, public PUBLISHER { int Acode;char Aname[20];float Amount;public:AUTHOR(); void Start(); void Show();};

Page 28: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.

(ii) Write the names of all the members which are accessible from member functions of class AUTHOR.

(iii) How many bytes are required by an object belonging to class AUTHOR? (iv) Write the sequence of the constructors’ invocation when the object of author is created.

Ans: (i) Nil (ii) Acode, Aname, Amount, Employees, Start(), Show(), Haveit(),Giveit(), Register(), Enter(), Display()(iii) 70 bytes (iv) BRANCH(), PUBLISHER(), AUTHOR()

Page 29: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

QUESTIONS AND ANSWERS - CLASS XII C++

1 What are input and output streams? What is the significance of fstream.h file?Ans: Input stream: The stream that supplies data to the program is known as input stream.

Output stream: The stream that receives data from the program is known as output stream.fstream.h file includes the definitions for the stream classes ifstream, ofstream and fstream. In C++ file input outputfacilities implemented through fstream.h header file.

2 Discuss the files stream classes defined inside fstream.h header file.Ans: ifstream: can be used for read operations.

ofstream: can be used for write operations.fstream: can be used for both read & write operations.

3 What are the steps involved in using a file in a C++ program?Ans: In order to process files, follow these steps:

(i) Determine the type of link.(ii) Declare a stream accordingly.(iii) Link file with the stream(iv) Process as required, and(v) De-link the file with the stream.

4 Describe the various classes available for file operations.Ans: Class Functions

filebuf It sets the file buffers to read and write.fstreambase This is the base class for fstream, ifstream and ofstream classes.ifstream It provides input operations for file.ofstream It provides output operations.fstream It provides support for simultaneous input and output operations.

5 Discuss the two methods of opening a file within a C++ program. When is one method preferred over the other?

Ans: A file can be opened in two ways :-a) Using the constructor of the stream class – This method is useful when only one file is used in the stream.Constructors of the stream classes ifstream, ofstream and fstream are used to initialize the file stream object withthe file name. For example,ifstream read_file(“Names.Dat”);b) Using the function open() - This method is useful when we want to use different files in the stream. If two ormore files are to be processed simultaneously, separate streams must be declared for each. For example,ifstream ifl; //input stream ifl createdifl.open(“Names.Dat”); // file Names.Dat linked with iflSecond method is preferred over first method when there is a situation to open more than one file.

6 When a file is opened for output what happens when(i) the mentioned file does not exist.(ii) the mentioned file does exist.

Ans: (i) Creates a new file.(ii) the act of opening a file for output scraps it off so that output starts with a fresh file.

7 Explain how while (filin) statement detects the eof for a file i.e., connected to filin stream.Ans: To detect end of file, without using EOF(), we may check whether the stream object has become NULL or

not. Forexample,while(filin){……}

Page 30: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

The value in filin becomes zero when the end of file is reached, and the loop ends. Since reading occurs inside theloop, there will be no more attempts to read the file.

8 What role is played by file modes in file operations? Describe the various file mode constants and theirmeanings.

Ans: A file mode describes how a file is to be used: read it, write to it, append it, and so on. Different file modesconstants and their meanings are as following:Constant Meaningios::in Opens file for reading.ios::out Opens file for writing.ios::ate This seeks to end-of-file upon opening of the file.ios::app This causes all output to that file to be appended to the end.ios::trunc The contents of a pre-existing file by the same name to be destroyed and truncates the file tozero length.ios::nocreate Causes open() function to fail if the file does not already exist.ios::noreplace Causes open() function to fail if the file already exist.ios::binary Causes a file to be opened in binary mode.

9 Write a code snippet that will create an object called filout for writing, associate it with the filename STRS. Thecode should keep on writing strings to it as long as the user wants.

Ans: #include<iostream.h>#include<stdio.h>#include<conio.h>#include<fstream.h>void main(){char c,fname[10];ofstream filout;filout.open("STRS");cout<<"Enter contents to store in file (Enter # to stop):\n";while((c=getchar())!='#'){filout<<c;}filout.close();getch();}

10 How many file objects would you need to create to manage the following situations? Explain(i) to process three files sequentially(ii) to merge two sorted files into a third file

Ans: i) 3ii) 3

11 Both ios::ate and ios::app place the file pointer at the end of the file when it is opened. What then, is thedifference between them?

Ans: Both ios::ate and ios::app place the file pointer at the end of the file when it is opened. The difference between thetwo is that ios::app lets you add data to the end of the file only, while the ios::ate mode when opened withofstream allows you to write data anywhere in the file, even over old data.

12 What are the advantages of saving data in:(i) binary form (ii) text form

Ans: (i) binary form:

Page 31: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Binary files are faster and easier for a program to read and write than are text files. As long as the file doesn’t need to be read by people or need to be ported to a different type of system, binaryfiles are the best way to store program information.(ii) text form: It can be read by people. It can be ported to a different type of system.

13 When do you think text files should be preferred over binary files?Ans: When file does need to be read by people or need to be ported to a different type of system, text files

should bepreferred over binary files.

14 Write a program that counts the number of characters up to the first $ in input and that leaves the $ in the inputstream.

Ans: #include<fstream.h>#include<stdio.h>#include<iostream.h>void main(){char s[80],ch;int count=0;ifstream file("abc.txt");while(!file.eof()){ file.getline(s,80);for(int i=0;i<80;i++){ if(s[i]=='$')break;count++;}};cout<<count;file.close();}

15 Write a program that reads a text file and creates another file that is identical expect that every sequence ofconsecutive blank space is replaced by a single space.

Ans: #include <fstream.h>#include <iostream.h>#include <ctype.h>#include <conio.h>void main(){char ch;int count=0;ifstream in_stream;ofstream out_stream;clrscr();in_stream.open("A.txt");out_stream.open("B.txt");while (!in_stream.eof()){ch = (char)in_stream.get( );if(isspace(ch))count++;if(count >= 2)

Page 32: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ch=' ';count = 0;}else{out_stream <<ch;}}}

16 Suggest the situation where write() and read() are preferred over get() and put() for file I/O operations. Supportyour answer with examples.

Ans: The get() and put() functions perform I/O byte by byte. On the other hand, read() and write() functions let you readand write structures and objects in one go without creating need for I/O for individual constituent fields.Example:file.get(ch);file.put(ch);file.read((char *)&obj, sizeof(obj));file.write((char *)&obj, sizeof(obj));

17 Discuss the working of good() and bad() functions in file I/O error handling.Ans: good(): Returns nonzero (true) if no error has occurred. For instance, if fin.good() is true, everything is

okay with thestream named as fi and we can proceed to perform I/O operations. When it returns zero, o further operations canbe carried out.bad(): Returns true if a reading or writing operation fails. For example in the case that we try to write to a file that isnot open for writing or if the device where we try to write has no space left.

18 What are the similarities and differences between bad() and fail() functions.Ans: Similarities: bad() and fail() both are error handling functions and return true if a reading or writing

operation fails.Differences: Both bad() and fail() return true if a reading or writing operation fails but fail() also returns true in thecase that a format error happens, like when an alphabetical character is extracted when we are trying to read aninteger number.

19 How is the working of file I/O error handling functions associated with error-status flags?Ans: The error-status flags store the information on the status of a file that is being currently used. The current

state ofthe I/O system is held in an integer, in which the following flags are encoded:Name Meaningeofbit 1 when end-of-file is encountered, 0 otherwise.failbit 1 when non-fatal I/O error has occurred, 0 otherwise.badbit 1 when fatal I/O error has occurred, 0 otherwise.goodbit 0 value

20(A)

Observe the program segment given below carefully, and answer the question that follows:class Book{ int Book_no;char Book_name[20];public://function to enter Book details

Page 33: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

void enterdetails();//function to display Book detailsvoid showdetails();//function to return Book_noit Rbook_no() { return book_no; }};void Modify(Book NEW){ fstream File;File.open("BOOK.DAT",ios::binary|ios::in|ios::out);Book OB;int Recordsread=0,Found=0;while(!Found&&File.read((char*)&OB,sizeof(OB))){ Recordsread++;if(NEW.RBook_no()==OB.RBook_OB()){ _______________ //Missing StatementFile.write((char*)&NEW,sizeof(NEW));Found=1;}ElseFile.write((char*)&OB,sizeof(OB));}if(!Found)cout<<"Record for modification does not exist";File.close();}If the function Modify() is supposed to modify a record in file BOOK.DAT with the values of Book NEW passed toits argument, write the appropriate statement for Missing Statement using seekp() or seekg(), whichever needed,in the above code that would write the modified record at its proper place.

Ans: File.seekg(-1*sizeof(NEW),ios::cur);20(B) int main()

{ char ch='A';fstream fileout("data.dat",ios::out);fileout<<ch;int p=fileour.tellg();cout<<p;return 0;}What is the output if the file content before the execution of the program is the string "ABC"?(Note that " " are not part of the file).

Ans: 120(C) (i) Write a user defined function in C++ to read the content from a text file NOTES.TXT, count and

display thenumber of blank spaces present in it.(ii) Assuming a binary file FUN.DAT is containing objects belonging to a class LAUGHTER (as defined below). Writea user defined function in C++ to add more objects belonging to class LAUGHTER at the bottom of it.class LAUGHTER { int Idno //Identification numberchar Type[5]; //LAUGHTER Typechar Desc[255]; //Descriptionpublic:

Page 34: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

void Newentry(){ cin>>Idno;gets(Type);gets(Desc);}Void Showscreen(){ cout<<Idno<<":"<<Type<<endl<<Desc<<endl;}};

Ans: (i) void countspace(){ifstream fins;fins.open("NOTES.TXT");char ch;int count=0;while(!fins.eof()){fin.get(ch);if(ch==' ')count++;}cout<<"Number of blank spaces"<<count;fin.close();}

21 int main(){ char ch='A';fstream fileout("data.dat",ics::app);fileout<<ch;int p=fileout.tellg();cout<<p;return 0;}What is the output if the file content before the execution of the program is the string "ABC"?(Note that " " are not part of the file).

Ans: 422(a) Observe the program segment given below carefully, and answer the question that follows:

class Labrecord{ int Expno;char Expriment[20];char Checked;int Marks;public://function to enter Expriment detailsvoid EnterExp();//function to display Expriment detailsvoid ShowExp();//fuction to retur Expnochar RChecked() { return Checked; }//fuction to assign Marksvoid Assignmarks(int M){ Marks=M;};};void ModifyMarks()

Page 35: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ fstream File;File.open("Marks.DAT",ios::binary|ios::in|ios::out);Labrecord L;int Rec=0;while(File.read((char*)&L,sizeof(L))){ if(L.RChecked()==’N’)L.Assignmarks(0);elseL.Assignmarks(10);_____________ //statement 1_____________ //statement 2Rec++;}File.close();}If the function ModifyMarks() is supposed to modify Marks for the records in file MARKS.DAT based on theirstatus of the member Checked (containing value either ‘Y’ or ‘N’). Write C++ statements for the statement 1 andstatement 2, where statement 1 is required to position the file write pointer to an appropriate place in the filestatement 2 is to perform the write operation with the modified record.

Ans: Statement 1:File.seekp(-1*sizeof(L),ios::cur);Statement 2:File.write((char*)&L,sizeof(L));

22(b) Write a function in C++ to print the count of the word 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.

Ans: void wordcount(){ifstream fil("STORY.TXT");char word[30]; //assuming longest word can be 29 characters longint count=0;while(!fil.eof()){ cin>>word;if((strcmp("the",word)==0) && (strcmp("The",word)==0));count++;}fil.close();cout<<count;}

22(c) Given a binary file SPORTS.DAT, containing records of the following structure type:struct Sports{ char Event[20];char Participant[10][30];};Write a function in C++ that would read contents from the file SPORTS.DAT and creates a file namedATHLETIC.DAT copying only those records from SPORTS.DAT where the event name is “Athletics”.

Page 36: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans: void copyfile(){ifstream fin;ofstream fout;fin.open("SPORTS.DAT",ios::in|ios::binary);fout.open("ATHELETIC.DAT",ios::out|ios::binary);Sports s1;while(!fin.eof()){ fin.read((char*)&s1,sizeof(s1));if(strcmp(s1.Event,"Athletics")==0)fout.write((char*)&s1,sizeof(s1));}fin.close();fout.close();}

23 Observe the program segment given below carefully and fill the blanks marked as statement 1 and Statement 2using tellg() and seekp() functions for performing the required task.#include<fstream.h>class Customer{long Cno;char Name[20],Mobile[12];public://function to allow user to enter the Cno, Name, Mobilevoid Enter();//function to allow user to enter (modify) mobile numbervoid Modify();//function to return value of Cnolong GetCno() { return Cno;}};void ChangeMobile(){Customer C;fstream F;F.open(“CONTACT.DAT”,ios::binary|ios::in|ios::out);long Cnoc; //customer no. whose mobile number needs to be changedcin>>Cnoc;while(F.read((char*)&C,sizeof(c))){If(Cnoc==C.GetCno()){C.Modify();//statement 1Int Pos= ______________ //to find the current position//of file pointer// statement 2______________ //to move the file pointer to write the//modified the record back on to the file//for the desired CnocF.write((char*)&C,sizeof(c));}}

Page 37: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

File.close();}

Ans: Statement 1:F.tellg() ;Statement 2:F.seekp(Pos-sizeof(C));ORF.seekp(-l*sizeof(C) ,ios::cur);

24 Write a function in C++ to count the words to and the present in a text file “POEM.TXT”.[Note. that the words “to’ and “the” are complete words.]

Ans: void COUNT (){ifstream File;File. open (POEM.TXT);char Word[80] ;int Cl = 0, C2 = 0;while(!File.eof()){File>>Word;if (strcmp (Word, to) ==0)Cl++;else if (strcmp (Word, the) ==0)C2++;}cout<<”Count of -to- in file:" <<Cl;cout<<”Count of -the- in file:”<<C2;File.close(); //Ignore}

25 Write a function in C++ to search and display details. of all trains, whose destination is “Delhi” from a binary file“TRAIN.DAT”. Assuming the binary file is containing the objects of the following class.class TRAIN{int Tno; // Train Numberchar From[20]; // Train Starting Pointchar To[20]; // Train Destinationpublic:char* GetFrom (){return From;}char* GetTo (){return To;}void Input () {cin>>Tno;gets(From);gets(To);}void Show () {cout<<Tno<<:<<From<<:<<To<<endl;}};

Ans: void Read ( ){TRAIN T;ifstream fin;fin. open (TRAIN.DAT, ios::binary);while(fin.read((char*)&T, sizeof(T))){if(strcmp(T.GetTo() ,Delhi)==O)T.Show() ;}fin.close(); //Ignore

Page 38: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

}26 Observe the program segment given below carefully, and answer the question that follows:

class Candidate{ long CId; //Candidate's Idchar CName[20]; //Candidate's Namefloat Marks; //Candidate's Markspublic:void Enter();void Display();void MarksChange();//Funcion to change markslong R_CId() { return CId; }};void MarksUpdate(log ID){ fstream File;File.open("CANDIDATE.DAT",ios::binary|ios::in|ios::out);Candidate C;int Record=0,Found=0;while(!Found&&File.read((char*)&C,sizeof(C))){ if(Id==C.R_CId()){ cout<<"Enter new Marks";C.MarkChange();______________ //Statement 1______________ //statement 2Found=1;}Record++;}if(found==1) cout<<"Recoed Updated";File.close();}Write the statement 1 to position the File Pointer at the beginning of the Record for which the Candidate's Idmatches with the argument passed, ad statement 2 to write the updated Recode at that position.

Ans: Statement 1:File.seekg()-1*sizeof(C),ios::cur);Statement 2:File.write((char*)&C,sizeof(C));

27 Write a function in C++ to count the number of uppercase alphabets present in a text file “ARTICLE.TXT”.

Ans: int countupcase(){ifstream fin("ARTICLE.TXT");int count=0;char ch;while(!fin.eof()){ fin>>ch;if(isupper(ch))count++;}fin.close();return count;}

28 Given a binary file TELEPHON.DAT, containing records of the following class Directory:

Page 39: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

class Directory{ char Name[20];char Address[30];char AreaCode[5];char Phone_No[15];public:void Register();void Show();int CheckCode(char AC[]){ return strcmp(AreaCode,AC); }};Write a function COPYABC() in C++, that would copy all those records having AreaCode as “123” fromTELEPHONE.DAT to TELEBACK.DAT.

Ans: void COPYABC(){ifstream fin("TELEPHON.DAT",ios::in|ios::binary);ofstream fout("TELEBACK.DAT",ios::out|ios::binary);Directory ph;while(!fin.eof()){ fin.read((char*)&ph,sizeof(ph));if(ph.checkcode("123")==0)fout.write((char*)&ph,sizeof(ph));}fin.close();fout.close();}

29 Observe the program segment given below carefully, and answer the question that follows:class Team{ long TId[10]; //Team's Idchar TName[20]; //Team's Namefloat Points; //Team's Pointspublic:void Accept();void Show();void PointChange(); //Function to change Pointslong R_TId() {return TId; }};void ReplacePoints(long Id){ fstream File;File.open("TEAM.DAT",ios::binary|ios::in|ios::out);Team T;int Record=0;Found=0;while(!Found && File.read((char*)&T,sizeof(T))){if(Id==T.R_TId()){ cout<<"Enter new Points";T.PointsChange();________________ //Statement 1________________ //Statement 1Found=1;}Record++;}

Page 40: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

if(found==1)cout<<"Record Updated";File.close();}Write the statement 1 to position the File Pointer at the beginning of the Record for which the Team's Id matcheswith the argument passed, ad statement 2 to write the updated Recode at that position.

Ans: Statement 1:File.seekg()-1*sizeof(T),ios::cur);Statement 2:File.write((char*)&T,sizeof(T));

30 Write a function in C++ to count the number of digits present in a text file “PARA.TXT”.Ans: void countdigit(){

ifstream fil("PARA.TXT”,ios::in);int count=0;char ch=fil.get();while(!fil.eof()){ if(isdigit(ch))count++;ch=fil.get();}cout<<"no of digit: "<<count<<endl;}

31 Given a binary file CONSUMER.DAT, containing records of the following structure typeclass Consumer{ char C_Name[20];char C_Address[30];char Area[25];char C_Phone_No[15];public:void Ledger();void Disp();int checkCode(char AC[]){ return strcmp(Area,AC); }};Write a function COPYAREA() in C++, that would copy all those records having Area as “SOUTH” fromCONSUMER.DAT to BACKUP.DAT.

Ans: void COPYAREA(){ifstream fin("CONSUMER.DAT",ios::in|ios::binary);ofstream fout("BACKUP.DAT",ios::out|ios::binary);Consumer c;while(!fin.eof()){ fin.read((char*)&c,sizeof(c));if(c.checkcode("SOUTH")==0)fout.write((char*)&c,sizeof(c));}fin.close();fout.close();}

32 Observe the program segment given below carefully, and answer the question that follows:class PracFile{ int Pracno;

Page 41: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

char PracName[20];char TimeTaken;int Marks;public://function to enter PracFile detailsvoid EnterPrac();//function to display PracFile detailsvoid ShowPrac();//function to return TimeTakenchar RTime() { return TimeTaken; }//fuction to assign Marksvoid Assignmarks(int M){ Marks=M;};};void AllocateMarks(){ fstream File;File.open("MARKS.DAT",ios::in|ios::out);PracFile P;int Record=0;while(File.read((char*)&P,sizeof(P))){ if(P.RTime()>50)P.Assignmarks(0);elseP.Assignmarks(10);_____________ //statement 1_____________ //statement 2Record++;}File.close();}If the function AllocateMarks() is supposed to Allocate Marks for the records in file MARKS.DAT based on theirvalue of member TimeTaken. Write C++ statements for the statement 1 and statement 2, where statement 1 isrequired to position the file write pointer to an appropriate place in the file statement 2 is to perform the writeoperation with the modified record.

Ans: Statement 1: File.seekp((Record)*sizeof(P));ORFile.seekp(-1*sizeof(P),ios::cur);Statement 2: File.write((char*)&P,sizeof(P));

33 Write a function in C++ to print the count of the word is an independent word in a text file DIALOGUE.TXT.For example, if the content of the file DIALOGUE.TXT is:This is his book. Is this good?Then the output of the program should be 2.

Ans: void wordcount{ ifstream fin("DIALOGUE.TXT");char word[10];int wc=0;while(!fin.eof()){ fin>>word;

Page 42: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

if((strcmp(word,"Is")==0)||(strcmp(word,"is")==0))wc++;}cout<<wc;fin.close();}

34 Given a binary file GAME.DAT, containing records of the following structure typestruct Game{ char GameName[20];char Participant[10][30];};Write a function in C++ that would read contents from the file GAME.DAT and creates a file named BASKET.DATcopying only those records from GAME.DAT where the event name is “Basket Ball”.

Ans: void CreateNewFile(){Game g1;ifstream fin;ofstream fout;fin.open("GAME.DAT",ios::in|ios::binary);fout.open("BASKET.DAT",ios::out|ios::binary);while(!fin.eof()){ fin.read((char*)&g1,sizeof(g1));if(strcmp(g1.GameName,"Basket Ball")==0)fout.write((char*)&g1.sizeof(g1));}fin.close();fout.close();}

35 A file contains a list of telephone numbers in the following form:Arvind 7258031Sachin 7259197Karma 5119812The names contain only one word the names and telephone numbers are separated by white spaces. Writeprogram to read a file and display its contents in two columns.

Ans: #include<fstream.h>#include<conio.h>void main(){ifstream fin;fin.open("telephone.txt");char ch;while(!fin.eof()){fin.get(ch);cout<<ch;}fin.close();getch();}

36 Write a program that will create a data file similar to the one mentioned in question 1 (type C). Use a class objectto store each set of data.

Ans: Try to solve this problem.

Page 43: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

37 Write a program that copies one file to another. Has the program to take the file names from the users? Has theprogram to refuse copy if there already is a file having the target name?

Ans: #include<iostream.h>#include<conio.h>#include<fstream.h>#include<stdlib.h>void main(){ofstream outfile;ifstream infile;char fname1[10],fname2[20];char ch,uch;clrscr( );cout<<"Enter a file name to be copied ";cin>> fname1;cout<<"Enter new file name";cin>>fname2;infile.open(fname1);if( infile.fail( ) ){cout<< " No such a file Exit";getch();exit(1);}outfile.open(fname2,ios::noreplace);if(outfile.fail()){cout<<"File Already Exist";getch();exit(1);}else{while(!infile.eof( )){ch = (char)infile.get( );outfile.put(ch);}}infile.close( );outfile.close( );getch( );}

38 Write a program that appends the contents of one file to another. Have the program take the filenames from theuser.

Ans: #include<iostream.h>#include<conio.h>#include<fstream.h>#include<stdlib.h>void main(){ofstream outfile;ifstream infile;

Page 44: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

char fname1[10],fname2[20];char ch,uch;clrscr( );cout<<"Enter a file name from where to append ";cin>> fname1;cout<<"Enter the file name where to append";cin>>fname2;infile.open(fname1);if( infile.fail()){cout<< " No such a file Exit";getch();exit(1);}outfile.open(fname2,ios::app);while( !infile.eof()){ch = (char)infile.get();outfile.put(ch);}infile.close( );outfile.close( );getch( );}

39 Write a program that reads character from the keyboard one by one. All lower case characters get store insidethe file LOWER, all upper case characters get stored inside the file UPPER and all other characters get storedinside OTHERS.

Ans: #include<iostream.h>#include <ctype.h>#include<conio.h>#include <stdio.h>#include<fstream.h>void main(){char c,fname[10];ofstream filout1,filout2,filout3;filout1.open("UPPER.txt");filout2.open("LOWER.txt");filout3.open("OTHER.txt");cout<<"Enter contents to store in file (Enter # to stop):\n";while((c=getchar())!='#'){if(isupper(c)){filout1<<c;}else if(islower(c)){filout2<<c;}else{

Page 45: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

filout3<<c;}}filout1.close();filout2.close();filout3.close();getch();}

40 Write a program to search the name and address of person having age more than 30 in the data list of persons.

Ans: Assuming the file “employee.dat” is already existing in binary format.#include<iostream.h>#include<conio.h>#include <stdio.h>#include<fstream.h>class employee{char name[20];char address[20];int age;public:void showdata(){cout<<"\nEmployee Name : ";puts(name);cout<<"\nEmployee Address : ";puts( address);}int retage(){return age;}};void search (){employee emp;ifstream ifs;ifs.open("employee.dat",ios::binary);while(ifs.read((char*)&emp,sizeof(emp))){if(emp.retage()>30)emp.showdata();}ifs.close();}void main(){clrscr();search();getch();}

41 Write a program to maintain bank account using two files:(i) Master (accno, ac-holder’s name, balance)(ii) Transaction (accno, transactiondate, fromtype, amt)The trantype can either be‘d’ for Deposit or ‘w’ for Withdraw, Amt stores the amount deposited or withdrawn.

Page 46: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

For each transaction the corresponding record in Master file should get updated.Ans: Try to solve this problem.42 Write a function in C++ to count and display the number of lines starting with alphabet ‘A’ present

in a text file“LINES.TXT”.Example: If the file “LINES.TXT” contains the following lines:A boy is playing there.There is a playground.An aeroplane is in the sky.Alphabets and numbers are allowed in the password.The function should display the output as 3.

Ans: void countAlines(){ifstream fin("LINES.TXT");char str[80];int c=0;while(!fin.eof()){ fin.getline(str,80);if(str[0]=='a'||str[0]=='A')c++;}fin.close();cout<<"Total lines starting with a/a are: "<<c<<endl;}

43 Given a binary file STUDENT.DAT, containing records of the following class Student typeclass Student{ char S_Admno[10]; //Admissio number of studentchar S_Name[30]; //Name of studentint Percentage; // Marks Percentage of studentpublic: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 ReturnPercentage(){ return Percentage; }};Write a function in C++, that would read contents of file STUDENT.DAT and display the details of those Studentswhose Percentage is above 75.

Ans: void Dispmore75(){ifstream fin;fin.open("STUDENT.DAT",ios::in|ios::out|ios::binary);Student A;while(!fin.eof()){ fin.read((char*)&A,sizeof(A));if(A.ReturnPercentage()>75)A.DisplayData();}fin.close();

Page 47: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

}44 Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line

2 using fstreamfunctions for performing the required task.#include<fstream.h>class Stock{long Ino; // Item Numberchar Item[20]; // Item Nameint Qty; // Quantitypublic:void Get(int);Get(int);// Function to enter the contentvoid Show( ); // Function to display the contentvoid Purchase(int Tqty){Qty+ = Tqty; // Function to increment in Qty}long KnowIno( ){ return Ino;}};void Purchaseitem(long PINo, int PQty)// PINo -> Info of the item purchased// PQty -> Number of items purchased{fstream File;File.open(“ITEMS.DAT”,ios::binary|ios::in|ios::cut); int Pos=-1;Stock S;while (Pos== -1 && File.read((char*)&S, sizeof(S)))if (S.KnowInc( ) == PINo){S.Purchase(PQty); // To update the number of itemsPos = File.tellg()- sizeof(S);//Line 1 : To place the file pointer to the required position______________________________________;//Line 2 : To write the objects on the binary file______________________________________;}if (Pos == -1)cout<<“No updation done as required Ino not found...”;File.close( );}

Ans: Line 1:File.seekp(Pos);Line 2:File.write((char*) &S, sizeof(S));

45 Write a function COUNT_DO( ) in C++ to count the presence of a word „do‟ in a text file “MEMO.TXT”.Example : If the content of the file “MEMO.TXT” is as follows:I will do it, if yourequest me to do it.It would have been done much earlier.The function COUNT_DO( ) will display the following message:Count of -do- in file: 2

Page 48: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans: void COUNT_TO( ){ifstream Fi1(“MEMO.TXT”);char STR[10];int c=0;while(Fi1.getline(STR,10,’ ‘)){if (strcmpi(STR, “do”) = = 0)C++;}Fi1.close( );cout<<“Count to -do- in file: “<<c<<endl;}

46 Write a function in C++ to read and display the detail of all the users whose status is ‘A’ (i.e. Active) from abinary file “USER.DAT”. Assuming the binary file “USER.DAT” is containing objects of class USER, which isdefined as follows:class USER{int Uid; // User Idchar Uname[20]; // User Namechar Status; // User Type: A Active I Inactive public:public:void Register( ); // Function to enter the contentvoid show( ); // Function to display all data memberschar Getstatus( ){ return Status; }};

Ans: void DisplayActive( ) {USER U;ifstream fin;fin.open(“USER.DAT”, ios:: binary);while (fin.read( ( char*) &U, sizeof(U))){if (U.Getstatus( ) = = ‘A’)U.show( );}fin.close( ); // Ignore}

47 Observe the program segment given below carefully and fill the blanks marked as statement 1 and statement 2using seekg(), seekp(), tellp(), and tellg() functions for performing the required task.#include<fstream.h>class PRODUCT{int Pno;char Pname[20];int Qty;public:void ModifyQty(); //the function is to modify quantity of a PRODUCT};void PRODUCT::ModifyQty(){fstream File;File.open(“PRODUCT.DAT”,ios::binary|ios::in|ios::out);

Page 49: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

int MPno;cout<<”product no to modify quantity:”;cin>>MPno;while(File.read((char*)this,sizeof(PRODUCT))){if(MPno==Pno){cout<<”present quantity:”<<Qty<<endl;cout<<”changed quantity:”;cin>>Qty;int Position= ; //statement 1; //statement 2File.write((char*)this,sizeof(PRODUCT)); //Re-writing the record}}File.close();}

Ans: Statement 1:int Position=File.tellg( );Statement 2:File.seekp(Position-sizeof(PRODUCT),ios::beg);

48 Write a function in C++ to count the no of “Me” or “My” words present in a text file “DIARY.TXT”.If the file “DIARY.TXT” content is as follows:My first book was Me and My family. It gave me chance to be known the world.The output of the function should beCount of Me/My in file : 4

Ans: void COUNT( ){ifstream Fil("DIARY. TXT");char STR[10];int count = 0;while(!Fil.eof( )){Fil>>STR;if(strcmp(STR,"Me")==0||strcmp(STR,"My")==0)count++;}Cout<<"Count of Me/My in file :"<<count<<end1;Fil.close( ); //Ignore

49 Write a function in C++ to search for a laptop from a binary file “LAPTOP.DAT” containing the objects of classLAPTOP (as defined below). The user should enter the Model No and the function should search and display thedetails of the laptop.class LAPTOP{long ModelNo;float RAM,HDD;char Details[120];public:void StockEnter(){ cin>>Modelno>>RAM>>HDD;gets(Details);}

Page 50: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

void StockDisplay(){ cout<<ModelNo<<RAM<<HDD<<Details<<endl;}long ReturnModelNo(){ return ModelNo; }};

Ans: void Search( ){LAPTOP L;long modelnum;cin>>modelnum;ifstream fin;fin.open("LAPTOP.DAT",ios::binary|ios::in);while(fin.read((char*)&L,sizeof(L))){if(L.ReturnModelNo( )==modelnum)L.StockDisplay( );}fin.close(); //Ignore}

Unit-2

DATA STRUCTURES

1. ARRAYS From this topic the questions are like passing array as function arguments, operations on 1-D

and 2-D, 2-D address calculation are asked for 2/3 marks. STRATEGY :

i. From 1-D array learn Sorting(Selection, Bubble, Insertion) and Searching (Linear, Binary) and traversal methods.

ii. From 2-D, learn traversing technique, matrix multiplication, addition, diagonal sum.2. LINKED LIST AND STACK

From this topic the questions like Infix to postfix conversion and vice versa for 2 marks, evaluation of postfix expression for 2 marks.

Program for implementation of dynamic stack or static stack for 4 marks.3. QUEUE

From this topic there will be a question for 4 marks regarding either lined or array implementation of queue, circular queue

STRATEGY :i. Static and Learn Dynamic Stack(Push, Pop), static and Dynamic Queue (Insert, Delete),

infix to postfix or postfix to infix conversion, evaluation.

Arrays - 3 (a) and 3 (d) questions are pertaining to 1-D and 2-D Arrays of 2 Marks / 3 Marks .

Preparation Strategy

Page 51: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

This chapter is quite aggregative from the view point of upcoming board exams. Topics like passing Array as function arguments, operations on 1-D and 2-D Arrays. 2-D Array Address Calculation are asked for 2/3 marks.

1) Concept of Array2) Address calculation of 2-D Arrays3) Passing Array as Function Arguments.

Passing Array as Function arguments, operation on Array, Array element address calculation are to be addressed by the students.

Tips for scoring minimum marks are as follows

1 D Arrays 2 mark question

Write a function in C++, which accepts an integer array and its size as arguments and replaces elements having odd values with thrice its value and elements having even values with twice its value. Example: if an array of nine elements initially contains the elements as 3, 4, 5, 16, 9 then the function should rearrange the array as 9, 8, 15, 32, 27void RearrangeArray(int A[], int size) { }½ mark for the above code

void RearrangeArray(int A[],int size) {for(int i=0;i<size;i++){} }1 mark for the above codeFor the complete code 2 marks.

2 D Arrays 3 mark question• Write a function in C++ to print the product of each column of a two dimensional integer array passed as

the argument of the function.• Ex: if the two dimensional array contains

1 2 43 5 64 3 22 1 5

Page 52: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Then the output should appear as:Product of Column 1 = 24Product of Column 2 = 30Product of Column 3 = 240

void ColProd(int A[4][3],int r, int c){}

½ mark for the above code

void ColProd(int A[4][3],int r,int c){ for(int i=0;i<r;i++){ for(j=0;j<c;j++){}}}

1 ½ mark for the above code3 marks for the complete code .

SOLVED QUESTIONS: 1 Differentiate between one-dimensional and two-dimensional arrays.Ans. One-dimensional array Two-dimensional array

1. A one-dimensional array is a group of elementshaving same data type and same name.A two-dimensional array is an array in which eachelement is itself a 1-D array.There is no rows and columns in one-dimensionalarray.There is a concept of rows and columns in two dimensional array.Syntax: datatype Arrayname[size]; Example: int A[10];Syntax: datatype Arrayname[rowsize][col-size];Example: int A[10]; Example: int A[10][5];

2 Write a user-define function Upper-half() which takes a two dimensional array A, with N rows and N columns as argument and point the upper half of the array.e.g., If A is2 3 1 5 07 1 5 3 12 5 7 8 10 1 5 0 13 4 9 1 5The output will be2 3 1 5 01 5 3 1

Page 53: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

7 8 10 15

Ans Void Upper-half(int b[][10],int N){ int i,j;for(i=N;i>0;i--){ for(j=N;j>0;j--){ if(i>=j)cout<<b[i][j]<<" ";elsecout<<" ";}cout<<"\n";}}

3 Suppose an array A[10] stores numeric values only. Write algorithms to(i) calculate the average of the values in A(ii) print the even numbers stored in A.

Ans (i) calculate the average of the values in A1. Start2. read A[i]3. let i=0,sum=0,avg=04. add A[i] into sum and store it into sum5. divide sum by 10 and store it in avg6. check whether i is less than 10 if yes than increment i by 17. print avg8. End

(ii) print the even numbers stored in A.1. Start2. read A[i]3. let i=04. check whether A[i]%2 is equal to 05. if yes than print A[i]6. check whether i is less than 10 if yes than increment i by 17. End

4 What are data structures? What are their types and sub-types? Explain each of the subtypes with examples.

Ans The data structures are named group of data of some data types. The data structures can be classified intofollowing two types:1. Simple Data Structure: These data structure are normally built from primitive data types like integers, reals,characters, boolean. Simple data structure can be classified into following two categories:(a) Array: Arrays refer to a named list of a finite number n of similar data elements.For example, int ARR[10];Above array ARR have 10 elements, each elements will be referenced as Arr[0], ARR[1]………….ARR[9].(b) Structure: Structure refers to a named collection of variables of different data types.For example, a structure named as STUD contais (Rno, Name, Mark), then

Page 54: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

individual fields will be referenced asSTUD.fieldname such as, STUD.Rno, STUD.Name etc.2. Compound Data Structure: Simple data structure can be combine in various waus to form more complexstructures called compound data structures which are classified into following two categories:(a) Linear data structure: These data structures are a single level data structures representing linear relationshipamong data. Following are the types of linear data structure:(i) Stacks: Stack is a LIFO (Last In First Out) list. For example, stack of plates on counter, as that plates are insertedor removed only from the top of the stack.(ii) Queue: Queue is a FIFO (First In First Out) list. For example, line of people waiting for their turn to vote.(iii) Linked List: Linked lists are special lists of some data elements liked to one another. For example, peoplesseating in a cinema hall where each seat is connected to other seat.

(b) Non-Linear data structure: These data structures are multilevel data structure representing hierarchicalrelationship among data. For example, relationship of child, parent and grandparent.

5 From a two-dimensional array A[4 x 4], write an algorithm to prepare a one dimensional array B[16] that willhave all the elements of A as if they are stored in row-major form. For example for the following array:the resultant array should be1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Ans. #include (iostream.h)#include (conio.h)void main( ){int A[4][4], B[16];// Input elementsfor(int i = 0; i < 4 ; i++)for( int j = 0; j < 4 ; j++){cout<<"\n Enter elements for "<< i+1 << "," << j+1 << "location :";cin >> A[i][j];}clrscr();//Print the arraycout<<"\n The Original matrix : \n\n";for( i = 0; i < 4 ; i++){for( j = 0; j < 4 ; j++)cout<< A[i][j]<<"\t";cout<< "\n";}int k = 0;// Convert 2 - D array into 1-D array by row-major rulefor( i = 0; i < 4 ; i++)for( j = 0; j < 4 ; j++)

Page 55: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

B[k] = A[i][j];//display the 1D Arrayfor( k=0; k<16; k++)cout<< B[k] << " ";getch( );}

6 Write a function in C++, which accepts an integer array and its size as arguments and replaces elements havingodd values with thrice its value and elements having even values with twice its value.Example: if an array of nine elements initially contains the elements as 3, 4, 5, 16, 9then the function should rearrange the array as 9, 8, 15, 32, 27

Ans void RearrangeArray(int A[],int size){for(int i=0;i<size;i++){ if(A[i]%2==0)A[i]*=2;elseA[i]*=3;}}

7 Write a function in C++ to print the product of each column of a two dimensional integer array passed as theargument of the function.Explain: if the two dimensional array contains1 2 43 5 64 3 22 1 5Then the output should appear as:Product of Column 1 = 24Product of Column 2 = 30Product of Column 3 = 240

Ans. void ColProd(int A[4][3],int r,int c){ int Prod[C],i,j;for(j=0;j<c;j++){ Prod[j]=1;for(i=0;i<r;i++)Prod[j]*=A[i][j];cout<<"Product of Column" <<j+1<<"="<<Prod[j]<<endl;}}

8 Write a function in C++ which accepts a 2D array of integers and its size as arguments and display the elementswhich lie on diagonals.[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3 x 3, 5 x 5, 7 x 7 etc….]Example, if the array content is5 4 36 7 81 2 9Output through the function should be:

Page 56: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Diagonal One: 5 7 9Diagonal Two: 3 7 1

Ans. const int n=5;void Diagonals(int A[n][n], int size){int i,j;cout<<"Diagonal One:";for(i=0;i<n;i++)cout<<A[i]ij]<<" ";cout<<"\n Diagonal Two:"for(i=0;i<n;i++)cout<<A[i][n-(i+1)]<<" ";}

9 Write a function in C++ which accepts a 2D array of integers and its size as arguments and display the elementsof middle row and the elements of middle column.[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3 x 3, 5 x 5, 7 x 7 etc….]Example, if the array content is3 5 47 6 92 1 8Output through the function should be:Middle Row: 7 6 9Middle Column: 5 6 1

Ans const int S=7; // or it may be 3 or 5int DispMRowMCol(int Arr[S][S],int S){ int mid=S/2;int i;//Extracting middle rowcout<<"\n Middle Row:";for(i=0;i<S;i++)cout<<Arr[mid][i]<<" ";//Extracting middle columncout<<"\n Middle Column:";for(i=0;i<S;i++)cout<<Arr[i][mid]<<" ";}

10 Write a function in C++ to print the product of each row of a two dimensional integer array passed as theargument of the function.Explain: if the two dimensional array contains20 40 1040 50 3060 30 2040 20 30Then the output should appear as:Product of Diagonal 1 = (1 x 5 x 2 x 4)=40Product of Diagonal 2 = (3 x 6 x 3 x 2)=108

Ans void RowProduct(int A[4][3],int R,int C){ int Prod[R];for(int i=0;i<R;i++)

Page 57: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ Prod[i]=1;for(int j=0;j<c;j++)Prod[i]*=A[i][j];cout<<"Product of row"<<i+1<<"="<<Prod[i]<<endl;}}

11 Write a function REASSIGN() in C++, which accepts an array of integer and its size as parameters and divide all those array elements by 5 which are divisible by 5 and multiply other array element by 2.Sample Input Data of the arrayA[0] A[1] A[2] A[3] A[4]20 12 15 60 32Content of the array after calling REASSIGN() functionA[0] A[1] A[2] A[3] A[4]4 24 3 12 64

Ans. void REASSIGN (int Arr[ ], int Size){for (int i=0;i<Size;i++)if (Arr[i]%5==0)Arr[i]/=5;elseArr[i]*=2;}

12 Define a function SWAPCOL() in C++ to swap (interchange) the first column elements with the last columnelements, for a two dimensional integer array passed as the argument of the function.Example: If the two dimensional array contents2 1 4 91 3 7 75 8 6 37 2 1 2After swapping of the content of 1st column and last column, it should be:9 1 4 27 3 7 13 8 6 52 2 1 7

Ans Ans. void SWAPCOL(int A[ ][100], int M, int N){int Temp, I;for (I=0;I<M;I++){Temp = A[I][0];A[I][0] = A[I][N-1];A[I][N-1] = Temp;}}

Page 58: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

13 Define a function SWAPARR() in C++ to swap (interchange) the first row elements with the last row elements,for a two dimensional integer array passed as the argument of the function.Example: If the two dimensional array contents5 6 3 21 2 4 92 5 8 19 7 5 8After swapping of the content of 1st column and last column, it should be:9 7 5 81 2 4 92 5 8 15 6 3 2

Ans void SWAPARR (int A[100][], int M, int N){int Temp, I;for (I=0;I<M;I++){Temp = A[0][I];A[0][I] = A[N-1][I];A[N-1][I] = Temp;}}

Practice Questions

1. Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value

2. Write a function in C++ which accepts an integer array and its size as argument and exchanges the value of first half side elements with the second half side elements of the array.

Example: If an array of eight elements has initial content as 2,4,1,6,7,9,23,10. The function should rearrange the array as 7,9,23,10,2,4,1,6.

3. Write a function in c++ to find and display the sum of each row and each column of 2 dimensional array. Use the array and its size as parameters with int as the data type of the array.

4. Write a function in C++, which accepts an integer array and its size as parameters and rearrange the array in reverse. Example if an array of five members initially contains the elements as 6,7,8,13,9,19 Then the function should rearrange the array as 19,9,13,8,7,6

5. Write a function in C++, which accept an integer array and its size as arguments and swap the elements of every even location with its following odd location. Example : if an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 Then the function should rearrange the array as 4,2,6,1,7,5,23,9,10

Page 59: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

6. Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having odd values with thrice and elements having even values with twice its value. Example: If an array of five elements initially contains the elements 3,4,5,16,9

Then the function should rearrange the content of the array as 9,8,15,32,27

QUESTION 3(A) PERTAINING TO SEARCHING / SORTING / MERGING TECHNIQUES THAT CARRIES 3MARKS

SPLIT-UP OF MARKS /

( ½ Mark for correct Function Header)( ½ Mark for correct initialization of required variables)( ½ Mark for correct formation of loop)(1 ½ Mark for appropriate conditions and assignments in the loop)

QUESTIONS RELATED TO 3(a)1. Write a Get2From1() function in C++ to transfer the content from one array ALL[ ] to two different arrays

Odd[ ] and Even[ ]. The Odd[ ] array should contain the values from odd positions(1,3,5,….) of ALL[ ] and Even[ ] array should contain the values from even positions (0,2,4,…) of ALL[ ].

Example: If the ALL array contains 12,34,56,67,89,90 the Odd[ ] array should contain 34, 67,90 and the Even[ ] array should contain 12,56,89 3

Answer:void Get2From1(int ALL[ ],int n, int Odd[ ],int Even[ ]){ int j=0,k=0;

for (int i=0; i<n; i++) if(i%2==0) Even[j++]=a[i]; else Odd[k++]=a[i];

Page 60: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

}

2. Write a Get1From2 ( ) function in C++ to transfer the content from two arrays FIRST[ ] and SECOND[ ] to array ALL[ ]. The even places (0, 2, 4, ...) of array ALL[ ] should get the content from the array FIRST[ ] and odd places (1, 3, 5, ) of the array ALL[] should get the content from the array SECOND[ ]. Example: If the FIRST[ ] array contains 30, 60, 90

And the SECOND[ ] array contains 10, 50, 80The ALL[ ] array should contain 30, 10, 60, 50, 90, 80

Answer :

void Get1From2 (int ALL[],int FIRST[],int SECOND[],int N,int M)

{

for(int I=0,J=0,K=0;i<N+M; I++)

if (I%2==0)

ALL[I]=FIRST[J++];

else

ALL[I]=SECOND[K++];

}

3. Write a function in C++ to merge the contents of two sorted arrays A & B into third array C.Assuming array A and B are sorted in ascending order and the resultant array C is also required to be in ascending order.

ANSWER:void AddNSave(int A[ ],int B[ ],int C[ ],int N,int M, int &K) {int I=0,J=0;K=0;while (I<N && J<M) { if (A[I]<B[J]) C[K++]=A[I++]; else if (A[I]>B[J]) C[K++]=B[J++]; else { C[K++]=A[I++]; J++; } for (;I<N;I++) C[K++]=A[I]; for (;J<M;J++) C[K++]=B[J];} }

4. Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.

Answer :void AddNSave(int A[],int B[],int C[],int N,int M, int &K)

Page 61: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ int I=0,J=M-1; K=0;

while (I<N && J>=0) { if (A[I]<B[J]) C[K++]=A[I++]; else if (A[I]>B[J]) C[K++]=B[J--]; else { C[K++]=A[I++]; J--; } } for (int T=I;T<N;T++) C[K++]=A[T]; for (T=J;T>=0;T--) C[K++]=B[T];

}

5. Write a function SORTPOINTS( ) in C++ to sort an array of structure Game in ascending order of Points using Bubble Sort.

Note: Assume the following definition of structure Game

struct Game{long PNo; //Player Numberchar PName [20] ;long Points;} ;

ANSWER: void SORTPOINTS(Game G[], int N){Game Temp;for (int I = 0; I<N-l; I++)for (int J = 0; J<N-I-l; J++)if(G[J].Points < G[J+l].Points){Temp = G[J];G[J] = G[J+l];G[J+l] = Temp;}

6. Assume array E containing elements of structure Employee is required to be arranged in descending order of Salary. Write a C++ function to arrange same with the help of bubble sort, the array and its size is required to be passed as parameters to the function. Definition of structure Employee is as follows:

Struct Employee{int Eno;char name[25];float Salary;};

Page 62: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Solution:void bubble(Employee E[ ],int n){ int i,j; Employee Etemp;

for(i=0;i<n;++i)for(j=0;j<(n-1)-i ;j++) if(E[j].salary<E[j+1].salary) {

Etemp=E[j];E[j]=E[j+1];E[j+1]=temp;

} cout<<"The details of the employee in ascending order of salary ";

for(i=0;i<n;i++) cout<<E[i].Eno<<'\t'<<E[i].name<<.\t<<E[i].Salary<<endl;

}7. Defined function in C++ to search for one float from p with the help of binary search method.The function

should return an integer 0 to show absence of the number in the array. The function should have the parameters as (1) an array P (2) the number DATA to be searched (3) number of elements N.

Answer:int BinSearch(float P[ ], float DATA, int N){ int l=0,u=N-1,m; while(l<=u){ m=(l+u)/2; if (DATA= = P[m]) return 1; else if(DATA<P[m]) u=m-1; else l=m+1;} return 0;}

8. Linear search int linear_search(int a[], int size, int item){ int i=0; While(i<size&& a[i]!=item) i++;

if(i<size)cout<<item << “is present in the array at index no”<<i;

else cout<<item<”is not present in the array”<<endl; }}

9. Selection Sort void selectionSort(int a[ ], int N){ int i, j, small; for (i = 0; i < (N - 1); i++)

Page 63: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ small = a[i]; for (int j = i + 1; j < N; j++) {

if (a[j] < small) {

small=a[j]; minIndex = j; } } a[minindex]=a[i] ; a[i]=small; } }

QUESTION No. 3(b) 3MarksMarking Scheme( ½ 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) __________________________________________________________________________________

1) 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.

Answer: Given, For given array A[M][N] where M=Number of rows, N =Number of Columns present in the arrayaddress of A[I][J]= base address+(I * N + J)*sizeof(type)

W=4 M=20 N=30 Loc(P[2][20])=5000 Column Major Formula: Loc(P[I][J]) =Base(P)+ W * (M*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) =3392+4*(300+5) =3392+1220 =4612

2. For a given array A[10][20] is stored in the memory along the row with each of its elements occupying 4 bytes. Calculate address of A[3][5] if the base address of array A is 5000.

Solution:

For given array A[M][N] where M=Number of rows, N =Number of Columns present in the array

Page 64: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

address of A[I][J]= base address+(I * N + J)*sizeof(type)here M=10, N=20, I=3, J=5, sizeof(type)=4 bytes

address of A[3][5] = 5000 + (3 * 20 + 5) * 4= 5000 + 65*4=5000+260=5260

3. An array VAL[115][110] is stored in the memory with each element requiring 4 bytes of storage. If the base address of the array VAL is 1500, determine the location of VAL[12][9] when the array VAL is stored (i) Row wise (ii) Column wise.

Solution: Given Data: VAL[115][110] Word Length (W) = 4 Bytes Base Address of VAL(B) = 1500 VAL[12][9] = ? C = Total No of Columns R = Total No of Rows Lr = Least Row=1 Lc = Least Column=1 ( i ) Row Major: Address of an element (I,J) in row major = B + W ( C (I-Lr) + (J Lc)) VAL [12][9] = 1500 + 4 (10 * (12-1) + (9-1)) = 1500 + 4 (10 * 11+8) = 1500 + 4 (118)

= 1500 + 472 = 1972.

( i ) Column Major: Address of an element (I,J) in column major = B + W ( (I-Lr) + R(J Lc)) VAL [12][9] = 1500 + 4 ((12-1) +15 * (9-1)) = 1500 + 4 (11 + 15 * 8)

= 1500 + 4 ( 11+ 120) = 1500 + 4 * 131 = 1500 + 524 = 2024

4. An array Arr[15][20] is stored in the memory along the row with each element occupying 4 bytes. Find out the Base address of the location Arr[3][2], if the location Arr[5][2] is stored at the address 1500.

Solution: Given Data: Arr[15][20] W=4 B=? R=15 C=20 Lr = 0 Lc = 0 Address of Arr[3][2] = ?

Address of Arr[5][2] = 1500. Address of an element (I,J) in row major = B+W(C(I-Lr)+(J-Lc )) Therefore, 1500 = B+4(20(5-0)+(2-0)) 1500 = B+4(20*5+2) 1500 = B+4*102 1500 = B+408 B =1500-408

Page 65: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

B=1092 Address of Arr[3][2] =1092+4(20*3+2) =1092+4(62) =1092+248 =1340.

5) An array Array[20][15] is stored in the memory along the column with each element occupying 8 bytes. Find out the base address of the element Array[2][3] if the element Array[4][5] is stored at the address 1000. Solution: Given Data: Aray [20][15] W=8 B=? R=20 C=15 Lr = 0 Lc = 0 Address of Array [2][3] =? Address of Array[4][5] =1000. Address of an element (I,J) in column major =B + W ( (I-Lr) + R(J-Lc ) ) Therefore

1000=B+8*((4-0)+20(5-0)) 1000=B+8*(4+20*5) 1000 =B+8*104 1000=B+832 B =1000-832 B =168 Therefore Address of Array[2][3]=168+8*((2-0)+20(3-0)) =168+8*(2+20*3) =168+8*62 =168+496 =664

6) An array S[40][30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the memory location for the element S[20][10], if the Base Address of the array is 5000.Solution

Given, W=2 N=40 M=30 Base(S)=5000 Row Major Formula: Loc(S[I][J]) =Base(S)+W*(M*I+J) Loc(S[20][10]) =5000+2*(30*20+10) =5000+2*(600+10) =5000+1220 =6220

7)An array S[40][30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the memory location for the element S[20][10], if an element S[15][5] is stored at the memory location 5500.Given, W=2 N=40 M=30 Loc(S[15][5])=5500

Row Major Formula: Loc(S[I][J]) =Base(S)+W*(M*I+J) Loc(S[15][5]) =Base(S)+2*(30*15+5) 5500 =Base(S)+2*(450+5) Base(S) =5500- 910 Base(S) =4590 Loc(S[20][10]) =4590+2*(30*20+10) =4590+2*(600+10) =4590+1220 = 5810

Page 66: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Practice Questions

An array Arr[50][100] is stored in the memory along the row with each element occupying 2 bytes of memory .Find out the base address of the location Arr[20][50], if the location of Arr[10][25] is stored at the address 10000.Ans 12050

An array [20][15] is stored in the memory along the column n with each element occupying 8 bytes of memory . find out the base address and address of the element Array [2][3] , if the element Array [10][25] is stored at the address 1000.Ans Base address 168, 664

An array X[7][20] is stored in the memory with each element requiring 2 bytes of storage . If the base address of array is 2000 , calculate the location of X[3][5] when the array X stored in column major order.Note: X[7][20] means valid row indices are 0 to 6 and valid column indices are 0 to 10.

Ans 2076

An array Arr[15][20] is stored in the memory along the row with element occupying 4 bytes of memoryFind out the base addresss and address of the element Arr[3][2] , if the element Arr[10][25] is stored at the address 1500.

Ans: Base Address 1092

Each element of an array DATA[1..10][1..10] required 8 bytes of storage .if base address of array DATA is 2000 determine the location od DATA [4][5] , when the array is stored (i) Row-wise (ii) Column -wise

Ans.2272,2344

Linked List Questions Question NO. 3(c ) Marks 4

(1 Mark for declaring Temp pointer) (1 Mark for creating a new node and assigning/entering appropriate values in it) (1 Mark for connecting link part of new node to top) (1 Mark for assigning Top as the new node i.e. Temp)

____________________________________________________________

1.) Define function stackpush( ) to insert nodes and stackpop( ) to delete nodes, for a linked list implemented stack having the following structure for each node:

struct Node{ char name[20];int age;

Page 67: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Node *Link; };class STACK{ Node * Top;

public:STACK( ) { TOP=NULL;}void stackpush( );void stackpop( );~STACK( ); };

ANS:void STACKPUSH(){

Node *newptr=new Node;cout<<”Enter the name”;gets(newptr->name);cin>>newptr->age;if(top==NULL) // Linked list is empty

{Top=newptr; /* New node is the first node*/

}else{

newptr->Link=Top; Top=newptr;

} }

void stackpop( ) // Pop from the beginning{

Node *temp;if(top==NULL)

{ cout<<”UNDERFLOW……………….”;

}else{

temp=Top;Top=Top->Link;delete temp;

} }

2)Write a function in C++ to perform Push operation on a dynamically allocated Stack containing real numbers.Answer: struct NODE{

float Data; NODE *Link;

}; Class STACK{

NODE *Top;public: STACK();

Page 68: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

void Push(); void Pop();

};void STACK::Push(){

NODE *Temp; Temp=new NODE; cin>>Temp->Data; Temp->Link=Top; Top=Temp;

} ( 1/2 Mark for appropriate function header) ( 1/2 Mark for declaring a Temporary pointer - TEMP) (1 Mark for new operation) (1 Mark for Temp->Link to Top) (1 Mark for assigning Top as Temp)

3)Write a function in C++ to delete a node containing customers information, from a dynamically allocated Queue of Customers implemented with the help of the following structure: struct Customer { int CNo ; char CName[20] ; Customer *Link ; } ;Answer: struct Customer { int CNo ; char CName[20] ; Customer *Link ; } ;class Queue{ Customer *front,*rear; public: Queue( ) { front=rear=NULL; } void Insert( ); void Delete( ); void Display( ); };

void Queue::Delete( ) { Customer *Temp; if(front= =NULL) cout<< “Queue Underflow. No element to delete”; else { cout<<”\n The customer number for the element to delete”<<front ->CNo;

cout<<”\n The customer name for the element to delete”<<front ->CName; Temp=front;

front = front->Link; delete Temp; } }

Page 69: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

4) Write a function in C++ to perform a DELETE operation in a dynamically allocated queue considering the following description : struct Node { float U, V ; Node *Link ; } ; class QUEUE { Node *Rear, *Front ; public :

QUEUE( ) { Rear = NULL ; Front = NULL ;}

void INSERT( ) ; void DELETE( ) ; ~ QUEUE( ) ; } ;Solution: void Queue::DELETE( ) { NODE *temp; if(front= = NULL)

cout<<”\nQueue Underflow”; else { cout<<”\nThe value of U of the element to delete:” <<Front->U; cout<<”\nThe value of V of the element to delete: “<<Front->V; temp=Front; Front=Front->Link; delete temp; } }

5)Write a function in C++ to perform a DELETE operation in a dynamically allocated queue considering the following description: struct Node

{ char name[20] ; int age;Node *Link; };

class QUEUE{ Node *Rear, *Front; public: QUEUE( ) { Rear =NULL; Front= NULL;} void INSERT ( ); void DELETE ( ); ~QUEUE ( ); };void QUEUE ::DELETE( ){

Node *temp;if(front==NULL) // No element in the queue

{cout<<”UNDERFLOW………………..”;}else

Page 70: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

{ temp=front; front=front->Link; // Make second node as first delete temp; // deleting the previous first node.} }void QUEUE:: INSERT( ){ Node *nptr;

nptr=new node;nptr->link=NULL;cout<<”enter name and age”;gets(nptr->name);cin>>nptr->age;if(rear==NULL) cout<<”Underflow!!”;else { ptr=front; if(front==rear) front=rear =NULL; else front=front->link;

delete ptr;} }

6)Each node of a STACK contains the following information, in addition to pointer field:(i).Pin code of city(ii).Name of city Give the structure of node for the linked STACK in question.TOP is a pointer that points to the topmost node of the STACK. Write the following functions:

(i) PUSH( ) To push a node into the STACK, which is allocated dynamically.(ii) POP( ) To remove a node from the STACK, and release the memory.

Solution:struct City{ long Cpin ; char CName[20] ; City *Next ; } ; class Stack { City *Top; public: Stack( ) { Top = NULL; } void Push( ); void Pop( ); void Display( ); };void Stack::PUSH( ) { City *Temp; Temp=new City; if(Temp= =NULL) { cout<<\nNo memory to create the node; exit(1); } cout<<\nEnter the City Pin Code to be inserted: ; cin>>TempCpin; cout<<\nEnter the City Name to be inserted: ; gets(TempCName); TempNext=Top; Top=Temp;

Page 71: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

} void Stack::POP( ){ City *Temp; if( Top= = NULL) cout<<”Stack Underflow; “ else { cout<<”\nThe City Pin Code for the element to delete: “<<Top->Cpin; cout<<”\nThe City name of the element to delete: “<<Top->CName;

Temp=Top; Top=Top->Next; Delete Temp;

} }

7)class queue { int data[10] ; int front, rear ;public : queue( ) { front = - 1 ; rear = - 1 ; } void add( ) ; //to add an element into the queue

void remove( ) ; //to remove an element from the queue void Delete(int ITEM( ) ; //to delete all elements which are equal to ITEM } ;Complete the class with all function definitions for a circular array Queue. Use another queue to transfer data temporarily.Solution: void queue::add( ){if((front= = 0 && rear = = 9) | | (front= =rear+1) ) cout<<”\nQueue Overflow”; else if (rear= = -1) {

front=rear=0; cout<<”\nEnter the element to be inserted”; cin>>data[rear]; } else if(rear= =9) { rear=0; cout<<”\nEnter the element to be inserted”; cin>>data[rear];}

else { rear++; cout<<\nEnter the element to be inserted;

Page 72: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

cin>>data[rear]; } }void queue::remove( ) { if(front= = -1) cout<<\nQueue Underflow;

else { cout<<”\nThe element to be deleted<<data[front]”; if(front= =rear) front=rear=-1; else if (front= =9) front=0; else front++; }}

8)Write a function in C++ to perform Insert operation in a dynamically allocated Queue containing names of students. struct NODE { float Data; NODE *Link; };class STACK{ NODE *Top;public: STACK(); void Push();void Pop(); void Display(); ~STACK(); };void STACK::Push() { NODE *Temp; Temp=new NODE; cin>>Temp->Data;Temp->Link=Top; Top=Temp; }

Question 3(e) carries 2 marks

Page 73: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Split up of marks( 1½ Mark for showing stack position for operations )

( ½ Mark for correctly evaluating the final result)

Evaluation of a POSTFIX expression:Steps:

1. Read the expression from left to right, if an operand is encountered, push it into stack. 2. If a binary operator is encountered, pop two operands from stack and if a unary operator is encountered,

pop one operand and then evaluate it. 3. Push back the result onto stack. 4. Repeat it till the end of the expression.

1. Evaluate the following postfix notation of expression (show status of stack after execution of each operation).5, 11, -, 6, 8, +, 12, *, /

Answer:Step Input Action Stack Status1 5 Push (5) 52 11 Push (11) 5, 113 - Pop (11)

Pop (5)

Push (5-11) -6

4 6 Push (6) -6, 65 8 Push (8) -6, 6, 86 + Pop (8) -6, 6

Pop (6) -6

Push (6+8) -6, 14

7 12 Push (12) -6, 14, 128 * Pop (12) -6, 14

Pop (14) -6

Push (14 * 12) -6, 168

9 / Pop (168) -6Pop (-6)

Push (-6/ 168) -1/28

Page 74: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

2. Evaluate the following postfix notation of expression (show status of stack after execution of each operation).TURE, FALSE, TRUE, FALSE, NOT, OR, TRUE, OR, OR, AND

Answer:Step Input Action Stack Status1 TRUE Push TRUE2 FALSE Push TRUE, FALSE3 TRUE Push TRUE, FALSE, TRUE4 FALSE Push TRUE, FALSE, TRUE, FALSE5 NOT Pop(False) TRUE, FALSE, TRUE

Push (Not FALSE=TRUE) TRUE, FALSE, TRUE, TRUE

6 OR Pop(TRUE) TRUE, FALSE, TRUEPop (TRUE) TRUE, FALSE

push (TRUE or TRUE=TRUE) TRUE, FALSE, TRUE

7 TRUE push TRUE, FALSE, TRUE, TRUE8 OR pop (TRUE) TRUE, FALSE, TRUE

pop(TRUE) TRUE, FALSE,

push (TRUE or TRUE=TRUE) TRUE, FALSE, TRUE

9 OR pop (TRUE) TRUE, FALSE,pop(FALSE) TRUE

push (TRUE or FALSE=TRUE) TRUE, TRUE

10 AND pop (TRUE) TRUE,

3. Evaluate the following postfix notation of expression:

50, 60, + , 20, 10, -, *

Ans: Element Scanned STACK

50 50

60 50, 60

+ 110 (since 50+60=110)

20 110, 20

Page 75: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

10 110, 20, 10

– 110, 10 (since 20-10=10)

* 1100 (since 110*10=1100)

Result : 1100

4.Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation :

50,40,+,18, 14,-, *,40,+

Answer:

Element Scanned STACK Status

50 50

40 50,40

+ 90

18 90,18

14 90,18,14

- 90,4

* 360

40 360,40

+ 400

RESULT=400

5.Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:

2,13, + , 5, -,6,3,/,5,*,<

Answer:

Element Scanned STACK Status

2 213 2,13+ 155 15,5- 10

Page 76: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

6 10,63 10,6,3/ 10,25 10,2,5* 10,10< FALSE ( SINCE 10<10 -> FALSE)RESULT=FALSE.

6.Evaluate the following postfix notation of expression:

True, False, AND, True, True, NOT, AND,OR

Answer: Ans

Element Scanned STACK Status

True TRUE

False TRUE, FALSE

AND FALSE (SINCE TRUE AND FALSE=>FALSE)

True FALSE, TRUE

True FALSE, TRUE, TRUE

NOT FALSE, TRUE,FALSE (SINCE NOT(TRUE)=>FALSE)

AND FALSE,FALSE (SINCE TRUE AND FALSE=>FALSE)

OR FALSE (SINCE FALSE OR FALSE=>FALSE)

Result: FALSE

7.Evaluate the following postfix notation of expression: 2

True, False, NOT, AND, True, True, AND,OR

Answer:

Element Scanned STACK Status

True TRUE

False TRUE, FALSE

NOT TRUE, TRUE

AND TRUE

True TRUE, TRUE

True TRUE, TRUE, TRUE

Page 77: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

AND TRUE, TRUE

OR TRUE

Result: TRUE

PRACTICE PROBLEMS:1.Evaluate the following postfix expression using a stack and show the contents of the stack after execution of

each operation. 5,11,+, 6, 8, +, 2, / ,* ANS =23

2. Evaluate the following postfix expression using a stack. Show the contents of stack after execution of each operation.

20, 8, 4,/, 2,3,+,*,- ANS =10

3. Evaluate the following postfix expression showing stack status after every step.8, 2, +, 5, 3, -, *, 4 / ANS =05

4. Evaluate the following Boolean postfix expression showing stack status after every stepTrue, False, True, AND, OR, False, NOT, AND ANS =TRUE

5. Evaluate the following postfix expression E given below; show the contents of the stack during the evaluationa) E= 5,9,+2,/,4,1,1,3,-,*,+b) E=25, 8, 3, - , / 6, *, 10 +c) E=8, 7, -, 9, 8, *, -, 2, / , 3,4, * 2, / -d) E= 5,20,15,-,*,25,2,*,-e) E= 10,+,15,*,25,5,/,2+f) E= 7,6,2,/,+,18,-g) E= 7,6, +, 8, * , 2, -, 3, * , 2, 4, * , -h) E=TRUE, FALSE, NOT, TRUE, OR, FALSE, AND, ORi) E=FALSE, TRUE, TRUE, NOT, AND, OR, AND

Converting INFIX to POSTFIX notation: An arithmetic expression is an expression having variables, constants and operators. The hierarchy of the operators is as follows: Arithmetic Operators

Precedence

Exponents( ^ or ↑) HighestMultiplication(*) and Division (/) MiddleAddition (+) and Subtraction (-) LowestLogical Operators PrecedenceNOT(!) HighestAND (&&) MiddleOR (||) Lowest Stack can be used to convert an infix expression into postfix notation.Steps:

1. Scan the given infix expression from left to right and repeat the step 2 to 5 for each element until the stack is empty.

2. If an operand is encountered, place it onto the output (pop). 3. If a left parenthesis is encountered, push it into stack. 4. If an operator is encountered, then:

(i) If a symbol of lower or same priority is encountered, pop entries from the stack until an entry of lower priority is reached.

Page 78: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(ii) After popping, push the operator onto stack 5. If a right parenthesis is encountered, pop the stack elements until a corresponding left parenthesis is

reached. 6. End

Example: Convert ((A+B)*C/D+E^F)/G into postfix notation from showing stack status after every step.Answer:Step Input Action Stack Status Output1 ( Push (2 ( Push ((3 A Print (( A4 + Push ((+ A5 B Print ((+ AB6 ) Pop & Print ( AB+7 * Push (* AB+8 C Print (* AB+C9 / Pop & print ( AB+C*

Push (/ AB+C*10 D Print (/ AB+C*D11 + Pop & Print ( AB+C*D/12 E Print ( AB+C*D/E13 ^ Push (^ AB+C*D/E14 F Print (^ AB+C*D/EF15 ) Pop & Print Empty AB+C*D/EF^16 / Push / AB+C*D/EF^17 G Print / AB+C*D/EF^G18 Pop Empty AB+C*D/EF^G/Remark: * and / has same priority so in step 9, so * is popped and after that / is pushed.

Example: Convert the expression (TRUE && FALSE) || !(FALSE||TRUE) into postfix notation from showing stack status after every step.Answer:Step Input Action Stack Status Output1 ( Push (2 TRUE Print ( TRUE3 && Push (&& TRUE4 FALSE Print (&& TRUE FALSE5 ) Pop Empty TRUE FALSE &&6 || Push || TRUE FALSE &&7 ! Push || ! TRUE FALSE &&8 ( Push || ! ( TRUE FALSE &&9 FALSE Print || ! ( TRUE FALSE && FALSE10 || Push || ! ( || TRUE FALSE && FALSE11 TRUE Print || ! ( || TRUE FALSE && FALSE TRUE12 ) Pop || ! TRUE FALSE && FALSE TRUE ||13 Pop || TRUE FALSE && FALSE TRUE || !14 Pop Empty TRUE FALSE && FALSE TRUE || ! ||

Remark: Here TRUE , FALSE are operands and !, ||, && are operators.

1. Convert the following infix expressions to postfix expressions using stack 2 Marks(i) A + (B * C) ^ D – (E / F – G)(ii) A * B / C * D ^ E * G / H

Page 79: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(iii) ((A*B)-((C_D)*E/F)*G

Unit-3

DATABASE AND SQL

Basic Database concepts

Data :- Raw facts and figures which are useful to an organization. Information:- Well processed data is called information. Field: Set of characters that represents specific data element.Record: Collection of fields is called a record. A record can have fields of different data types.File: Collection of similar types of records is called a file.Table: Collection of rows and columns that contains useful data/information is called a table.

A table generally refers to the passive entity which is kept in secondary storage device.Relation: Relation (collection of rows and columns) generally refers to an active entity on which

we can perform various operations. Database: Collection of logically related data along with its description is termed as database. Tuple: A row in a relation is called a tuple.Attribute: A column in a relation is called an attribute. It is also termed as field or data item.Degree: Number of attributes in a relation is called degree of a relation.Cardinality: Number of tuples in a relation is called cardinality of a relation.

Student

RollNo Name Address101 abc PQ-40102 bca AR-40KeysPrimary Key: Primary key is a key that can uniquely identifies the records/tuples in a relation. This

key can never be duplicated and NULL.Candidate Key: Set of all attributes which can serve as a primary key in a relation.Alternate Key: All the candidate keys other than the primary keys of a relation are alternate keys for a relation.

Structured Query LanguageSQL is a non procedural language that is used to create, manipulate and process the databases(relations).

Characteristics of SQLIt is very easy to learn and use.Large volume of databases can be handled quite easily.It is non procedural language. It means that we do not need to specify the procedures to accomplish a task

Page 80: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

but just to give a command to perform the activity.SQL can be linked to most of other high level languages that makes it first choice for the database programmers.

Processing Capabilities of SQLThe following are the processing capabilities of SQL

1. Data Definition Language (DDL)DDL contains commands that are used to create/ modify/ delete the tables, databases etc.e.g:Create table, alter table etc.2. Data Manipulation Language (DML)DML contains command that can be used to manipulate the data base objects and to query the databases

for information retrieval.e.g Select, Insert, Delete, Update etc.

Data types of SQLJust like any other programming language, the facility of defining data of various types is available in SQL also. Following are the most common data types of SQL.

1) NUMBER2) CHAR 3) VARCHAR / VARCHAR24) DATE5) LONG

1. NUMBERUsed to store a numeric value in a field/column. It may be decimal, integer or a real value. General syntax is

Number(n,d)Where n specifies the number of digits andd specifies the number of digits to the right of the decimal point.e.g marks number(3) declares marks to be of type number with maximum value 999.

pct number(5,2) declares pct to be of type number of 5 digits with two digits to the right of decimal point.

2. CHAR Used to store character type data in a column. General syntax is Char (size)where size represents the maximum number of characters in a column. The CHAR type data can hold at most 255 characters.e.g name char(25) declares a data item name of type character of upto 25 size long. 3. VARCHAR/VARCHAR2This data type is used to store variable length alphanumeric data. General syntax is

varchar(size) / varchar2(size)where size represents the maximum number of characters in a column. The maximum allowed size in this data type is 2000 characters.e.g address varchar(50); address is of type varchar of upto 50 characters long.4. DATEDate data type is used to store dates in columns. SQL supports the various date formats other that the standard DD-MON-YY.e.g dob date; declares dob to be of type date.5. LONGThis data type is used to store variable length strings of upto 2 GB size.e.g description long;SQL Commandsa. CREATE TABLE Command:

Page 81: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Create table command is used to create a table in SQL. It is a DDL type of command. The general syntax of creating a table isCreating TablesThe syntax for creating a table iscreate table <table> (<column 1> <data type> [not null] [unique] [<column constraint>],. . . . . . . . .<column n> <data type> [not null] [unique] [<column constraint>],[<table constraint(s)>]);For each column, a name and a data type must be specified and the column name must be unique within the table definition. Column definitions are separated by comma. Uppercase and lowercase letters makes no difference in column names. A not null Constraint means that the column cannot have null value, that is a value needs to be supplied for that column. The keyword unique specifies that no two tuples can have the same attribute value for this column.

Operators in SQL:The following are the commonly used operators in SQL

1. Arithmetic Operators +, -, *, / 2. Relational Operators =, <, >, <=, >=, <>3. Logical Operators OR, AND, NOT

Arithmetic operators are used to perform simple arithmetic operations.Relational Operators are used when two values are to be compared and Logical operators are used to connect search conditions in the WHERE Clause in SQL.Constraints:Constraints are the conditions that can be enforced on the attributes of a relation. The constraints come in play when ever we try to insert, delete or update a record in a relation.

1. NOT NULL2. UNIQUE3. PRIMARY KEY4. FOREIGN KEY5. CHECK6. DEFAULT

Not null ensures that we cannot leave a column as null. That is a value has to be supplied for that column.e.g name varchar(25) not null;Unique constraint means that the values under that column are always unique. e.g Roll_no number(3) unique;Primary key constraint means that a column can not have duplicate values and not even a null value. e.g. Roll_no number(3) primary key;The main difference between unique and primary key constraint is that a column specified as unique may have null value but primary key constraint does not allow null values in the column.

CREATE TABLE student (Roll_no number(3) primary key,Name varchar(25) not null,Class varchar(10),Marks number(3) check(marks>0),City varchar(25) );

Data Modifications in SQLAfter a table has been created using the create table command, tuples can be inserted into the table, or tuples can be deleted or modified.

Page 82: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

INSERT Statement The simplest way to insert a tuple into a table is to use the insert statementinsert into <table> [(<column i, . . . , column j>)] values (<value i, . . . , value j>);

INSERT INTO student VALUES(101,'Rohan','XII',400,'Jammu');While inserting the record it should be checked that the values passed are of same data types as the one which is specified for that particular column.

Roll_no Name Class Marks City101 Rohan XII 400 Jammu

102 Aneeta Chopra XII 390 Udhampur

103 Pawan Kumar IX 298 Amritsar

104 Rohan IX 376 Jammu

105 Sanjay VII 240 Gurdaspur

113 Anju Mahajan VII 432 PathankotQueries:To retrieve information from a database we can query the databases. SQL SELECT statement is used to select rows and columns from a database/relation.

SELECT CommandThis command can perform selection as well as projection.Selection: This capability of SQL can return you the tuples form a relation with all the attributes.Projection: This is the capability of SQL to return only specific attributes in the relation.* SELECT * FROM student; command will display all the tuples in the relation student * SELECT * FROM student WHERE Roll_no <=102;The above command display only those records whose Roll_no less than or equal to 102.Select command can also display specific attributes from a relation.* SELECT name, class FROM student;The above command displays only name and class attributes from student table.* SELECT count(*) AS “Total Number of Records” FROM student;Display the total number of records with title as “Total Number of Records” i.e an alias We can also use arithmetic operators in select statement, like* SELECT Roll_no, name, marks+20 FROM student;* SELECT name, (marks/500)*100 FROM student WHERE Roll_no > 103;Tip: : If the word list/details come in the question it is a case of SELECT *. If specific cols are to be displayed use SELECT Col1, Col2…. From TableEliminating Duplicate/Redundant dataDISTINCT keyword is used to restrict the duplicate rows from the results of a SELECT statement.

Display the different classes of the studentsSELECT DISTINCT class FROM student;

The above command returns Name

XIIIXVII

*Tip to students: If the word different appears in the question, it is a POSSIBLE case of DISTINCT.Conditions based on a rangeSQL provides a BETWEEN operator that defines a range of values that the column value must fall for the condition to become true.

Page 83: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

e.g. SELECT Roll_no, name FROM student WHERE Roll_no BETWENN 100 AND 103;The above command displays Roll_no and name of those students whose Roll_no lies in the range 100 to 103 (both 100 and 103 are included in the range).

Conditions based on a listTo specify a list of values, IN operator is used. This operator select values that match any value in the given list.e.g. SELECT * FROM student WHERE city IN (‘Jammu’,’Amritsar’,’Gurdaspur’);The above command displays all those records whose city is either Jammu or Amritsar or Gurdaspur.

Conditions based on PatternSQL provides two wild card characters that are used while comparing the strings with LIKE operator.a. percent(%) Matches any stringb. Underscore(_) Matches any one charactere.g SELECT Roll_no, name, city FROM student WHERE Roll_no LIKE “%3”;displays those records where last digit of Roll_no is 3 and may have any number of characters in front.e.g SELECT Roll_no, name, city FROM student WHERE Roll_no LIKE “1_3”;displays those records whose Roll_no starts with 1 and second letter may be any letter but ends with digit 3.ORDER BY ClauseORDER BY clause is used to display the result of a query in a specific order(sorted order).The sorting can be done in ascending or in descending order. It should be kept in mind that the actual data in the database is not sorted but only the results of the query are displayed in sorted order.e.g. SELECT name, city FROM student ORDER BY name;The above query returns name and city columns of table student sorted by name in increasing/ascending order.e.g. SELECT * FROM student ORDER BY city DESC;It displays all the records of table student ordered by city in descending order.Note:- If order is not specifies that by default the sorting will be performed in ascending order.

GROUP BY ClauseThe GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns.The syntax for the GROUP BY clause is:SELECT column1, column2, ... column_n, aggregate_function (expression)FROM tablesWHERE conditionsGROUP BY column1, column2, ... column_n;aggregate_function can be a function such as SUM, COUNT, MAX, MIN, AVG etc.e.g Display the name of city and number of students in each city (or Display the number of students city wise)

SELECT City, COUNT(*) as "Number of Students"FROM studentGROUP BY city;

Tip: If the question contains results for each, department wise etc it is a case of GROUP BY

HAVING ClauseThe HAVING clause is used in combination with the GROUP BY clause and not WHERE. It can be used in a SELECT statement to filter the records that a GROUP BY returns.The syntax for the HAVING clause is:SELECT column1, column2, ... column_n, aggregate_function (expression)FROM tablesGROUP BY column1, column2, ... column_nHAVING condition1 ... condition_n;e.g Display the total sales for each department whose total sales is more than 1000.

SELECT SUM(sales) FROM emp

Page 84: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

GROUP BY departmentHAVING SUM(sales) > 1000;

Page 85: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Functions available in SQL

SQL provide large collection of inbuilt functions also called library functions that can be used directly in SQL statements.Some of the commonly used functions are sum() avg(), count(), min(), max() .

SELECT sum(marks) FROM student;displays the sum of all the marks in the table student.

SELECT min(Roll_no), max(marks) FROM student;displays smallest Roll_no and highest marks in the table student.

SELECT avg(marks) FROM student displays the average marks in the table student

SELECT count (*) FROM studentdisplays total number of rows in the table.

DELETE CommandTo delete the record fro a table SQL provides a delete statement. General syntax is:-

DELETE FROM <table_name> [WHERE <condition>];e.g. DELETE FROM student WHERE city = ‘Jammu’;This command deletes all those records whose city is Jammu.NOTE: It should be kept in mind that while comparing with the string type values lowercase and uppercase letters are treated as different. That is ‘Jammu’ and ‘jammu’ is different while comparing.

UPDATE CommandTo update the data stored in the data base, UPDATE command is used.

e. g. UPDATE student SET marks = marks + 100;Increase marks of all the students by 100.

e. g. UPDATE student SET City = ‘Udhampur’ WHERE city = ‘Jammu’;changes the city of those students to Udhampur whose city is Jammu.

We can also update multiple columns with update command, likee. g. UPDATE student set marks = marks + 20, city = ‘Jalandhar’

WHERE city NOT IN (‘Jammu’,’Udhampur’);

ALTER TABLE Command

In SQL if we ever need to change the structure of the database then ALTER TABLE command is used. By using this command we can add a column in the existing table, delete a column from a table or modify columns in a table.

Adding a columnThe syntax to add a column is:-

ALTER TABLE table_nameADD column_name datatype;

e.g ALTER TABLE student ADD(Address varchar(30));The above command add a column Address to the table atudent.If we give commandSELECT * FROM student;The following data gets displayed on screen:

Page 86: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Roll_no Name Class Marks City Address101 Rohan XI 400 Jammu

102 Aneeta Chopra XII 390 Udhampur

103 Pawan Kumar IX 298 Amritsar

104 Rohan IX 376 Jammu

105 Sanjay VII 240 Gurdaspur

113 Anju MAhajan VIII 432 Pathankot

Note that we have just added a column and there will be no data under this attribute. UPDATE command can be used to supply values / data to this column.

Removing a column

ALTER TABLE table_nameDROP COLUMN column_name;

e.g ALTER TABLE StudentDROP COLUMN Address;

The column Address will be removed from the table student.

DROP TABLE CommandSometimes you may need to drop a table which is not in use. DROP TABLE command is used to Delete / drop a table permanently. It should be kept in mind that we can not drop a table if it contains records. That is first all the rows of the table have to be deleted and only then the table can be dropped. The general syntax of this command is:-DROP TABLE <table_name>;e.g DROP TABLE student;This command will remove the table student

Questions : Database and SQL : 1 mark questions

Q1 Write SQL queries to perform the following based on the table PRODUCT having fields as (prod_id, prod_name, quantity, unit_rate, price, city)

i. Display those records from table PRODUCT where prod_id is more than 100.ii. List records from table PRODUCT where prod_name is ‘Almirah’iii. List all those records whose price is between 200 and 500.iv. Display the product names whose price is less than the average of price.v. Show the total number of records in the table PRODUCT.

2 mark questions

1. Distinguish between Candidate Key and Primary key with suitable example.Ans: Candidate Key: The attributes or the group of attributes that can be used to uniquely identify a tuple in a relation. There may be more than one candidate key.Primary Key: The attributes or the group of attributes that is used to uniquely identify a tuple in a relation. There can be only one primary key in a table.

Page 87: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

For example consider the following table Table: Student

Stud_Id Name Course email

S001 Ajay Kumar Science [email protected]

S009 Vinod Singh Science [email protected]

In the above table, Stud_Id and email will be the candidate keys as two students may have same name but not same Id and email. Normally Stud_id will be considered as primary key.

2. Define degree and cardinality with exampleAns: Degree is the number of attributes (Columns) in a relation. For example, in the above student table, there are 4 columns so the degree of the relation is 4.Cardinality is number of tuples (rows) in a relation. For example in the above student table, there are two rows, so the cardinality of this table is 2. (Note for the student- don’t count the top heading row while counting cardinality.)

3. Define attribute and tuple.Ans: Attributes are the columns of a relation/table. Tuples are the rows.

4. What is DDL? Give two commands in DDL.Ans: Data Definition Language is the subset of SQL that deals with the creation or modification of structure of database or table. Create, Alter and Drop are the commands under DDL.

5. What is DML? Give two commands under DML.Ans: Data Manipulation Language is the subset of SQL that deals with the manipulation (inserting, updating, deleting, display) of the data stored in table. Select, Insert, Update, delete are the commands that are used under DML.

6. What is a cartesian product? Explain with be example.Ans: Cartesian Product: It operates on two relations and is denoted by X. for example Cartesian product

of two relation R1 and R2 is represented by R=R1X R2. The degree of R is equal to sum of degrees of R1 and R2. The cardinality of R is product of cardinality of R1 and cardinality of R2

Example of Cartesian Product

The table R1

Empno Ename Dept

1 Bill A

2 Sarah C

3 John AThe table R2

Dno Dname

A Marketing

B Sales

C Legal

R1 X R2

Page 88: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Empno Ename Dept Dno Dname

1 Bill A A Marketing

1 Bill A B Sales

1 Bill A C Legal

2 Sarah C A Marketing

2 Sarah C B Sales

2 Sarah C C Legal

3 John A A Marketing

3 John A B Sales

3 John A C Legal

3 marks questions 1. What is relation? What is the difference between a tuple and an attribute?

2. Define the following terminologies used in Relational Algebra:(i) selection (ii) projection (iii) union (iv) Cartesian product

3. What are DDL and DML?4. Differentiate between primary key and candidate key in a relation?5. What do you understand by the terms Cardinality and Degree of a relation in relational database?

4 Marks Questions SQL

Q1 Write SQL commands for (i) to (viii) on the basis of relations given below:BOOKSbook_id Book_name author_name Publishers Price Type qtyk0001 Let us C Sanjay mukharjee EPB 450 Comp 15p0001 Genuine J. Mukhi FIRST PUBL. 755 Fiction 24m0001 Mastering c++ Kanetkar EPB 165 Comp 60n0002 Vc++ advance P. Purohit TDH 250 Comp 45k0002 Near to heart Sanjeev FIRST PUBL. 350 Fiction 30

ISSUEDBook_ID Qty_Issued

L02 13L04 5L05 21

i. To show the books of FIRST PUBL Publishers written by P.Purohit.ii. To display cost of all the books written for FIRST PUBL.iii. Depreciate the price of all books of EPB publishers by 5%.iv. To display the BOOK_NAME,price of the books whose more than 3 copies have been issued.v. To show total cost of books of each type.vi. To show the detail of the most costly book.

Q2. Write SQL commands for (a) to (f) and write output for (g) on the basis of PRODUCTS relation given below:PRODUCT TABLE

PCODE PNAME COMPANY PRICE STOCK MANUFACTURE WARRANTY

Page 89: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

P001 TV BPL 10000 200 12-JAN-2008 3P002 TV SONY 12000 150 23-MAR-2007 4P003 PC LENOVO 39000 100 09-APR-2008 2P004 PC COMPAQ 38000 120 20-JUN-2009 2P005 HANDYCAM SONY 18000 250 23-MAR-2007 3a) To show details of all PCs with stock more than 110.b) To list the company which gives warranty for more than 2 years.c) To find stock value of the BPL company where stock value is sum of the products of price and stock.d) To show number of products from each company.e) To count the number of PRODUCTS which shall be out of warranty on 20-NOV-2010.f) To show the PRODUCT name which are within warranty as on date.g). Give the output of following statement.(i) Select COUNT(distinct company) from PRODUCT.(ii) Select MAX(price)from PRODUCT where WARRANTY<=3

3.Table : SchoolBus

Rtno

Area_overed Capacity Noofstudents Distance Transporter Charges

1 Vasant kunj 100 120 10 Shivamtravels 1000002 Hauz Khas 80 80 10 Anand travels 850003 Pitampura 60 55 30 Anand travels 600004 Rohini 100 90 35 Anand travels 1000005 Yamuna Vihar 50 60 20 Bhalla Co. 550006 Krishna Nagar 70 80 30 Yadav Co. 800007 Vasundhara 100 110 20 Yadav Co. 1000008 Paschim Vihar 40 40 20 Speed travels 550009 Saket 120 120 10 Speed travels 10000010 Jank Puri 100 100 20 Kisan Tours 95000

(b) To show all information of students where capacity is more than the no of student in order of rtno.(c) To show area_covered for buses covering more than 20 km., but charges less then 80000.(d) To show transporter wise total no. of students traveling. (e) To show rtno, area_covered and average cost per student for all routes where average cost per student is -

charges/noofstudents.(f) Add a new record with following data:

(11, “ Moti bagh”,35,32,10,” kisan tours “, 35000) (g) Give the output considering the original relation as given:

(i) select sum(distance) from schoolbus where transporter= “ Yadav travels”;(ii) select min(noofstudents) from schoolbus;

(iii) select avg(charges) from schoolbus where transporter= “ Anand travels”;(i) select distinct transporter from schoolbus;

4.TABLE : GRADUATE

S.NO NAME STIPEND SUBJECT AVERAGE DIV.1 KARAN 400 PHYSICS 68 I2 DIWAKAR 450 COMP. Sc. 68 I3 DIVYA 300 CHEMISTRY 62 I4 REKHA 350 PHYSICS 63 I5 ARJUN 500 MATHS 70 I6 SABINA 400 CEHMISTRY 55 II7 JOHN 250 PHYSICS 64 I

Page 90: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

8 ROBERT 450 MATHS 68 I9 RUBINA 500 COMP. Sc. 62 I10 VIKAS 400 MATHS 57 II

(a) List the names of those students who have obtained DIV 1 sorted by NAME.(b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year

assuming that the STIPEND is paid every month.(c) To count the number of students who are either PHYSICS or COMPUTER SC graduates.(d) To insert a new row in the GRADUATE table: 11,”KAJOL”, 300, “computer sc”, 75, 1

(e) Give the output of following sql statement based on table GRADUATE:(i) Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;(ii) Select SUM(STIPEND) from GRADUATE WHERE div=2;(iii) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;(iv) Select COUNT(distinct SUBDJECT) from GRADUATE;

(f) Assume that there is one more table GUIDE in the database as shown below:Table: GUIDE

g) What will be the output of the following query:SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT= MAINAREA;

5. Write SQL command for (i) to (vii) on the basis of the table SPORTSTable: SPORTS

(a) Display the names of the students who have

grade ‘C’ in either

Game1 or Game2 or both.

(b) Display the number of students getting grade ‘A’ in Cricket.(c) Display the names of the students who have same game for both Game1 and Game2.(d) Display the games taken up by the students, whose name starts with ‘A’.(e) Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’ in both Game1 and

Game2.(f) Arrange the whole table in the alphabetical order of Name.(g) Add a new column named ‘Marks’. 6. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables

Table: VEHICLE VCODE VEHICLETYPE PERKMV01 VOLVO BUS 150V02 AC DELUXE BUS 125V03 ORDINARY BUS 80

MAINAREA ADVISORPHYSICS VINODCOMPUTER SC ALOKCHEMISTRY RAJANMATHEMATICS MAHESH

Student NO Class Name Game1 Grade Game2 Grade210 7 Sammer Cricket B Swimmin

gA

11 8 Sujit Tennis A Skating C12 7 Kamal Swimming B Football B13 7 Venna Tennis C Tennis A14 9 Archana Basketball A Cricket A15 10 Arpit Cricket A Atheletics C

Page 91: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

V05 SUV 30V04 CAR 18 Note: PERKM is Freight Charges per kilometer Table: TRAVEL CNO CNAME TRAVELDAT

EKM VCODE NOP

101   K.Niwal   20151213   200 V01 32103 redrick Sym 20160321 120 V03 45105 Hitesh Jain 20160423 450 V02 42102 Ravi Anish 20160113 80 V02 40107 John Malina 20150210 65 V04 2104 Sahanubhuti 20160128 90 V05 4106 Ramesh Jaya 20160406 100 V01 25 Note: ● Km is Kilometers travelled ● NOP is number of passengers travelled in vehicle(i) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending order of CNO.(ii) To display the CNAME of all the customers from the table TRAVEL who are traveling by vehicle with code V01 or V02.(iii) To display the CNO and CNAME of those customers from the table TRAVEL who travelled between ‘2015‐12‐31’ and ‘2015‐05‐01’.(iv) To display all the details from table TRAVEL for the customers, who have travel distance more than 120 KM in ascending order of NOP.(v) SELECT COUNT(*),VCODE FROM TRAVEL  GROUP BY VCODE HAVING COUNT(*)>1(vi) SELECT DISTINCT VCODE FROM TRAVEL(vii) SELECT  A.VCODE, CNAME, VEHICLETYPE   FROM TRAVEL A,VEHICLE  B  WHERE  A.VCODE = B.VCODE  AND  KM<90(viii) SELECT CNAME,KM*PERKM   FROM TRAVEL A,VEHICLE B  WHERE A.VCODE=B.VCODE AND A.VCODE=’V05’

Page 92: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

BOOLEAN ALGEBRA MARKING SCHEME

UNIT TOPICS MARKS

BOOLEAN ALGEBRA LAWS OF BOOLEAN ALGEBRA

2M

WRITING SOP/POS FROM TRUTH TABLE

1M

SOLVING K-MAP 3M

WRITING EXPRESSION FROM LOGIC CIRCUITS

2M

UNIT 4 : Boolean Algebra : 2 Marks Questions

1. Write the equivalent Boolean Expression for the following Logic Circuit

2. Write the equivalent Boolean Expression F for the following circuit diagram :

3. Write the equivalent Boolean Expression F for the following circuit diagram :

4. Convert the following Boolean expression into its equivalent Canonical Sum of

Product Form((SOP)

(X’+Y+Z’).(X’+Y+Z).(X’+Y’+Z).(X’+Y’+Z’)

Page 93: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

5. Convert the following Boolean expression into its equivalent Canonical Product

of Sum form (POS):

A.B’.C + A’.B.C +A’.B.C’

6. Draw a Logical Circuit Diagram for the following Boolean Expression:

A.(B+C’)

7. Write the equivalent Boolean Expression F for the following circuit diagram :

8. Prove that XY+YZ+YZ’=Y algebraically

9. Express the F(X,Z)=X+X’Z into canonical SOP form.

10. Write the equivalent Boolean Expression for the following Logic Circuit.

11. Interpret the following logical circuit as Boolean expression

12. Design (A+B).(C+D) using NAND Gate

13. Simplify the following Boolean Expression using Boolean postulates and laws of

Boolean Algebra.

Z=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)

Page 94: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

14. Prove x’.y’+y.z = x’yz+x’yz’+xyz+x’yz algebraically.

15. Prove that (a’+b’)(a’+b)(a+b’)=a’b’.

16. A Boolean function F defined on three input variable X,Y,Z is 1 if and only if the number of 1(One) input is odd (e.g. F is 1 if X=1,Y=0,Z=0). Draw the truth table for the above function and express it in canonical sum of product form.

3 Marks Questions : Boolean Algebra

1. If F(a,b,c,d)=_(0,2,4,5,7,8,10,12,13,15), obtain the simplified form using K-Map.

2. If F(a,b,c,d) = _ (0,1,3,4,5,7,8,9,11,12,13,15), obtain the simplified form using KMap

3. Obtain a simplified form for a boolean expression

F(U,V,W,Z)= _ (0,1,3,5,6,7,10,14,15)

4. Reduce the following boolean expression using K-Map

F(A,B,C,D) = _ (5,6,7,8,9,12,13,14,15)

5. Reduce the following Boolean expression using K-Map:

F(A,B,C,D)=_(0,1,2,4,5,8,9,10,11)

6. Reduce the following Boolean expression using K – Map

F (A, B, C, D) =(0,2,3,4,6,7,8,10,12)

7. Reduce the following Boolean Expression using K-Map:

F(A,B,C,D)= _(0,1,2,4,5,6,8,10)

Answers: 2 Marks Questions : Boolean Algebra

1. F(P,Q)=(P'+Q).(P+Q')

2. A’B+AB+AB’

3. X’(Y’+Z)

4.

F( X , Y , Z ) = (4 , 5 , 6 , 7)

= (0 , 1 , 2 , 3)

= X’. Y’. Z’ + X’. Y’. Z + X’. Y. Z’ + X’. Y. Z

5. A.B’.C + A’.B.C +A’.B.C’ = _(0,1,4,6,7) OR =(A+B+C).(A+B+C’).(A’+B+C).(A’+B’+C).(A’+B’+C’)

6.

Page 95: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

7. (A+C)(A’+B)

8. XY+YZ+YZ’=Y

L.H.S.

XY+YZ+YZ’

= XY+Y(Z+Z’)

=XY+Y=Y(X+1)

=Y.1

=Y=RHS

9. F(X,Z)=X+X’Z =X(Y+Y’)+X’(Y+Y’)Z

=XY+XY’+X’YZ+X’Y’Z

=XY(Z+Z’)+XY’(Z+Z’)+X’YZ+X’Y’Z

=XYZ+XYZ’+XY’Z+XY’Z’+X’YZ+X’Y’Z

10. XY+(XY)’+X’

11. ab+b’c+c’e’

12.

13. Z=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)

RHS=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)

=a’bc+ab’c+ab’c’+ab.1

=a’bc+ab’c’+ab’c

=ab’(c+c’)+ab’c

=ab’+ab’c

=ab’(1+c)

Page 96: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

=ab’

14. L.H.S.= x’y +y.z

=x’y.1+1.y.z =x’y(z+z’)+(x+x’)y.z

=x’yz+x’yz’+xyz+x’yz =RHS

15. LHS=(a’+b’)(a’+b)(a+b’)

=(a’a’+a’b+a’b’+b’b)(a+b’)

=(a’+a’b+a’b’+0)(a+b’)

=aa’+a’b’+aa’b+a’bb’+a’ab’+a’b’b’

=0+a’b’+0+)+0+0+a’b’=a’b’=RHS

16.

X Y Z F

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

Canonical SOP

XYZ’+XY’Z+XY’Z’+XYZ

UNIT 4 : Boolean Algebra : 1 Marks Questions

1. Define Binary logic ?

2. What is a Boolean Operation ?

3. Define a boolean function ?

4. Define a Boolean Expression ?

5. Name the three primary and secondary operators of Boolean Algebra ?State any four postulates of boolean algebra ?

6. Define Idempotent Law ?

Page 97: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

7. Define Absorptive Law ?

8. Define Involution Law ?

9. What is De Morgan’s Theorem ?

10. State the principle of duality ?

11. State the steps required to calculate the dual of any expression ?

12. State the dual of : A+A’ = 1

13. What is a Boolean Function ?

14. Define the Sum Of Products format of a boolean expression ?

15. Define the Product of Sums format of a boolean expression ?

16. What is a Karnaugh map ?

17. Draw the truth table of NAND gate ?

18. Define the XNOR gate ?

19. What is a Half Adder ?

20. What is a Full Adder ?

21. Differentiate between an Encoder and a Decoder ?

22. What are Universal Gates ? Name any two Universal Gates ?

23. Define the working of a XOR gate ?

24. What is a Multiplexer ?

25. What is a Multivibrator ?

26. What is a Minterm ?

27. What is a Maxterm ?

28. What is a Canonical Sum of Products ?

29. What is a Canonical Product of Sums ?

30. State the total number of combinations possible for a three input gate ?

31. Draw a logical circuit diagram for the following Boolean expression: A.(B+C)’

32. Convert the following Boolean expression into its equivalent Canonical Sum of Products Form

(U’+V’+W’). (U+V’+W’). (U+V+W)

33. Draw the Logical Circuit Diagram for the following Boolean Expression: ( A’.B’).+(C.D’)

34. Write the equivalent Canonical Product of Sum for the following expression.

Page 98: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

F(A,B,C) = ∑(1,2,3,4)

35. Write the SOP form of a Boolean function G, which is represented in a truth table as follows:

P Q R (G)0 0 0 10 0 1 00 1 0 00 1 1 11 0 0 11 0 1 01 1 0 01 1 1 0

36. Write the equivalent Boolean expression for the following Logic Circuit:U

V

37. Write the equivalent Boolean expression for the following Circuit

38. For the given truth table, give canonical sum-of-products(SOP) and canonical product-of- sum (POS) expression

X Y Z F o/p

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 0

Page 99: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 1

39. Write the principal of Duality and write the dual of the Boolean Expression:

(B` + C) + A`

40. Interpret the following logical circuit as Boolean expression.

42. Prove that XY+YZ+YZ’=Y

43. Write the equivalent Boolean expression for the following logic circuit.

44. Express the F(X,Z)=X+X’Z into canonical SOP form.

45. Write the equivalent canonical POS expression for the following SOP expression: F(x,y,z)=Σ(0,2,5,6)

Boolean Algebra : 3/4 Marks Questions

b

a

e

c

Page 100: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

1. Reduce the following Boolean expression using K-map.

F(A, B, C, D)= (0, 1, 2, 4, 5, 7, 8, 9, 10, 11, 14)

2. Reduce the following Boolean expression using the K-map. (3)

F(A,B,C,D)= Σ(0,1,3,4,7,8,11,12,15);

3. If F(a,b,c,d)= Σ (1,3,4,5,7,9,11,12,13,15) obtain the simplified form using K-Map

4. Reduce the following Boolean expression using K-map: H(U, V, W, Z) = (0, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15)

5. Reduce the following Boolean expression using K-map:H(U, V, W, Z) = (0, 1, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15)

6. Reduce the following Boolean expression using K-Map

F(A,B,C,D) = ∑ (0,1,3,4,5,7,8,9,11,12,13,15) obtain the simplified form using K-Map.

7. Reduce the following Boolean expression using K-map

F(A,B,C,D)= (1,3,4,5,7,9,11,12,13,14

Answers: 3 marks Questions

Boolean Algebra

1.

The Final Expression is F=c’d’+bd+b’c’d

2.

Page 101: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

3.

The POS form is (U+Z’).(V’+W’).(U+V+W).(U’+W’+Z)

10 do yourself

4.

5.

Page 102: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

6.

Q NO. 6 BOOLEAN ALGEBRA

Q PAPER2014

Question 6 :

Na NName the law shown below and verify it using a truth table.

A+B.C = (A+B).(A+C)(b) Obtain the Boolean Expression for the logic circuit shown below:

(8 Marks)

Page 103: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(c) Write the Sum of Product form of the function F(P,Q,R) for the following truth table representation of F:

P Q R F

0 0 0 1

0 0 1 00 1 0 00 1 1 11 0 0 0

1 0 1 01 1 0 11 1 1 1

(d) Obtain the minimal form for the following Boolean expression using Karnaugh’s Map.F(A,B,C,D)= ∑ (1, 4, 5, 9, 11, 12, 13, 15)

[2+2+1+3=8]

ANSWERSAnswer 6 : (8 Marks)

(a)    According to the Distributive Law :

1.  First LawA(B+C)= (A.B+A.C)

2.  Second LawA+B.C= (A+B).(A+C)

Therefore the equation A+B.C = (A+B).(A+C) indicates second distributive law.

Page 104: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Hence verified.(b)

Boolean expression for the given logic circuit will be:(X’+Y)+(Z’+W)

(c)  The Sum of Product form will be:P’Q’R’ + P’QR+PQR’+PQR

(d) Karnaugh’s Map for the equation given below-F(A,B,C,D)= ∑ (1, 4, 5, 9, 11, 12, 13, 15)

Q PAPER 2013

Question 6 :

(a) Verify the following using Boolean Laws:

X+Z = X+X’.Z + Y.Z

(b) Obtain the Boolean Expression for the logic circuit shown below:

Page 105: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

 

(c) Write the sum of the product form of the function F(A,B,C) for the following truth table representation

of F.

A B C F

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

(d) Obtain the minimal form for the following Boolean expression using Karnaugh’s map.

F(U,V,W,Z) = ∑(0, 1, 2, 3, 6, 7, 8, 9, 10, 13, 15)

[2+2+1+3 = 8](8 Marks)

ANSWERS

Answer 6 : (8 Marks)

(a). X + Z = X + X’. Z + Y . Z

= (X + X’) (X + Z) + Y . Z

= X + Z + Y . Z

= X + Z(1+Y)

= X + Z [Hence verified]

(b)  F = (P’.Q) + (Q+R’) 

(c) F = A’.B.C’ + A’.B.C + A.B’.C’ + ABC

(d) F(U,V,W,Z)= ∑(0, 1, 2, 3, 6, 7, 8, 9, 10, 13, 15)

Page 106: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Quard 1: U’V’

Quard 2: U’W

Quard 3: V’W’

Pair 1: V’WZ’

Pair 2: UVZ

F(U,V,W,Z) = U’V’ + U’W + V’W’ + V’WZ’ +UVZQ PAPER 2012

Question 6 : a) Verify the following using truth table:(i) X.X’=0(ii) X+1=1

b) Write the equivalent Boolean expression for the following Logic Circuit:

Page 107: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

c) Write the SOP form of a Boolean function F, which is represented in a truth table as follows:X Y Z F

0 0 0 1

0 0 1 0

0 1 0 1

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

d) Reduce the following Boolean Expression using K-Map:F(A,B,C,D)=∑(2,3,4,5,6,7,8,10,11)[2+2+1+3 =8]

ANSWERS

Answer 6 : (8 Marks)(a). (i) Truth table for X.X’=0 

The AND operator results in 1 only when all the inputs will be 1.

X X’ X.X’

0 1 0

Page 108: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

1 0 0

Hence X.X’=0 is proved.

(ii) Truth table for X+1=1 The OR operator results in 0 only when all the inputs will be 0.

X 1 X+1

0 1 1

1 1 1

Hence  X+1= 1 is proved.(b). Boolean Expression for given logic circuit is:

F = UV’ + U’W’(c).  SOP form of the Boolean function F is :

F = X’Y’Y’ + X’YZ’ + XY’Z’ + XYZd) F(A,B,C,D) = ∑(2,3,4,5,6,7,8,10,11)

As shown above, here we have 3 Quad and 1 pair.Reducing Quad1 = A’CReducing Quad2 = A’B

Page 109: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Reducing Quad3 = B’CReducing Pair 1 = AB’D’

Hence final reduced Boolean expression is:

F = A’C + A’B + B’C + AB’D’Q PAPER 2011

Question 6 : a) Verify the following using Truth Table: X + Y . Z = (X+Y).(X+Z)

b) Write the equivalent Boolean expression for the following Logic Circuit: 

c) Write the SOP form of a Boolean function F, which is represented in a truth table as follows:U V W F0 0 0 10 0 1 00 1 0 00 1 1 11 0 0 01 0 1 01 1 0 11 1 1 1

d) Reduce the following Boolean Expression using K-Map:F(A,B,C,D) = (0,1,2,4,5,6,8,9,10)

[2+2+1+3 = 8]ANSWERS

Answer 6 : (8 Marks)(a)

X Y Z X+Y X+Z X+Y.Z (X+Y).(X+Z)0 0 0 0 0 0 00 0 1 0 1 0 00 1 0 1 0 0 00 1 1 1 1 1 11 0 0 1 1 1 11 0 1 1 1 1 11 1 0 1 1 1 11 1 1 1 1 1 1

(b) P.Q’ + P.R’

(8 Marks)

Page 110: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(c) U'V'W' + U'VW + UVW' + UVW

(d) 

A’B’C’D’ + A’B’C’D + A’BC’D’ + A’BC’D + A’B’CD’ + A’BCD’ + A’B’C’D’ + A’B’CD’ + AB’C’D’ + AB’CD’= > A’C’ + B’D’ + A’D’C

Q PAPER 2010Question 6 :

a) Verify the following algebraically. (2)( A ’ + B ’ ) . ( A + B)= A ’. B + A . B ’

b) Write the equivalent Boolean Expression for the following Logical circuit: (2)

c) Write POS from a Boolean function H, which is represented in a truth table as follows:

d) Reduce the following expression by using K-Map. (3)F (U,V,W,Z) =  (3,5,7,10,11,13,15)

X Y Z H

0 0 0 1

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

Page 111: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

ANSWERS

Answer 6 : (8 Marks)a) LHS = ( A ’ + B ’ ) . (A+B)

= A ’ . A + A ’ . B + A . B ’ + B ’. B= 0 + A ’ .B + A . B ’ + 0

= A ’ . B + A . B ’= RHS (Verified)

b) ( P + Q ’ ) .  ( Q + R ’ )

c) The POS form is:( X+Y+Z ’ ) . ( X ’+Y+Z ’ ) .(X ’+ Y ’+Z )

d)   F(U,V,W,Z) = WZ+VZ+UV'W

Q PAPER 2009

Question 6 : (a) State and verify absorption law using truth table. [2] 

(b) Write the equivalent Boolean Expression for the following Logic Circuit: [2 ]

c) Write the POS from of a Boolean function G, which is represented in a truth table as follows: [1]U V W G0 0 0 10 0 1 10 1 0 00 1 1 01 0 0 11 0 1 11 1 0 01 1 1 1

(d) Reduce the following Boolean Expression using K-Map: [3]

Page 112: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

H(U,V,W,Z)=(0,1,4,5,6,7,11,12,13,14,15)ANSWERS

Answer 6 : (8 Marks)a) Absorption Law:-    According to absorption law,X+XY=XX(X+Y)=XThe two parts of the absorption law are sometimes called the "absorption identities".Verification of Absorption Law by truth table:

Thus, we can see in the table that:X+XY=X andX(X+Y)=X. 

(b)   The equivalent Boolean expression for the following logic circuit is:P Q+P R

(c)    To obtain the POS form of function G, add a new column to the truth table: 

By multiplying the maxterms for 0’s, we get the desired product of sums expression, that 

is:  

(d) Using K-MAP: 

Page 113: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Now, pairing 1’s to form oct, quad , we get the following figure:

Hence, Resultant expressionV+ U’W’ + UWZ

Q PAPER 2008

Question 6 : (a) State and verify De Morgan’s law in Boolean Algebra. [2](b) Draw a logical circuit diagram for the following Boolean Expression.X’. ( Y’ + Z) [1](c) Convert the following Boolean expression into its equivalent Canonical sum of products form. [2](X’+ Y + Z’). (X’+ Y + Z) . (X’+ Y’ + Z’)(d) Reduce the following Boolean expression using K-Map.  [3]

F(A, B, C, D) =   ( 0,2,3,4,6,7,8,10,12)

ANSWERS

Answer 6 : (8 Marks)a) According to Demorgan’s law1) The complement of the sum is equal to the product of the complement.2) The complement of the product is equal to the sum of the complement. 

(a+b)’=a’.b’(a.b)’=a’+b’(a+b) + (a’ . b’) = 1 (a+b) + (a’ . b’) =(a+(a’.b’)) + (b +(a’.b’))  distributivity =(a+a’).(a+b’)+(b+a’).(b+b’)       distributivity=1.(a+b’)+(a’+b).1                      inverse axiom + commutative=a+b’+a’+b                                 unit property=a+a’+b+b’                                 commutativity=1+1                                           inverse axiom= 1                                              unit axiom

ab + (a’ + b’) = 1 ab + (a’ + b’) = ((a’ + b’) + a)((a’ + b’) + b)   commutativity + distributivity = (a + (a’ + b’))((a’ + b’) +b)     commutativity= ((a + a’) + b’)(a’ + (b + b’))    associativity + commutativity= (1 + b’)(a’ + 1)                       inverse axiom= 11                                          unit property= 1                                            unit axiom

(b) Logical circuit for X’. (Y’+Z) is:

Page 114: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(c) Conversion of the Boolean expression into its equivalent Canonical SOP form with the help of a truth table:            (X’+ Y + Z’). (X’+ Y + Z) . (X’+ Y’ + Z’)

X Y Z MINTERM MAXTERM0 0 0 X’.Y’.Z’0 0 1 X’. Y’. Z0 1 0 X’.Y.Z’0 1 1 X’.Y.Z1 0 0 X’+Y+Z1 0 1 X’+Y+Z’1 1 0 X’+Y’+Z1 1 1 X’+Y’+Z’

POS FORM=( X’+Y+Z’). (X’+Y+Z) . (X’+Y’+Z). (X’+Y’+Z’)SOP FPRM=( X’.Y’.Z’) + (X’. Y’. Z) + (X’.Y.Z’) + (X’.Y.Z)

(d) Using K-Map:

F=C’D’+ A’C + AB’CD’

COMMUNICATION AND NETWORK CONCEPTS

TYPE A: VERY SHORT ANSWER QUESTION

1. Define a network. What is its need? Ans. A network is an interconnected collection of autonomous computer that can share and exchange information.

Need for networking: Resourcesharing (Processing, Peripherals, Information and software)

Page 115: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Communication between computers 2. Write two advantage and disadvantage of networks. Ans. Advantage:

We can share resources such as printers and scanners. Can share data and access file from anycomputer. Disadvantage: Server faults stop applications from being available. Network faults can cause loss of data.

3. What is ARPAnet ? What is NSFnet ? Ans. ARPAnet (Advanced Research Project Agency Network is a project sponsored by U. S. Department of

Defense.NSFnet was developed by the National Science Foundation which was high capacity network and strictly used foracademic and engineering research.

4. Whatdo you understand by InterSpace? Ans. Interspace is a client/server software program that allows multiple users to communicate online with real-time

audio, video and text chat I dynamic 3D environments.5. Name two switching circuits and explain any one.Ans. The two switching circuits are

2. Circuit Switching 3. Message Switching

Circuit Switching - In this technique, first the complete physical connection between two computers is established and then data are transmitted from the source computer to the destination computer.

6. What is communication channel? Name the basic types of communication channels available. Communication channel mean the connecting cables that link various workstations.

Ans. Following are three basic types of communication channels available:a) Twisted-Pair Cables b) Coaxial Cables c) Fiber-optic Cables

7. Define baud, bps and Bps. How are these interlinked? Ans. Baud is a unit of measurement for the information carrying capacity of a communication channel.

bps- bits per second. It refers to a thousand bits transmitted per second.Bps- Bytes per second. It refers to a thousand bytes transmitted per second.

All these terms are measurement units used to refer to the amount of information travelling through a

single channel at any one point of time.8. What are the various types of networks? Ans. There are three types of networks :

i. Local Area Networks (LANs) ii. Metropolitan Area Network (MAN) iii. Wide Area Networks (WAN)

9. What is the differencebetween MAN and WAN? Ans. MANs arethe networks that link computer facilities within a

city.WANs are the networks spread over large distances.

10. What is meant by topology? Name some popular topologies. Ans. Topology refers to the way in which the workstations attached to the network are interconnected. The most

popular topologies are :

Page 116: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(a) Bus or Linear Topology (b) Ring Topology (c) Star Topology (d) Tree Topology

11. What are the factors that must be considered before making a choice for the topology? There arenumber of factors to consider in before making a choice for the topology, the most important of which

Ans. are as following :(a) Cost. (b) Flexibility (c) Reliability

12. What are the similarities and differences between bus and tree topologies? Ans. Similarities :

Inboth Bus and Tree topologies transmission can be done in both the directions, and can be received by allother stations.

In both cases, there is no need to remove packets from the medium.Differences : Bus topology is slower as compared to tree topology of network.Tree topology is expensive as compared to Bus Topology

13. What are the limitations of star topology? Ans. Requires more cable length than a linear

topology. If the hub, switch, or concentrator fails, nodes attached are disabled. Moreexpensive than linear bus topologies because of the cost of the hubs, etc.

14. When do you think, ring topology becomes the best choice for a network? Ans. Ring topology becomes the best choice for a network when,

Short amount of cable is required. No wiring closetspace requires.

15. Write the two advantages and two disadvantages of Bus Topology in network. Ans. Advantage:

Easy to connect a computer or peripheral to a linear bus. Requires less cable length than a star topology. Disadvantage : Slower ascompared to tree and star topologies of network Breakage of wire at any point disturbs the entire network

16. Briefly mention two advantages and two disadvantages of Star Topology in network. Advantage:

Ans. Easy to install and wire. No disruptions to the network when connecting or removing devices. Disadvantage : Requires more cable length than a linear topology. If the hub, switch, or concentrator fails, nodes attached are disabled.

17. Give two advantages and twodisadvantages of following network topologies : (i)Star (ii)Tree

Ans.Star Topology Tree TopologyAdvantage : Advantage :Easy to install and wire. Faster as compared toBus Topology.

No disruptions to the network whenEasier to set-up for multi-floor plans of

connecting or removing devices. network.

Page 117: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Disadvantage : Disadvantage :Requires more cable length than a linear

Slower as compared to Star Topology.

topology. Expensive as compared to BusExpensive as compared to Bus Topology Topology.

Page 118: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

18.

Ans.

19.

Ans.

20.

Ans.

21.Ans.

22.

Ans.

23.

Page 119: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Give two advantages and two disadvantages of following network topologies :(i)Bus (ii)Tree BusTopology

Advantage: Easy to connect a computer or peripheral to a linear bus. Requires less cable length than a startopology. Disadvantage: Slower as compared to tree and star topologies of network Breakage of wire at any point disturbs the entire network TreeTopology Advantage: Faster as compared to Bus Topology. Easier to set-up for multi-floor plans of network. Disadvantage: Slower as compared to Star Topology. Expensive as compared to Bus Topology. Write two advantages and disadvantages of following :(i)Optical fibers (ii) Satellites (iii) Microwaves. Advantage:

Optical fibers Satellites MicrowavesIt is guarantees secure transmission. Large area coverage of earth. Free from land acquisition rights.It is very high transmission capacity

Inexpensive compare to cable.

Ability to communicate over oceans.

Disadvantage :Optical fibers Satellites MicrowavesExpensive. Require high investment in case off failure. Insecure Communication.Hard to install. Requires legal permissions. Limited bandwidth.

Write two disadvantages of twisted paircables.Disadvantage : It is not capable to carrying signal to long distance. It connects only up to 100 meters. What is modem? Name two categories of modems.Modem is a device that converts digital communication signals toanalog communication digital signals andvice versa.Following are the two categories of modems.1) Internal Modem (Fixed with computer) 2) External Modem (Connect externally to computer). Define the following :(i)RJ-45 (ii)Ethernet (iii) Ethernet card (iv)hub (v)Switch

(i) RJ-45: RJ45 is a standard type of connector for network cables and networks. It is an 8-pin connector usually used with Ethernet cables.(ii)Ethernet: Ethernet is a LAN architecture developed by Xerox Corp alongwith DEC and Intel. It uses a Bus or Star topology and supports data transfer rates of up to 10 Mbps.(iii)Ethernet card: The computersparts of Ethernet areconnected through a special card called Ethernet card. It contains connections for either coaxialor twisted pair cables.(iv)Hub: In computer networking, a hub is a small, simple, low cost device that joins multiple computers together. (v)Switch: ASwitchis a small hardware device that joins multiple computers together within one local area network (LAN).Define the following :(i)Protocol (ii) Host (iii) Repeater (iv) Bridge (v) Router (vi) Gateway.

Page 120: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans.

24.Ans.

25.Ans.

26.Ans.

27.Ans.

28.Ans.

29.Ans.

(i)Protocol: Aprotocolis adescription of the rules and message formats that computers must follow to communicate with each other.(ii)Host: The computer system providing the web-hosting is known as the web host. It allows their customers to place web documents onto a special type of computer called a web server.(iii)Repeater: It is a device that amplifies and restores the power of a signal being transmitted on the network.. (iv)Bridge: A bridge is a device designed to connect two LAN segments. The purpose of a bridge is to filter traffic on a LAN.(v)Router: A router is a networking device whose software and hardware are usually tailored to the tasks of routing and forwarding information.(vi)Gateway: Anetwork gatewayisa computer which hasinternetworkingcapability of joining together two networks that use different base protocols.What is remote login? What is Telnet?Remote login: Remote login is the process of accessinga network from a remote place without actually being at the actual place of working.Telnet: Telnet is an Internet utility that lets you log onto remote computer system.Briefly explain file transfer protocol. FTP stands forFileTransferProtocol. FTP can transfer any type of file between two computers. Also used as a command such as FTP ftp.cbsecsnip.in What is Internet? What is E-mail?Internet: The Internet is a worldwide network of computer networks around the globe.E-mail: E-mail or electronic mail is sending and receiving of messages by a computer.What are the advantages of E-mail? Whatare the disadvantages of E-mail?Advantage: Low cost. Speed. Waste reduction.

Disadvantage: Computerliteracy. Sent mail can bechanged or deleted. Easy to sent a message that you latter regret. Hard to express emotions.

What is structure of an E-mailmessage?An electronic mail messages is structured very much like a paper letter.In mail message, there are three parts: The header – is the envelope, The body – is the actual message, The signature – comes at the

end. Some common header lines include : To: The recipient(s) of the message. Date: The date the message was sent. From: The person who sent the message. Cc: Thepeople who were mailed copies of the message.

What isHTML?Where it isused?HTML (Hyper Text Markup Language)which isused to create Hypertext documents(web pages)for websites.HTML is the static markup language. It is used to create WebPages. Tells the browser how to display text, pictures and other support media. Support multimedia and new page layout features. Provides may tags for control the presentation of information on the web pages, such as <body>,

Page 121: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

<li>,

<hr> etc.

Page 122: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

30. Whatis URL? What is WWW?

Ans.URL: URL(UniversalResourceLocater) specifies the distinct address for each resource on the Internet, such as ftp,http etc.WWW: WWW (World Wide Web)is a set of protocol that allows you to access any document on the Internetthrough a naming system based on URL’s.

31. What is protocol? Name some commonly used protocols. Ans. A protocol means the rules that are applicable for a network or we can say that the common set of rules used for

communication in network.Different types ofprotocols are :

(i) HTTP : Hyper Text Transfer Protocol (ii) FTP : File Transfer Protocol (iii) SLIP : Serial Line Internet Protocol (iv) PPP : Point to Point Protocol (v) TCP/IP : Transmission Control Protocol/ Internet Protocol (vi) NTP : Network Time Protocol (vii) SMTP : Simple Mail Transfer Protocol (viii) POP : Post Office Protocol (ix) IMAP : Internet Mail Access Protocol

32. What is TCP/IP? What is HTTP? Ans. TCP/IP (Transmission Control Protocol / Internet Protocol): A protocol for communication between

computersused as a standard fortransmitting data over networks and is the basis for standard Internet protocols.HTTP(Hyper Text Transfer Protocol) : An application level protocol with the lightness and speed necessary fordistributed, shared, hypermedia information systems

33. Define Mobile Communication and Wireless Communication. Ans. Mobile Communication essentially refers to a computing device that is not continuously connected to the

base orcentral network. This may include laptops, newly created smart phones and also PDA’s.Wireless Communication is simply data communication without the use of a landline. This may involve a cellulartelephone, a two way radio, a fixed wireless connection, a laser, or satellite communications.

34. Define GSM, CDMA,and WLL. Ans. GSM: GSM (Globalsystem for mobile communication) is a wide area wireless communications System

that usesdigital radio transmission to provide voice data and multimedia communication services. A GSM systemcoordinates the communication between mobile telephones, base stations, and switching systems.CDMA: CDMA (Code Division Multiple Access) is a digital wireless telephony transmission technique, which allowsmultiple frequencies to be used simultaneously – Spread Spectrum.WLL: WLL (Wireless in Local Loop) is a system that connects subscriber to the public switched telephone network(PSTN) using radio signal as alternate for other connecting media.

35. Define the following: (i)3G (ii)EDGE (iii)SMS (iv)TDMA Ans. (i) 3G: 3G (Third Generation) mobile communication technology is a broadband, packet-based

transmission oftext, digitized voice, video and multimedia at data rates up to 2 mbps, offering a consistent set of services tomobile computer and phone users no matter where they are located in the world.(ii)EDGE: EDGE (Enhanced Data rates for Global Evolution) is radio based high-speed of mobile data

Page 123: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

standard,developed specifically to meet the bandwidth needs of 3G.(iii)SMS: SMS (Short Message Service) is the transmission of short text messages to and from a mobile phone, faxmachine and IP address.(iv)TDMA: TDMA (Time Division Multiple Access) is a technology for delivering digital wireless service using time-divisionmultiplexing (TDM).

36. What is Voice-Mail? What is Chatting? Ans. Voice-Mail: The voice-mailrefers to e-mail system that support audio. User can leave spoken

message for oneanother and listen to the messages by executing the appropriate command in the e-mail system.Chatting: It is an application to communicate with a person, a group, or a site on the Internet in real time bytyping text. The text appears on the screen(s) of all the other participants in the “chat”.

37. What is Video conferencing?

Page 124: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans. It is a conference between two or more participants at different locations over the Internet or a private network.

Each user has a video camera, microphone, and speakers mounted on his or her computer. As the participants speak to one another, they hear each other’s voices and see a video image of the other participant(s).

38. Define webbrowser and webserver.

Ans.Web Browser: AWeb Browserissoftware which used for displaying the content on web page(s). It is used byclient to view web sites. Example of Web browser – Google Chrome, Fire Fox, Internet Explorer, Safari, Opera, etc.Web Server: AWeb Serveris software which fulfills the request(s) done by web browser. Web server havedifferent ports to handle different request from web browser like generally FTP request is handle at Port 110 andHTTP request is handle at Port 80. Example of Web server are – Apache, IIS

39. What is web hosting?Ans. Web Hostingis a means of hosting web-server application on a computer system through which electronic

content on the Internet is readily available to any web- browser client.40. What is hacking? Ans. Hacking is process of accessing of a computer system or network without knowing the access authorization

credential of that system. Hacking can be illegal or ethical depending on the intention of the hacker.41. (a) What is purpose of using a gateway in context of networking?Ans. In network gateway is used to connect dissimilar networks. It establishes an intelligent connection between a

local network and external networks with completely different structures.

(b) Write an advantage and a disadvantage of using Optical fibercable. Ans. Advantages : Disadvantages :

Secure transmission. Expensive.

Low attenuation.Difficult to connect tofibers.

No EMI interference. Hard to install.Very high transmission capacity. Noise exception.Used for broadband transmission and Connection loss.

possible to mix data transmission Difficult to repair.channels with cannels for telescope, TVetc.

(c) Write one advantage and one disadvantage of following network topologies in network : (i)BUS Topology , (ii)STAR Topology

Ans. BUS Topology STAR TopologyAdvantage : Advantage :Simple architecture. Easy to detect faults and to remove

parts.Disadvantage : Disadvantage:Breakage of wire at any point disturbs

Expensive as compared to Bus Topology

the entire network.(d) What is the difference between LAN and MAN? Ans. LAN MAN

LANs are computer networks confined to a MANs arethe networks that link computer facilitieslocalized area such as an office or a factory. within a city.

42. What is the purpose of using a repeater in context of networking?

Page 125: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans.Purpose of using repeater in context of networkingis to amplify transmission signals when these signal becomeweaker due to long distance transmission.

43. What are cookies? Ans. Cookies are messages that a Web server transmits to a web browser so that the Web server can keep track of the

user’s activity on a specific Web site. Cookies are saved in form of text file in client computer.44. What is cracking? How is it differentfrom hacking? Ans. Cracking is defined as the attempt to remove the copy protections inserted into software programs. A program

successfully stripped of protections is then known as having been "Cracked".

Page 126: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Some of the removed protections include:Time limits, RegistrationScreen,Serial Number.Hacking can be ethical/legal but cracking is totally illegal method also called piracy.

45. What is 80 – 20 rule of network design? Ans. In a properly designed small to medium-sized network, 80 percent of the trafficon a given segment should be

local, and not more than 20 percent should need to move across a backbone link.46. Which of the following (i) is not a broadcast device (ii) offers a dedicated bandwidth? Ans. (a) Repeater (b) bridge (c) hub (d)switch

(i) Bridge(ii) Switch

47. What is web scripting? Ans. A script is a small bit of code that enables web browsers to do something rather than just displaying static

results. Scripts are used in web design to create dynamic pages. There are 2 categories of Web script Client Side Script which can be written by using JavaScript, VB Script and Server Side Script which can be written in PHP, JSP

48. Name some web scripting languages. Ans. There are many scripting languages available today. Most common once are VBScript, JavaScript, ASP, PHP, PERL,

and JSP.49. What is Cyber Crime? Ans. As define in Cambridge dictionary defines Cyber Crimes as Crimes committed with the use of

computers or relating to computers, especially through the Internet.Universally, Cyber Crime is understood as an unlawful act where in the computer is either a tool or a target or both.

50. When was IT Act enforced in India? Ans. In India, IT Act was enforced on 17 October 2000.

TYPE B: SHORT ANSWER QUESTION

Page 127: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

1. What is network? What are its goals and applications? Ans. A network is an interconnected collection of autonomous computer that can share and exchange information.

Network GoalsFollowing are some of thenetwork goals : Resource Sharing Reliability Reduced costs Communication Medium Application of Networks Following are the some of the important applications of network : Sharing Access to remote database Communication facilities

2. Brieflyexplain how Internet evolved. Ans. Evolution of networking started way back in 1969 by the development of first network called

ARPANET.The goal of this project was to connect computers at U. S. defense & different universities.

In 1980’s, the NSFnet was started to make high-capacity network strictly for academic and engineering research

In 1990sthe internetworking of ARPANET, NSFnet and other private networks resulted into Internet.

3. Write a short note on ARPAnet. Ans. Stands for Advanced Research Project Agency Network.

It is a project sponsored by U. S. Department of Defense.Planted in 1969 to connect computers at U. S. defense & different universities.The users of this system were able to exchanging data and messages, play long distance games and

socialize with people who share their interests.In 1980s, NSFnet was started to make high capacity network, which are more capable than ARPANET.

Page 128: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

In 1990s the internetworking of ARPANET, NSFnet and other private networks resulted into internet.

4. Howdoes Internet work? Ans. In Internet, most computers are not connected directly to the Internet. Rather they are connected to

smaller network, which in turn are connected through gateways to the Internet backbone.The reason that Internet works at all is that every computer connected to it uses the same set of rules for communication called protocol.How Internet functions : Firstly the information or file to be sent to another computer is divided into small parts called

Packets. Each packet is given a sequential number e.g. 1,2,3. Then packets are sentto the address of destination computer. The destination computer receives the packets randomly. If packet is lost it is demanded again. Then packets are rearranged in their correct order and get actual information/file.

5. Write a short note on InterSpace. Ans. InterSpace is a client/server software program that allows multiple users to communicate online

with real-time audio, video and text chat I dynamic 3D environments.

Provide most advanced form ofcommunication. It is an application environment for interconnecting spaces to manipulate information. Vision of what Internet become, where users cross-correlates information in multiple ways from

multiple sources. 6. How is circuit switching different from message switching? Ans. Circuit switching – when communication needs to take place, a dedicated path is opened end to end

for the duration of the communication session. An example would be plain old telephone service.Packet switching – is takingdata and breaking it into little packages, or packets. Those packets are then sent across a network. The path that those packets take are not dedicated. So, individual packets may take separate paths on the network to get to the destination. This is how the internet works.

7. How does transmission take place across networks? Ans. Various switching techniques are used to transmit data across networks. These are as following:

Circuit Switching. Message Switching. Packet Switching.

v) What are communication channels? Discuss various communication channels available for networks.

Ans. Communication channel mean the connectingmediasthat link various workstations. Following are three basic types of communication channels available: Twisted-Pair Cables :Thiscable consistsof two insulated copperwires twisted around each other.

These are also used for short and medium range telephone communication. Coaxial Cables : A coaxial cable consists of one or more small cables in protective covering.

These are more expensive than twisted pair cables but perform better. Fiber-optic Cables : These cables are made of plastic or glass and are about as thinas human

hair. These cables are highly durable and offer excellent performance but are expensive. vi) Write some advantages and disadvantages of following :

(i)Opticalfibres (ii) coaxialcables (iii) twistedpair cables (iv) radio waves (v) microwaves (vi) satellites.

Ans. Optical FibresAdvantage DisadvantageSecure transmission. Expensive.Low attenuation. Difficult to connect to fibers.No EMI interference. Hard to install.Very high transmission capacity. Noise exception.

Page 129: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Used for broadband transmission and Connection loss.possible to mix data transmission Difficult to repair.channels with cannels for telescope, TVetc.

Coaxial Cables

Page 130: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

10.Ans.

11.Ans.

Advantage Disadvantage Better data transmission than twisted- Single cable failure can take down an

pair cables. entire network. Used as source for shared cable Expensive

network. Not compatible with twisted pair cables. Used for broadband transmission. Higher bandwidths up to400 mbps.

Twisted Pair CablesAdvantage DisadvantageSimple. Incapable for long distance.Flexible. Unsuitable for long distance.Low weight. Supports maximum data rates 1 mbpsInexpensive. without conditioning and 10 mbps withConnected easily. conditioning.Easy to install and maintain.

Radio WavesAdvantage DisadvantageFree from land acquisition rights.Insecure communication.Provides ease of communicationoverSusceptible to weather effects.

difficult terrain.Provide mobility.Inexpensive

Micro WavesAdvantage DisadvantageInexpensive. Insecure Communication.Free from land acquisition rights.Reduce signal strength.Provides ease of communication overSusceptible to weather effects.

difficult terrain. Limited bandwidth.Ability to communicate over oceans.High cost for implementation and

maintenance.

SatellitesAdvantage DisadvantageLarge area coverage of earth.Cannotdeploy large, High gainInexpensive compare to cable. antennas.Commercial attractive. Overloading of available bandwidths.Useful for sparsely populated areas.Require high investment in case off

failure.High atmospheric losses above 30 GHz

limitcarrier frequencies.Requires legal permissions.

What is bandwidth? How is it measured?Bandwidth is the amount of data that can be transmitted via a given communications Channel in a given unit of time. It exactly shows that how much stuff that you can send through a connection. Bandwidth is measured in kilohertz(KHz), megahertz(MHz),gigahertz(GHz), terahertz(THz).What do you understand by data transfer rates?The speed with which data can be transmitted from one device to another. Data rates are often measured in megabits (million bits) or megabytes (million bytes) per second. These are usually abbreviated as Mbps and

Page 131: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value
Page 132: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

MBps, respectively.12. Discuss and compare various types of networks. Ans. There are three types of networks :

a) LAN (Local Area Network) – A group of computers that shares a common connection and is usually in a small area or even in the same building. For example, it can be an office or a home network. It is usually connected by Ethernet cables and has high speed connections. If it was a wireless setup, it would be called a WLAN, which would have a lower connection speed. b)MAN (Metropolitan Area Network) –This is a larger network that connects computer users in a particular geographic area or region. For example, a large university may have a network so large that it may be classified as a MAN. The MAN network usually exists to provide connectivity to local ISPs, cable TV, or large corporations. It is far larger than a LAN and smaller than a WAN. Also, large cities like London and Sydney, Australia, have metropolitan area networks. c)WAN (Wide Area Network) – This is the largest network and can inter-connect networks throughout the world because it is not restricted to a geographical location. The Internet is an example of a worldwide public WAN. Most WANs exist to connect LANs that are not in the same geographical area. This technology is high speed and very expensive to setup.

13. Explain various mostly used topologies. Ans. 1. Bus or Linear Topology – It is characterized by common transmission medium shared by all the

connected hosts, managed by dedicated nodes. It offers simultaneous flow of data and control.Ring Topology – A ring topologyconnects one host to the next and the last host to the first. This creates a physical ring of cable. Star Topology – It is characterized by central switching mode (communication controller) unique path (point-to-point link) for each host. It is easy to add and remove additional host by upgrading the centralized node. Tree Topology – A tree topology may be defined as a group of bus topologies put together and controlled by one node.

14. Discuss the factors that govern the selection of topology for a network. Ans. There are number of factors that govern the selection of topology for a network, the most important of which

are as following :a) Cost – For a network to be cost effective, one would try to minimize installation cost. This may be

achieved by using well understood media and also, to a lesser extent, by minimizing the distances involved.

b) Flexibility – Because the arrangement of furniture,internal walls etc. in offices areoften subject to change, the topology should allow for easy reconfiguration of the network. This involves moving existing nodes and adding new ones.

c) Reliability – Failure in a network can take two forms. Firstly, an individual node can malfunction. This is not nearly as serious as the second type of fault where the network itself fails to operate. The topology chosen for the network can help by allowing the location of the fault to be detected and to provide some means of isolating it.

15. Compare and contrast (i)Star and Bus topologies (ii)Star and Tree topologies (iii) Bus and Ring topologies

Ans. (i)Star and Bus topologiesComparison : Contrast :In both topologies all devices are Bus topology is slower in contrast to

connected to a central cable/hub. star topologies of networkStar topology is expensive in contrast to

Bus Topology

(ii)Star and Tree topologies

Page 133: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Comparison : Contrast :Both required more wiring. Tree topology is slower in contrast to

star topologies of network.

Page 134: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(iii) Bus and RingtopologiesComparison : Difficult to identify the problem if

the entire network shuts down. If one node fails to pass the data,

entire network has failed.

More difficult to configure in contrast to star topologies.

Contrast : Ring topology faster communication

in contrast to Bus topology. In contrast to Bus topology Ring

topology has independent line of connection which allows freedom of removing or adding nodes from the network.

16. What is the role of modem in electronic communications? Ans. A modem (modulator -demodulator) is a device that modulates an analog

carrier signal to encode digital information, and also demodulates such a carrier signal to decode the transmitted information. The roal is to produce a signal that can be transmitted easily and decoded to reproduce the original digital data. Modems can be used over any means of transmitting analog signals, from light emitting diodes to radio.

17.Ans.

18.Ans.

What are hubs? What are its types?A common connection point for devices in a network. Hubs are commonly used to connect segments of a LAN. A hubcontains multiple ports. Hubs can be either passive or activePassive Hub – A passive hub serves simply as a conduit for the data, enabling it to go from one device (or segment) to another.Active Hub –In a situation of data received being weak but readable, the active hub restores the signal before rebroadcasting the same.What is the role of switch in a network?A switch is a hardware device that joins multiple computers together within one local area network (LAN). Network switches appear nearly identical to network hubs, but a switch generally contains more intelligence than a hub. Unlike hubs, network switches are capable of inspecting data packets as they are received, determining the source and destination device of each packet, and forwarding them appropriately.

19. Briefly discuss the role of following devices in the context of networking. Ans. (i)repeater (ii)router (iii)bridge (iv)gateway

Repeater – A repeater amplifies the input signal to an appropriate level and works at the physical level of the OSI model. Sometimes the signal on the Internet becomes weak before reaching the destination node. Thus, repeater is used to regenerate the incoming packet and amplify it and then transmit it to another segment of the network. Router – A router is a device or, in some cases, software in a computer which is connected to at least two networks and decides which way to send each information packet based on its current understanding of the state of the networks it is connected to. Bridge – A bridge device filters data traffic at a network boundary. Bridges reduce the amount of traffic on a LAN by dividing it into two segments. Bridges inspect incoming traffic and decide whether to forward or discard it. An Ethernet bridge, for example, inspects each incoming Ethernet frame - including the source and destination MAC addresses, and sometimes the

Page 135: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

frame size - in making individual forwarding decisions. Gateway – A network gateway is an internetworking system capable of joining together two networks that use different base protocols. A network gateway can be implemented completely in software, completely in hardware, or as a combination of both. Depending on the types of protocols they support.

20. What is a communication protocol? What is its role in a network? Ans. When computers communicate with each other, there needs to be a common

set of rules and instructions that each computer follows. A specific set of communication rules is called a protocol.The basic role of a protocol is to define what is communicated, how it is communicated and when it is communicated.

21. Write short note on: (i)HTTP (ii) TCP/IP (iii) FTP. Ans. Hypertext Transfer Protocol (HTTP) which uses a set of rules to allow communication between a browser

7

Page 136: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

and server. Generally this protocol use port 80. Transmission Control Protocol (TCP), which uses a set of rules to send and receive information

packets with other Internet points. Internet Protocol (IP), which uses a set of rules to address each message so it reaches

the correct destination. File Transfer Protocol (FTP), which uses a set of rules to allow transfer of files (uploading and

downloading) between the user’s computer and server. Generally this protocol use port 110. 22. What is wirelesscomputing?How is it different from mobilecomputing? Ans. Wireless refers to the method of transferring information between a computing device and a data source,

without a physical connection.Wireless Computing v/s Mobile Computing

Wirelesscomputing Mobile computingWireless refers to the method of transferring Mobile computing refers to computing devicesinformation between a computing device and a that are not restricted to a desktop.data source, without a physical connection.

Wirelesscomputingis simply data Mobile computing essentially refers to a

communication without the use of a landline.computing device that is not always connected toa central network.

Involve a cellular telephone, a two way radio, aInclude laptops, newly created smart phones and

fixed wireless connection, a laser, or satellite also PDA’s.communications.Computing device is continuously connected to Communicate with a base location, with orthe base network. without, a wireless connection.

23.

Ans.

24.An

s.

Page 137: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Write short notes on the following :(i)GSM (ii)CDMA (iii)WLL (iv)3G (v)

SMS (vi)EDGE (vii) UMTS.

(i) GSM(GlobalSystem forMobile Communications): It is leading digital cellular system. In covered areas, cell phone users can buy one phone that will workanywherethe standard is supported. It uses narrowband TDMA, which allows eight simultaneous calls on the same radio frequency.(ii)CDMA (Code Division Multiple Access): It is a digital cellular technology that uses spread-spectrum techniques. CDMA does not assign a specific frequency to each user. Instead, every channel uses the full available spectrum. (iii) WLL (Wireless in Local Loop): WLL is a system that connects subscribers to the public switched telephone network using radio signals as asubstitutefor other connecting media. (iv)3G: 3Gis a specification for the third generation of mobile communication of mobile communication technology. 3G promises increased bandwidth, up to 384 kbps when a device is stationary. (v)SMS (Short Message Service): SMS is the transmission of short text messages to and from a mobile phone, fax machine and or IP address. (vi) EDGE (Enhanced Data ratesfor Global Evolution): EDGE isa radio based high speed

mobile data standard. (viii) UMTS(Universal Mobile Telecommunications Service): UMTS is a third-generation(3G)broadband, packet-based transmission of text, digitized voice, video, and multimedia at data rates up to 2 megabits per second (Mbps). Discussthe advantage and disadvantage of E-mail.Following arethe advantageand disadvantage of E-mail.Advantage :

Inexpensive way to move information. Delivered mail very fast. Reducing clutter of paper in office. Easy to send email.

Page 138: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

25.Ans.

Maintain records of communication with someone else. Email waits until you read it.

Disadvantage : Need computer to read or print email. Sent mail can be changed or deleted. Easy to sent a message that you latter regret. Hard to express emotions.

Compare and Contrast (i) e-mail and voice mail(ii) e-mail and chatting.(i) E-mail and voice mail

Comparison :Both e-mail and voice-mail areused for communication.Contrast :

E-mailWritten, may be read quickly or slowly, as the receiver

desiresMay be stored on disk for future reference. Easy to

access specific storedmessages.

Preferred by visual learners

(ii) E-mail and chatting.

Voice mailOral, must be listened to at the speed it was

deliveredMay be stored on tape for future reference.

Hard to locate specific stored messages.

Preferred by auditory learners

26.Ans.

Comparison : Both e-mail and

chatting are used for communication. Contrast :

Chat occurs in near real-time while Email doesn’t Chat is a type of software while Email is a protocol Chat requires the permission of both parties while

Email does not Chat is typically software dependent while Email is

not Chat needs accounts on thesame provider while Email

does not What is videoconferencing?How is it related tonetworking?Video Conferencing is a two-way videophone conversation among multiple participants. To make use of video conferencing, you need to install a digital camera,videoconferencing software and an internet connection. It is related to networkingdue to multiple users are connected with each other while conferencing.

27. What iswebbrowser?What is a webserver?How are these two related?

Ans. A software applicationthat enables to browse, search and collect information from the web known as web browser, web browsers are used at client side.The web pages on the Internet are stored on thecomputers that are connected to the Internet. These computers are known as web servers.

Page 139: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Web browser and Web server are related in a way that web browser send request to the web server and web server responds to the requests made by web browsers and fulfill the request accordingly.

28. Write shortnotes on URLs and domain names.Ans. URLStand forUniversalResourceLocater.

URL specifies the distinct address for each resource on the Internet, such as ftp, http etc.

URL looks likethis:type://adress/path. Where, - type specifies the type of the server in which the file

is located. - address is a address of the server. - path is a location of the file on the server. An Internet address which is character based is called a

Domain Name, such as com, org etc. Here com indicates Commercial and org indicates non-profit Organization.

Two letter short form indicating the country name may be used with URL e.g., http://www.microsoft.co.in here the last in suggest that it is based inIndia.

29. What is webhosting?What are its variouscategories? Ans. Web Hostingis a means of hosting web-server application on a computer system.

Page 140: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

By using web hosting electronic content on the Internet is readily available to any web browser client.

The computer system providing the web-hosting is known as web-server or the web host. Web hosting can be classified into following four categories :

1. FreeHosting: available with many famous sites which offer to host some web pages for no cost. 2. Virtual or SharedHosting: here one’s web site domain is hosted on the web server of hosting

company along with the other web sites. Use “shared” if you have a professional website. 3. DedicatedHosting: here, the company wishing to goonlinerents an entire web server from

hosting company. This is suitable for large, high traffic sites. 4. Co-locationHosting: here, the company owning the site instead of web hosting company.

Suitable for those who need the ability to makechange. 30. Explainbriefly the following : (i) HTML (ii) XML (iii) DHTML Ans. HTML :

Stands forHyperTextMarkupLanguage. Used to design the layout of a document and to specify the hyperlinks. Tells the browser how to display text, pictures and other support media. Support multimedia and new page layout features. Provides many tags for control the presentation of information on the web pages, such as

<body>, <li>, <hr> etc.

XML: Stands for eXtensibleMarkupLanguage. A markup language is a mechanism to identify structure in a document. XML defines a standard way to add markup to documents. Provides an ability to define tags and the structural relationship between them. All of the semantics of an XML document will either be defined by the application that process

them or bystyle sheets.

DHTML : Stands forDynamic HTML. DHTML refers to web content that changes each time it is viewed. For example, graphic can

move from one location to another, in response to useraction,such as mouse click. Enable a web page to react to userinput without sending request to web server. Used to describe the combination of HTML, style sheets and scripts that allow document to be

animate 31. What do you understand by networksecurity?Why is it considered veryimportant? Ans. Network securitycan be used to define the mechanism of providing security over network to the

clients. Network security is considered very important because it is needed to protect data during their transmission and to guarantee that data transmissions are authentic.Twofundamental approaches are in use: conventional encryption and public-key encryption.

32. What is afirewall?Briefly explain different firewall techniques. Ans. The system designed to prevent unauthorized access to or from a private network is called Firewall.

There are several types of firewall techniques : Packetfilter: Looks as each packet entering or leaving the network and accepts or rejects it based

on user-defined rules. Packet filtering is fairly effective and transparent to users, but it is difficult to configure.

Application gateway: Applies security mechanisms to specific application, such as FTP and Telnet servers. This is very effective, but can impose performancedegradation.

Circuit-level gateway: Applies security mechanisms when a connection is established. Once the connection has been made, packets can flow between the hosts without further checking.

Proxy server: Intercepts all messages entering and leaving the network. The proxy server effectively hides the true networkaddresses.

33. What is hacking? What is cracking? How are these two terms inter-related?

Page 141: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans.

Hacking is an unauthorized/authorizedaccess to computer/networkin order togather information oftheactual user.

Cracking is defined as the attempt to remove the copy protections inserted into software programs by theowner of software.

Page 142: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

34.Ans.

35.Ans.

Hacking and Cracking both are related in a way that both unauthenticallycausedamage to the system.Define the following :(a) Viruses (b) Worms (c) Trojan Horse (d) Spam (e) Cyber Crime (f) India IT Act 2000 (g) IPR

(a)Viruses: Computer virus is a malicious program that requires a host and is designed to make a system sick, just like a real virus. (b) Worms: Worms are self-replicating programs that do not create multiple copies of itself on

one computer but propagate through the computer network. Worms log on to computer system using the username and password and exploit the system.

(c) Trojan Horse: A Trojan horse is a code hidden in program such as game or spreadsheet that looks safe to run but has hidden side effects.

(d) Spam: Spam refers toanunwanted generally commercial email sent to a large number of addresses.

(e) Cyber Crime: Cyber crime involves the usage of computer system and the computer network for criminal activity.

(f) India IT Act 2000: In India the cyber laws are contained in the InformationTechnology Act,2000 which was notified on 17 October 2000 which was based on the United Nation’s Commission for International Trade related laws(UNCITRAL) model law.

(g) IPR: TheIntellectualProperty may be defined as a product of intelligence that has commercial value, including copyrighted property such as literacy or artistic works, and ideational property.

What is the general process of designingnetworks?The general process of designing networks requires you to follow the steps as shown in following Fig :

36. While designing networks, what factors related to networkenvironment would youconsider? Ans. While designing networks we would consider location of hosts, servers, terminals and other end

nodes; the projected traffic for the environment; and the projected costs for delivering different service levels etc. factors related to network environment.

37. While designing networks, what factor related to performance, would you consider? Ans. While designing networks we would consider network reliability, traffic throughput and host/client computer

Page 143: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

speeds etc. factors related to performance.38. When would you prefer (i) hubs over repeaters (ii) bridges over hubs (iii) switch over others network devicesAns. ?

(i) We would prefer hubs over repeaters when the distance is less.

Page 144: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

39.Ans.

40.

(ii) We would preferbridges over hubs when we need toconnect multiple networks. (iii)We would prefer switch over others network devices when want to segment networks into

different subnetworksto prevent traffic overloading. Whenwould you opt for a router in a network?We would opt for a router in a network in when we want toconnect different network ofdifferent protocolfor example, a router can link Ethernet to a mainframe.What is the difference between client-side scripting and server-side scripting?

Ans.

Client Side ScriptingScript code is downloaded and executed at client end.Response to the interactions is more immediate once the program code has been downloaded.

Services are secure as they do not have access to files and databases.

Browser dependent.Affected by the processing speed of user’s computer.

JavaScript, VBScript etc are Client Side Scripting languages.

Server-Side ScriptingThe script is executed at the server-end and the result is sent to the client-end.Complex processes are more efficient as the program and associated resources are not downloaded to the browser.Have access to files and databases but have security considerations when sending sensitive information.Does notdependon browser.Affected by the processing speed of host server.

PHP, Perl, CGI are Server Side Scripting languages.

41.Ans.

How are viruses harmful? How can you prevent them?Viruses’ main objective is to make your system unstable and cause harm to data. Mainly these cause damage in many ways :

Can corrupt entire filesystem? Create bad sector on a disk. Decrease the space on hard disk by duplicating files. Can format the entire disk. Alter data in data files. Cause the system to hang.

Following are guidelines for virus prevention : Never useunknown disk or CD without scanning. Scan files downloaded from the internet. Use licensed software. Never boot your PC from floppy. Make regular backups. Install and use antivirus software and keep it up to date. Protect your PC with password.

TYPEC:LONG ANSWER QUESTIONS

1. Internet isnetwork of networks. How did it come into existence? How does it function? Ans. In following way internet was come into existence :

Evolution of networking started way back in 1969 by the development of first network called ARPANET. The goal of this project was to connect computers at U. S. defense & different universities.

Page 145: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

In 1980’s, the NSFnet was started to make high-capacity network strictly for academic and engineering research

In 1990sthe internetworking of ARPANET, NSFnet and other private networks resulted into Internet.

Page 146: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

How Internet functions : Firstly the information or file to be sent to another computer is divided into small parts called

Packets. Eachpacketis given a sequential number e.g. 1, 2, 3. Then packets are send to the address of destination computer. The destination computer receives the packets in randomly. Then packets are rearranged in their correct order and get actual information/file.

2. Discuss various types of networks. Can you imagine the relationship of a LAN with a WAN? What isit?Discuss. There are three types of networks :

Ans. 1 Local Area Networks (LANs) : Group of computers and network Communication devices interconnected within a geographically limited area, such as a building or a

campus. transfer data at high speeds Key purpose is to serve its users in resource sharing. Hardware and software resources are shared.

2. MetropolitanArea Network (MAN) : Spread over city, for example cable TV networks. Purpose is sharing hardware and software resource amongitsusers.

3. Wide Area Networks (WAN) : Spread across countries. Group of LANs that are spreadacross severallocations and connected together to look like one big

LAN. Facilitate fast and efficient exchange of information at lesser cost and higher speed. The largest WAN in existence is internet.

Yes, We can imagine the relationship of a LAN with a WAN. Actually,WAN can even be a group of LANS that are spread across several locations and connected together to look like one big LAN.

3. Briefly discuss wireless and mobile computing and various techniques used for wireless and mobile computing. Wireless communication is simply data communication without the use of landlines. Mobile computing means that

Ans. the computing device is not continuously connected to the base or central network.

Following are the various techniques used for wireless and mobile computing :1. GSM (GlobalSystem forMobile Communications): It is leading digital cellular system. In

covered areas, cell phone users can buy one phone that will any where the standard is supported. It uses narrowband TDMA, which allows eight simultaneous calls on the same radio frequency.

2. CDMA (Code-Division Multiple Access): It is digital technology that uses spread-spectrum techniques. CDMA does not assign a specific frequency to each user. Instead, every channel uses the full available spectrum.

3. WLL (Wireless inLocal Loop): WLL is a system that connects subscribers to the public switched telephone network using radio signals as a substitute for other connecting media.

4. Email (Electronic Mail): Email is sending and receiving messages by computer. 5. Chat: Online textual talk in realtimeis called chatting. 6. Video Conferencing: A two way videophone conversation among multiple participants is

called video conferencing. 7. SMS (Short Message Service): SMS is the transmission of short text messages to and from a

mobile phone, fax machine and or IP address. 8. 3G and EDGE: 3G is a specification for the third generation of mobile communication of mobile

communication technology. 3G promises increased bandwidth, up to 384 kbps when a device is

Page 147: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

stationary. EDGE (Enhanced Data rates for Global Evolution): EDGEisa radio based high speed mobile data standard.

4. Define network security. What is its need?How can it be achieved? Ans. Network security can be used to define the mechanism of providing security over network to the

clients. Needs of network security :Prevent unauthorized access of different types of information.

Page 148: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

To clarify that the information is not unauthentic. Transferring of data in encrypted form.

Network security can be achieved by various types of protectionmethods like authorization, authentication, encrypted smart cards, biometric systems and firewall.

5.(a) What isRepeater?Ans. A repeater is adevice that amplifies a signal being transmitted on the network.

(b) Expand the following terms with respect to networking :

Ans.

(I)FTP (ii)CDMA (iii) HTML

(iv) SMS

(i) FTP – File Transfer Protocol(ii)CDMA – Code Division MultipleAccess(iii)HTML- Hypertext Markup Language(iv)SMS – Short Message Service

(c) How is an Email different from chat?

Ans.Email is different from chat in following way :

Chat occurs in near real-time while Email doesn’t Chat is a type of software while Email is aprotocol Chat requires the permission of both parties while Email does not Chat is typically software dependent while Email is not Chat needs accounts on the same provider while Email does not

(d) “New York Avenue” is planning to expand their network in India, starting with two cities in India to provide infrastructure for distribution of their canned products. The company has planned to setup their main office in Ahmadabad, at three different locations and have named their office as “Work Office”, “Factory” and “Back Office”. The company has its Corporate Officein Delhi. A rough layout of the same is as follows:

Approximate distance between these office is as follows:

From To DistanceWork Office Back Office 110 MtrWork Office Factory 14 KMWork Office Corporate Unit 1280 KMBack Office Factory 13 KM

In continuation of the above , the company experts have planned to install the following number

Page 149: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

computers in each of their offices:

Work Office 200

Page 150: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans.

6.

Back Office 115Factory 67Corporate 75

(i) Suggest the kind of network required (out of LAN, MAN, WAN) for connecting each of the following office units:

Work Office and Factory Work Office and Back Office

(ii) Which one of the following device will you suggest for connecting all the computers with in each of their office units?

Switch/Hub Modem Telephone

(iii) Which of the following communication media, you will suggest to be procured by the company for connecting their local office units in Ahmadabad for very effective (High Speed) communication?

Telephone Cable Optical Fiber Ethernet Cable

(iv) Suggest a cable/wiring layout for connecting the company’s local office units located in Ahmadabad. Also, suggest an effective method/technology for connecting the company’s office unit located in Delhi.

(v) Which one of the following devices will you suggest for connecting all the computers within each of their offices?

Switch/Hub Modem Telephone

(i) Work Office and Factory – MAN Work Office and Back Office – LAN

(ii)Switch/Hub (iii)Optical Fibre(iv)Suggested layout is shown in adjacent figure –

Technology for connecting to Delhi office – Satellite. (v)Switch/HubGlobal Village enterprises has following four buildings in Hyderabad city

Page 151: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Computers in each building are networked but buildings are not networked so far. The company has now decided to connect buildings also.

(a) Suggest a cable layout for these buildings. (b) In each of the buildings, the management wants that each LAN segment gets a dedicated

bandwidth i.e., bandwidth must not be shared. How can this be achieved? (c) The company also wants to make available shared Internet access for each of the buildings.

How can this be achieved? (d) The company wants to link its headoffice in GV1 building to its another office in Japan

Ans.

(i) Which type of transmission medium is appropriate for such a link?(ii)What type of network would this connection result into?

(a)Suggested layout is shown in adjacent figure –

(b)By placing Switch in each building. (c)By using Switch internet can be shared.(d)(i)Satellite

(ii)WAN 7. (a) Write two advantages and two disadvantages for STAR topology. Ans. Advantage :

Easy to install and wire. Easy to detect faults and to remove parts. Disadvantage : Requires more cable length than a linear topology. More expensive than linear bus topologies because of the cost of the hubs, etc.

(b) Write onedifference between Telnet and FTP. Ans. FTPis a File Transfer Protocol, and its only concern is to facilitate the transfer of files from one point to

another whereas Telnet is simply a connection protocol that allows a user to connect to a remote server that is listening for Telnet commands

Page 152: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(c) Explain the following terms in short : (i)DHTML (ii)ISP

Ans. (i)DHTML – DynamicHyperTextMarkupLanguage (ii)ISP – Internet Service Provider

(d) Define Packet switching. Ans. Packet switching is one of the switchingtechniqueswhichrefertoprotocolsin which messages are divided

into packetsbefore they are sent. Each packet is then transmitted individually and can even follow different routes to its destination. Once all the packets forming a message arrive at the destination, they are recompiled into the original message.

8. (a) Write two advantages and two disadvantages for STAR topology.Ans. Advantage :

Easy to install and wire. Easy to detect faults and to remove parts. Disadvantage: Requires more cable length than a linear topology. More expensive than linear bus topologies because of the cost of the hubs, etc.

(b) Write one difference betweencoaxial and optical cable. Ans. Coaxial cables have solid wire core surrounded by one or more foil or wire shields whereas optical

fibres consists of thin strands of glass or glass like materials.Coaxial cables transmit electrical signals whereas Optical fibres transmit light signals or laser signals.

(c) Explain the following terms in short :

Ans.

(i)FTP (ii)URL(i)FTP – File Transfer Protocol(ii)URL - Uniform Resource Locator

(d) Define Packet switching.Ans. Packet switching is one of the switchingtechniqueswhichrefertoprotocolsin which messages are divided into

packetsbefore they are sent. Each packet is then transmitted individually and can even follow different routes to itsdestination. Once all the packets forming a message arrive at the destination, they are recompiled into the originalmessage.

9. (a) What was the role of ARPANET in Computer Network?

Ans.ARPANET standsfor AdvancedResearch Project Agency Network. It is a project sponsoredby U. S. Department ofDefense and planted in 1969 to connect computers at U. S. defense & different universities.In1980s, NSFnet was started to make high capacity network, which are more capable than ARPANET.In 1990s the internetworking of ARPANET, NSFnet and other private networks resulted into internet.

(b) Which of the following is not a unit for data transfer rate?(i)bps (ii)abps (iii)gbps (iv)kbps

Ans. abps is not a unit for data transfer rate.

(c) What is the difference between Trojan Horse and Virus in terms of computers? Ans. Computer virus is a malicious program that requires a host and is designed to make a system sick, just like

a real virus whereasTrojan horse is a code hidden in program such as game or spreadsheet that looks safe to run but has hidden side effects.

Page 153: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(d) What term we use for a software/hardware device, which is used to block, unauthorized access while permitting authorized communications. This term is also used for a device or set of devices configured to permit, deny,

Page 154: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

encrypt, or proxy all (in and out) computer traffic betweendifferent security domains based upon a set of rules and other criteria..

Ans. Firewall.

(e) Try it by yourself.

(f)Write the full forms of the following: (f1) GNU

(f2) XML

Ans. (f1) GNU – GNU’s Not Unix.(f2) XML - eXtensibleMarkupLanguage

(g) Write one advantage of each for Open Source Software and Proprietary Software.Ans. Advantage of Open Source Software:

Low cost and no license fees; Advantage of Proprietary Software:

Reliable, professional support and training available; 10. (a) What isModem? Ans. Amodem is a computer peripheral that connects a workstation to other workstation via telephone line s and

facilitates communications.

7. Expand the following terms with respect to Networking : (i)PPP (ii)GSM (iii)XML (iv)HTTP

Ans. (i) PPP - Point toPointProtocol(ii)GSM – Global System for Mobile communication (iii)XML - eXtensibleMarkupLanguage(iv)HTTP - HypertextTransferProtocol

5. How is a Hacker different from aCracker? Ans. Programmers who gain knowledge about computer systemfor playfulpranks are knownasHackers whereas

Crackers are malicious programmers who break into secure systems.

(d) “China Middleton Fashion” is planning to expand their network in India, starting with two cities in India to provide infrastructure for distribution of their product. The company has planned to setup their main office in Chennai at three different locations and have named their office as “Production Unit”, “Finance Unit” and “Media Unit”. The company has its corporate unit in Delhi. A rough layout of the same is as follows:

Page 155: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Approximate distance between these Units is as follows:

From To Distance

Page 156: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Production Unit Finance Unit 70 MtrProduction Unit Media Unit 15 KMProduction Unit Corporate Unit 2112 KM

Finance Unit Media Unit 15 KM

In continuation of the above , the company experts have planned to install the following number computers in each of their offices:

Production Unit 150Finance Unit 35Media Unit 10Corporate Unit 30

(i) Suggest the kind of network required (out of LAN, MAN, WAN) for connecting each of the following office units:

Production Unit and Media Unit Production Unit and Finance Unit

(ii) Which one of the following device will you suggest for connecting all the computers with in each of their units?

Switch/Hub Modem Telephone

(iii) Which of the following communication media, you will suggest to be procured by the company for connecting their local office units in Chennai for very effective (High Speed) communication?

Telephone Cable Optical Fiber Ethernet Cable

(iv) Suggest a cable/wiring layout for connecting the company’s local office units located in Chennai. Also, suggest an effective method/technology for connecting the company’s office unit located in Delhi.

Ans. (i)Production Unit and Media Unit- WANProduction Unit and Finance Unit- LAN

(ii) Switch/Hub(iii) Optical Fiber(iv) Cable/wiring Layout is:

Page 157: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Technology for connecting the company’s office unit – Satellite.11(a) What is the significance of Cyberlaw?Ans. Cyberlaw is a generic term which refers to all the leagel and regulatory aspects of Internet and the World Wide Web.

Anything concerned with or related to or emanating from any legal aspects or issues concerning any activity of

Page 158: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

netizens and others, in Cyberspace comes within the ambit of Cyberlaw. The growth of Electronic commerce has propelled the need for vibrant and effective regulatory mechanisms which would further strengthen the legal infrastructure, so crucial to the success of electronic Commerce. All these regulatory mechanisms and legal infrastructures come within the domain of Cyberlaw.

(b) Expand the following terms with respect to Networking :

Ans.(i)CDMA (ii)FTP (iii)WLL (iv)HTML

(i)CDMA – Code Division Multiple Access(ii) FTP – File Transfer Protocol(iii)WLL – Wireless in Local Loop(iv) HTML – Hypertext Markup Language

(c) Which of the following unitmeasures the speed with which data can be transmitted from one node to another node ofnetwork? Also, give the expansion ofthe suggested unit

(i) Mbps (ii)KMph (iii) MGps Ans. (i) Mbps. – Mega bytes per second.

(d) “Bhartiya Connectivity Association” is planning to spread their office in four major cities in India to provide regional IT infrastructure support in the field of Education & Culture. The company has planned to setup their head office in New Delhi in three location and have named their New Delhi office has “Front Office”, “Back Office” and “Work Office”. The company has three more regional offices as “South Office”, “East Office” and “West Office” located in other major cities of India. A rough layout of the same is as follows:

Approximate distance between these office as per network survey team is as follows:Place From PlaceTo DistanceBack Office Front Office 10 KMBack Office Work Office 70 MeterBack Office East Office 1291 KMBack Office West Office 790 KMBack Office South Office 1952 KM

In continuation of the above , the company experts have planned to install the following number of computers in each of their offices:

Back Office 100Front Office 20Work Office 50East Office 50

West Office 50

Page 159: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

South Office 50

(i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following set of their

Page 160: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

offices: Back Office and Work Office Back Office and South Office

(ii) Which device you will suggest to be produced by the company for connecting all the computers with in each of their offices out of the following devices?

Switch/Hub Modem Telephone

(iii) Which ofthe following communication medium, you will suggest to be procured by the company for connecting their local office units in New Delhi for very effective and fast communication?

Telephone Cable Optical Fiber Ethernet Cable

Suggest a cable/wiring layout for connecting the company’s local office located in New Delhi. Also, suggest aneffective method/technology for connecting the company’s regional office –“East Office”, “West Office” and

Ans.“South Office” with offices located in New Delhi.(i) Back Office and WorkOffice-MAN

Back Office and South Office-WAN(ii) Switch/Hub(iii) Optical Fiber(iv) Cable/wiring Layout is:

Technology for connecting the company’s regional office – Satellite.12(a) Differentiate between Internet and Intranet.

Ans.Internet is a network of computer network which operates world-wide using a common set of communicationprotocols. Internet is not owned by anybody.Whereas Intranet is an inter-connected network within one organization that uses Web technologies for the sharingof information internally. Intranet is privately owned.

(b) Expand the following terms :

Ans.

(i) CDMA (ii)URL (iii)HTTP (iv)WAN(i)CDMA – Code Division Multiple Access(ii)URL – Uniform Resource Locator(iii)HTTP – Hyper Text Transfer Protocol

Page 161: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

(iv)WAN – Wide Area Network

(c) Write one advantage of STAR topology as compared to BUS topology.

Ans.In STAR topology easy to detect faults whereas in BUS topology it is difficult to identify the problem if the entire

Page 162: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

network shuts down.

(d)Try it by yourself. 13(a). Name two transmission media for networking.Ans. Optical fibre and Coaxial cable.

(b)Expand the following terms : (i) XML (ii) GSM (iii) SMS (iv) MAN

Ans. (i) XML – eXtensibleMarkupLanguage(ii)GSM - Global System for Mobile communication(iii) SMS - Short Message Service (iv) MAN – Metropolitan Area Network

(c) Differentiate between Hackers andcrackers? Ans. Programmers who gain knowledge about computer system for playful pranks are known as Hackers whereas

Crackers are malicious programmers who break into secure systems.

(d) INDIAN PUBLIC SCHOOL in Darjeeling is setting up the network between its different wings. There are 4 wings named as SENIOR(S), JUNIOR (J), ADMIN (A) and HOSTEL (H).

Distance between various Wings

Number of Computers

Wing A to Wing S 100 m Wing A 10Wing A to Wing J 200 m Wing S 200Wing A to Wing H 400 m Wing J 100Wing S to Wing J 300 m Wing H 50Wing S to Wing H 100 m

Wing J to Wing H 450 m

(i)Suggest a suitable Topology for networking the computer of all wings.

(ii)Name the wing where the server is to be installed. Justify your answer

(iii) Suggest the placement of Hub/Switch in the network.(iv) Mention the economic technology to provide internet accessibility to all wings.

Ans. (i)Star or Bus or any other valid topology or diagram.(ii)Wing S, because maximum number of computer are locatedat Wing S.(iii)Hub/Switch in all the wings.(iv)Coaxial cable/Modem/LAN/TCP-IP/Dialup/DSL/Leased Lines or any other valid technology.

14(a). What is difference between Message Switching technique and Packet Switching technique?

Ans.Message Switching – In this form of switching no physical copper path is established in advance between sender andreceiver. Instead when the sender has a block of datato be sent, it is stored in first switching office, then forwardedlater, one jump at a time.Packet Switching – With message switching there is no limit on block size, in contrast packet switching places a tightupper limit on block size.

(b) Expand the following terminologies :

Page 163: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans.

(i) TCP/IP (ii) XML

(iii) CDMA (iv) WLL

(i) TCP/IP – Transmission Control Protocol/ Internet Protocol(ii) XML - eXtensibleMarkupLanguage (iii) CDMA - Code Division Multiple Access (iv) WLL - Wireless in Local Loop

(c) Write two applications of Cyber Law.

Page 164: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value

Ans. Two applications of Cyber Laware:(i) Digital transactions (ii) Activities on Internet.

(d) Try it by yourself.

15(a). What is difference Star Topology and Bus Topology of network?

Ans.In STAR topology easy to detect faults whereas in BUS topology it is difficult to identify the problem if the entirenetwork shuts down.

(b) Expand the following abbreviations :

Ans.(i) GSM (ii) CDMA(i) GSM – Global System for Mobile communication(ii) CDMA - Code Division Multiple Access

(c) What is protocol? Which protocol is used to search information from Internet using an internet browser?

Ans. A protocol means the rules that are applicable for a network or we can say that the common set of rules used for communication in network.HTTP(Hyper Text Transfer Protocol) is used to search information from Internet using an internet browser.

(d) Try it by yourself. 16(a). What is difference between LAN andWAN?Ans. LANs are interconnected within a geographically limited area, such as a building or a campus whereas

WANs are spread across countries.

(b) Expand the following abbreviations : (i) HTTP (ii) ARPANET

Ans. (i) HTTP - Hyper Text Transfer Protocol(ii) ARPANET - Advanced Research Project Agency Network

(c) What is protocol? Which protocol is used to copy a file from/to a remotely located server? Ans. A protocol means the rules that are applicable for a network or we can say that the common set of rules used for

communication in network.FTP(File Transfer Protocol)is used to copy a file from/to a remotely located server.

(d) Name two switching techniques used to transfer data between two terminals (computers). Ans. Two switching techniques are : (i) Message Switching (ii) Packet Switching

(e) Try it by yourself.

Page 165: · Web viewEach class describes a possibly infinite set of individual objects; each object is said to be an instance of its own class and each instance of the class has its own value