Computer Science QnA
Computer Science QnA
Ans) A large Printed circuit board which is the main circuit of the computer containing various components
(ii) Chipset- Coordinates data transfer b/w various components of the computer
Ans) Cache Memory is a very high-speed semiconductor memory. It can speed up CPU. It acts as a buffer between the CPU and main memory. The types of cache are:
Ans) Opening in a computer to insert a printed circuit board. Expansion slots add functionality to the computer.
1) The AGP (Accelerated Graphics Port) slot is for inserting Graphics (video) card which make graphics application run faster.
2) Processor Slot - The processor is usually the largest chip on the system board Processor slot is used to fit processor on the mother board.
3) RAM Slots: Random-Access Memory (RAM) stores programs and data currently being used by the CPU. There are typically two types of sockets to install memory
they are
Ans) Its a collection of wire that carries electronic signals from one component to another. There are 2 types:
(i) Internal bus or System bus - It connects major components of a computer such as the CPU, memory and I/O
(ii) External bus or Expansion bus – connects the different external devices, expansion slots, I/O ports and drive connections to the rest of computer.
Ans) A socket on the back of the computer used to connect external device to the computer is called por. The different I/O ports are serial, parallel, SCSI, game and USB
ports.
a) Serial Ports: Also called RS-232-C ports. Its used to connect modems and some type of printers. When data is sent out a serial port, it is sent 1 bit at a time.
Advantage is that the data is sent and received over only two lines.
b) Parallel Ports: Its reserved for printers and some types of external storage devices. They carry 8 bits of data at a time on parallel paths. The signals do not travel as
far as the signals of serial port. The printer is attached through a parallel port.
c) SCSI Ports (Small Computer System Interface) port High performance hard-disks, high-end scanners and CD-ROM drives use the SCSI interface for fast data transfers
and I/O operations.
d) Game port: connects a PC to a joystick. Game ports are fitted onto sound cards and display cards. The game port are used to attach gaming devices like joysticks to
the computer
e) USB Ports : USB port gives a single, standardized, easy-to-use way to connect a variety of peripherals (printers, scanners, digital cameras, web cameras, speakers,
etc) to a computer. USB is a plug and play interface between a computer and add-on devices. A new device can be added to the computer without adding an
adapter card or even turning the computer off
Online UPS - In Online UPS, the Inverter is directly connected to the device and it always on to give the required current to the device. If power fails, the battery backup
circuit switches on and takes the load. Online UPS is more efficient than the Offline.
Off line UPS - In Offline UPS the device is directly connected to the input current. The UPS circuit always monitors the voltage level in mains and if there is a voltage drop or
main failure it switches to the inverter.
Ans) Traversal – visiting each subscript at least once to perform some operation from the beginning to last element is called traversal
Insertion – adding new data item into the given collection of data items is called insertion.
Deletion – removing an existing data item from the given collection of data items is called deletion.
Searching –finding the location of a data item in the given collection of data items is called searching.
Merging – combining the data items of two structures to form a single structure is called merging.
Ans)
Push Algorithm (inserting an element in stack) POP Algorithm (deleting an element from stack)
Step 1: If Top=n-1 Then Step 1:If Top=-1 Then
Print “Stack is full” Print “Stack is empty or underflow”
[Exit] Exit
[EndIf] [EndIf]
Step 2: Top=Top+1 Step 2:Item=Stack[Top]
Step 3: Stack [Top]=Item Step 3:Top=Top-1
Step 4: Return Step 4:Return
Ans)
Ans) Loc(a[p])=Base(a)+w(p-Lb)
int a[5]={10,20,30,40,50};
1000 10 a[0]
1001
1002 20 a[1]
1003
1004 30 a[2]
1005
1006 40 a[3]
1007
1008 50 a[4]
1009
Ans) Simulation, Operating systems, Process management, Different applications software, Printer server routines
Process a[i]
[EndFor]
Step 2: Exit
Ans)
Step 1: loc=-1
Step 2: first=0
Step 3: last=n-1
Step 4: While(first<=last)
mid=(first+last)/2
If(item=a[mid])
loc=mid
Goto Step 5
Else If(item>a[mid])
first=mid+1
Else
last=mid-1
[EndIf]
[EndWhile]
Step 5:If(loc>=0)
Output “Element is found at position= “,loc
Else
Output ”Element is Not Found”
[EndIf]
Step 6:Exit
Ans)
Step 1: For i=1 to n-1
j=i
While(j>=1)
If(a[j]<a[j-1])
temp=a[j]
a[j]=a[j-1]
a[j-1]=temp
[EndIf]
j=j-1
[EndWhile]
[EndFor]
Step 2: Exit
Ans)
Procedural Programming / Procedure Oriented Programming (POP) Object Oriented Programming (OOP)
Variables Objects
Follows top down approach Follows bottom up approach
No access specifier Has access specifier (private, public and protected)
No data hiding Data hiding
Overloading not possible Overloading is possible
Abstraction – Its the process of representing essential features without including the background details or explanation.
Encapsulation (Data hiding) - Combining data and associated functions into a single unit. External non-member function cannot access or modify data, thus providing data security.
Inheritance – The capability of a class to inherit the properties of another class. Types of inheritance are single level, multi level, multiple, Hierarchical and Hybrid Inheritance.
Polymorphism (Function overloading) – Polymorphism is an ability of a function to have same name and multiple forms. Function overloading means two or more functions have same
name, but differ in the number of arguments or data type of arguments.
Message passing - OOP communicates through message passing. A message is request for execution of procedure (message passing is calling a function. It involves specifying the name of an
object, the member function and the arguments to be passed if any)
OOP allows overloading where objects can have different meaning depending upon context.
Ans)
Windows
Real-time systems
Image processing.
Mobile computing.
Ans) An object is an instance of a class. It is the real-world entity. An object is normally defined in the main() function.
ObjectName.DataMember;
ObjectName.MemberFunctionName(arguments);
Example:- obj.input();
3. Explain with syntax and example for class definition and class declaration.
Ans)
Syntax Example
class class-name class sum
{ {
private: private:
Member data; int a,b,s;
Member functions public :
protected: void input()
Member data; {
Member functions cin>>a>>b;
public: }
Member data; void process()
Member functions {
}; s=a+b;
}
void output()
{
cout<<s;
}
};
4. Explain with syntax and example for defining a member function outside the class.
Ans)
Syntax Example
return-type class-name :: function-name(argument1, argument2,...) class sum
{ { private:
Body of function int a,b,c;
} public :
void input();
};
void sum :: input()
{
cin>>a>>b;
}
5. Explain with syntax and example for defining a member function inside the class.
Ans)
Syntax Example
class class-name class sum
{ {
Access specifier: private:
return-type function-name(argument1, int a,b,s;
argument2,...) public :
{ void input()
Body of the function {
} cin>>a>>b;
}; }
void process()
{
s=a+b;
}
void output()
{
cout<<s;
}
};
Ans) Array having class type elements is known as array of objects. An array of objects is declared after class definition. Its defined in the same way as any other array. The
declaration of an array of class objects is similar to the array of structures in C++.
It contains only data members It contains data members and member functions
By default data members are public By default data members are private
A keyword struct is used for definition A keyword class is used for definition
Ans) An array is used as data members when large number of similar type of data members are considered. These data
members can be accessed by using corresponding subscripts.
Example:
class sample Chapter-8: Function overloading and
{ private :
int a[100],i; member functions
public :
1. void input(); Define function overloading. Explain with
- syntax and example.
-
Ans) }; Function overloading means two or more
void sample :: input()
{
functions have same name, but differ in
the cout<<”Enter 5 numbers\n“; number of arguments or data type of
for(i=0;i<5;i++) arguments
cin>>a[i];
}
Syntax Example
Return-type function-name(arguments..) #include<iostream.h>
#include<conio.h>
{ #include<math.h>
class fo
Body of the function {
} private:
float s;
public:
float area(float a)
{
return (a*a);
}
float area(float a, float b)
{
return (a*b);
}
float area(float a, float b, float c)
{
s=(a+b+c)/2;
return (sqrt(s*(s-a)*(s-b)*(s-c)));
}
};
void main()
{
float a,b,c;
fo obj;
cout<<”Enter value of a, b and c \n”;
cin>>a>>b>>c;
cout<<"Area of the square = "<<obj.area(a);
cout<<"Area of the rectangle = "<<obj.area(a,b);
cout<<"Area of the triangle = "<<obj.area(a,b,c);
}
Ans) Inline functions are defined inside the class before other functions of that class.
Function defined outside the class can be made inline including the keyword inline
Advantages Disadvantages
• Inline functions are small in size and compact. • The size of the executable file increases and
• Inline functions are executed faster than other requires more memory, if its called frequently
functions. • It does not work if the definition is long and
• Efficient code can be generated. complicated, contains looping/switch/goto
• Readability of the program is increased. statements and there are recursive calls.
Ans) A function whose body is inserted at the place of its call is called inline function. It reduces overhead and increases the speed of the function.
Ans)Friend functions are non-member functions that are given special access privileges.
Ans)
Syntax Example
class class_name #include <iostream.h>
{ #include<conio.h>
public: class sum
{
friend return_type function_name(argument/s);
private:
}; int a, b;
return_type function_name(argument/s) public:
void input()
{ {
- cout<<”Enter 2 numbers \n”;
cin>>a>>b;
} }
friend int add(sum obj);
};
int add(sum obj)
{
return (obj.a + obj.b);
}
void main()
{
clrscr();
sum obj;
obj.input();
cout << "Sum = "<<add(obj);
getch();
}
Ans) A constructor is a special member function that is used in classes to initialize the objects of a class automatically
Constructor is used can to set initial values for certain member variables.
If there is no constructor defined for a class then compiler will call the default constructor.
Syntax Example
class ClassName class series
{
{ private :
public : int x, n, i, s;
public :
ClassName()
series()
{ {
//default constructor s=1;
}
} void input();
}; void process();
void output();
};
…..
void main()
{
clrscr();
series obj;
obj.input();
obj.process();
obj.output();
getch()
}
Ans)
This method creates an object and passes the value to the constructor
This method creates an object and explicitly invokes the constructor with arguments.
This method creates an object and assigns only one value to the constructor. This method can be
used in a situation where the constructor initializes a single value.
Chapter-10: Inheritance
1. Define inheritance, base class and derived class.
Ans) Inheritance is the capability of one class (derived class) to inherit properties from another existing class (base class).
Base Class/Super Class: It is the class whose properties are inherited by another class.
Derived Class/Sub Class: It is the class that inherits the properties from base class.
Easy to maintain
Easy to extend
Memory Utilization
Ans)
Single Inheritance :-
Single Inheritance is the process of creating a new class from existing class base class. If a class is
derived from a single base class, it is called as single inheritance Eg:
Multilevel Inheritance: - Derivation of a class from another derived class is called multilevel
inheritance. Example:
Multiple Inheritance: - If a class is derived from more than one base, it is known as multiple
inheritance. Example:
Hierarchical inheritance :- if a number of classes are derived from a single base class, it is called as
hierarchical inheritance. Example:
Ans)
The way data is processed into an information is called as data processing cycle.
1) Data collection (Gathering data, facts and statistics): This task basically involves finding the origin of Data.
2) Data Input: The input of stored data should be done in a form that is understood by the data processing system.
3) Data Processing:
a. Classification of database
b. Sorting of database
c. Verification
d. Calculation
e. Recording and summarizing
4) Data Storage: Data storage may be on devices such as floppies. hard disk, and tape and so on or a hard copy may be
maintained in files.
5) Data Output: The output of data processing system is in the form of a report. Some of the output can be in the form
of sound, picture.
6) Communication: Computers have communication ability which increases their power. Eg. Email
3. DATA SHARING: The data stored in the database can be shared among multiple users of the database.
4. MULTIPLE USER INTERFACES (Multi-user Access): The query language provided by DBMS is so easy to understand.
5. BACKUP AND RECOVERY: for recovery from hardware and software failures.
g) Entity
Ans) a) File- Basic unit of storage in computer system which contains large collection of data.
b) Database- Collection (group) of logically related organized data that can be easily accessed, managed and updated.
c)Table- collection of data elements organized in terms of rows and columns.
d) Tuple/Record/Row- Single entry in a table.
e) Attribute/Field/Column: Each Column is identified by a distinct header called attribute or field.
f) Domain is a set of all unique values permitted for an attribute in that column.
g) Entity is a person, a place, or a thing for which data is collected and maintained .
Ans) Hierarchical Data Model:- It uses tree structures to represent relationship among records. The entities in this model are related in one-to-many relationships. For
example, a college has a number of courses to offer. Each course has a number of students registered for it.
Ans) File organization explains the way in which records are arranged and accessed.
Serial File Organization:- The collection of data records are stored in the chronological(time of creation) order in the physical medium. No particular sequence is followed to
store the data.
Sequential File Organization:- The data records are stored one after another in an ascending or descending order when file is created.
Ans)
Ans) Group functions are built in SQL functions that operate on group of rows and return one value for the entire group. These functions are :
COUNT() – returns the number of rows in the table that satisfies the condition specified in the WHERE condition. If the WHERE condition is not specified, then the
query returns the total number of rows in the table.
MAX() – returns the maximum value from a column.
MIN() – returns the minimum value from a column.
SUM() – returns the sum of a numeric column.
AVG() – returns the average value of a numeric column.
Ans)
• Constraints are rules enforced on data columns on table that limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the
database.
• It could be column level (applied only to one column) or table level (applied to the whole table).
• Constraints can be specified when a table is created with the CREATE TABLE statement or you can use ALTER TABLE statement to create constraints even after the
table is created.
6. Explain DDL commands with syntax and example.
Ans)
1. CREATE: Creates a new table, a view of a table, or other object in database.
Syntax:- CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
-------
-------
column_nameN data_type
);
Example:- CREATE TABLE student
(
rno char(8),
name varchar2(30),
combination char(4),
dob date,
fees number(10,2)
);
2. ALTER: Modifies an existing database object, such as a table.
Syntax:- ALTER TABLE table_name ADD/MODIFY/DROP columnname1 datatype, columnname2 datatype,.... ;
Examples:- ALTER TABLE student ADD address VARCHAR2(30));
ALTER TABLE student MODIFY address VARCHAR2(40));
ALTER TABLE student DROP address
3. DROP: Deletes an entire table, a view of a table, or other object in database.
Syntax:- DROP TABLE table_name;
Example:- DROP TABLE student;
Ans)
1. INSERT: Creates a record.
Syntax:- INSERT INTO table_name [(column1,column2,....columnN)]
VALUES(value1,value2,....,valueN);
The square brackets indicate that the items inside the brackets are optional.
Example:-INSERT INTO student (rno,combination,fees)
VALUES(‘16S1005’,’PCMC’,27000);
2. UPDATE: Modifies records.
Syntax:- UPDATE table_name
SET column_name=value [,column=value,...] WHERE condition;
Example: UPDATE student SET combination=’PCMC’
WHERE name=’Ashish’
3. DELETE: Deletes records.
Syntax:-DELETE FROM table_name [WHERE condition];
Example: DELETE FROM student WHERE combination=’PCMB’;