Upload
lehuong
View
238
Download
4
Embed Size (px)
Citation preview
1
OVERVIEW OF A COMPUTER
1. Briefly explain the history of computers.
The Abacus was the earliest calculating machine originated in china about 3000 years ago.
Napier‟s bones was invented by John Napier (1550-1617), a Scottish mathematician and
scientist.
The slide Rule was invented by William Oughtred in1625.it was about logarithms to do
multiplications quickly.
Blaise Pascal in 1642 invented first mechanical machine for adding.
Charles Babbage in 1834 developed a machine to perform differential equations called a
Difference Engine.
In 1890, an American named Herman Hollerith invented a counting machine to count the
population of USA.
2. Give the features of the First Generations.
Vacuum tubes for internal operations.
Magnetic drums were used for memory.
Punched cards was used for input and output.
Low level languages for programming were used.
The system was huge and non-portable.
3. Give the features of the Second Generations.
Transistors were used for internal operations.
Magnetic core for main memory was used.
High level languages were used for developing programs.
Used punched cards for input and printouts for output.
The systems were faster, more powerful, more reliable, cheaper, smaller in overall size and more
memory.
4. Give the features of the Third Generations
Integrated circuits on silicon chips were used for internal operations.
Minicomputers were introduced.
Maintenance cost was low as hardware failures were rare.
The systems were faster, more powerful, more reliable, cheaper, smaller in overall size and more
memory.
5. Explain the importance and usage of computers in education and industry.
Computers are used in classrooms to teach different subjects.
Students are often able to research their assignments without leaving their homes or dormitories.
Computers have had a major impact in industries where products are designed and
manufactured.
Computer Aided Design (CAD) is used to develop products. Computer Aided Manufacturing
(CAM) is used to produce them.
Factory floors are becoming increasingly occupied by computers used for many purposes
including inventory control and planning and process control.
2
6. Discuss the characteristics of a computer in detail.
Speed: Current computers are fast in doing calculations. The speed of the computer is measured
in terms of No. of million instructions per second (MIPS).
Storage capacity: Computers come with a very large amount of memory space. They hold lot a of
data.
Diligence: After doing work for some time, humans become tired but computers do not become
tired.
Accuracy: The results that the computers produce are accurate provided that the input data and
programs are reliable.
7. In the field of communication computer are the best? Why?
Used in teleconferencing to communicate and discuss on-line projects and technologies.
E-mail facility allows people to come together globally.
Voice mail increases communication by transmitting voice.
Used as a switching element in telephone exchange.
Used in satellite communication.
8. Explain the generations of computers in detail.
First Generation Computer
Vacuum tubes for internal operations.
Magnetic drums were used for memory.
Punched cards was used for input and output.
Low level languages for programming were used.
Second Generation Computer
Transistors were used for internal operations.
Magnetic core for main memory was used.
High level languages were used for developing programs.
The systems were faster, more powerful, more reliable, cheaper, smaller in overall size and more
memory.
Third Generation Computer
Integrated circuits on silicon chips were used for internal operations.
Minicomputers were introduced.
Maintenance cost was low as hardware failures were rare.
The systems were faster, more powerful, more reliable, cheaper, smaller in overall size and more
memory.
Fourth Generation Computer
More circuits on chips LSI, VLSL.
Introduction of microprocessors.
Easily portable because of their small size.
User friendly systems.
The systems were faster, more powerful, more reliable, cheaper, smaller in overall size and more
memory.
Fifth Generation Computer
Development of storage technology
Advancement in networking technology
Systems are more reliable, faster and cheaper.
3
Development of robots to assist human beings.
8. Explain the classification of computers in detail.
The computers are broadly classified into three categories. They are
Analog computers
Digital computers
Hybrid computers
Analog computers-continuous quantities are used. Computations are carried out with physical
quantities such as voltage, length, current, temperature etc. Analog computers operate by
measuring rather than counting. Ex: voltmeter, speedometer and thermometer.
Digital computers-computers work upon discrete data. They convert the data into digital (0 & 1)
and all operations are carried out on these digits. Digital computers are much faster than analog
computers and far more accurate. Digital computers are further classified in two ways.
i. Purpose-wise
ii. Size and performance wise
i. Purpose wise – digital computers are classified into two types: special purpose computer is the
one that is designed to perform specific task. Ex: Blood pressure monitoring system
ii .Size and performance wise-digital computers can be classifies into three types.
Also known as a PC, this is the most dominant form of computer. It typically provides access to a
wide variety of computing applications.
ii.Minicomputers- They are usually designed for real-time dedicated applications as high
performance, multiple user applications.
iii.Mainframes-A mainframe computer is a large and expensive computer capable of
simultaneously processing data for hundreds or thousands of users.
iv.Supercomputers- Designed for ultra-high performance tasks such as weather analysis,
encryption cracking and creation of animation.
Explain the role of computer in science and engineering.
Powerful computers are used to simulate dynamic processes in the practice of science and
engineering.
Supercomputers have numerous applications in chemistry, physics, structural engineering and
weather forecasting.
Physicians use computers to understand the human body and to diagnose disorders.
Satellites are commonly used in information technology. They may simply relay signals from one
point to another, eliminating the need for wires between.
9. Explain the block diagram of a computer.
Input unit: Computers need to receive data and instructions in order to solve any problem.
Central Processing Unit: is called the heart and brain of the computer system as it follows the
instructions of the software to manipulate data into information.
Memory Unit: Where all computer processing and program instructions are stored.
Output Unit: It is used to print or display the results.
4
INPUT OUTPUT MEMORY DEVICES
1. Write the difference between ROM and RAM
RAM (random access memory)is a primary memory.
ROM (read only memory) is a built in memory.
RAM is a volatile memory.
ROM is a non volatile memory.
In RAM the operating system, application programs, and current data are present.
In ROM only computer„s operating instructions are present.
2. Write a note on OCR, OMR and MICR
OCR coverts typing or hand written fonts into computer fonts. It is used in banks to read the
cheque numbers in the banks.
OMR is an optical scanner uses the laser for scanning.OMR sheet contains ovals or boxes to
select the correct answer from the given choice. It is used in CET for marking multiple choices.
MICR is used in banks that reads the text printed with magnetically charged ink. It is helpful to
segregate them based on branches, departments etc.It saves user time and ensures accuracy and
security.
3. Explain impact and non-impact printers in detail.
Impact produces text and images when print head strike the ink ribbon by physically making
contact with the paper.Its speed is less and does not generate the high quality output. Ex: Dot
matrix, Daisy wheel
Non Impact produces text and graphics on paper without striking the paper. It can also print
different colours,fonts,picture,drawings etc.It is expensive. Ex: Laser printer, Ink jet printer.
5
4. Explain input device in detail.
5. Explain output device in detail.
6
The different types of ROM are PROM-programmable read only memory.
EPROM-Erasable programmable read only memory.
EEPROM- Electrically erasable programmable read only memory.
The different types of RAM are
SRAM-Static random access memory
DRAM-Dynamic random access memory.
5. Illustrate the latest configuration of computers for today.
Operating system – Windows 8.1/Mac 10.10
Processor – Intel core i5,/i7
RAM – 8 GB
Hard drive – 1 TB
Monitor –LCD
Keyboard –Multimedia
Mouse - optical
6. Explain the storage medium in detail.
Hard Disk- is a secondary storage device. It is a disk pack consisting of several metal platters
coated with a magnetic material rotating at high speed. Each surface has a read or write head
mounted on an arm. The heads can only move in one radical direction. Both sides of a platter
are used. Each surface is divided into concentric circles or tracks, typically thousand tracks per
platter. Each track is divided into about 100 sectors separated by gaps to access data in a
specific location. The head waits until the desired sector is under it. This takes about 6
millisecond. Once the sector is found the data can be read at the rate of 4Mb.
7
Data Representation
1. Find (11001001.1011)2 = (?)8= (?)16
Group the binary digits in groups of 3 bits
011 001 001.101 100
Write the octal equivalent of each group
3 1 1.5 4(8)
Write 3 bit binary equivalent of each digit and Group the binary digits in groups
of 4 bits
0000 1100 1001.1011 0000
Write the hexadecimal equivalent of each group
C 9 B (16)
2. Find (FACE) 16 = (?)8
Write 4 bit equivalent of each digit
F=15= 1111 A=10=1010 C=12=1100 E=14=1110
Group the binary digits in groups of 3 bits
001 111 101 011 001 110
Write the octal equivalent of each group
1 7 5 3 1 6(8)
3. Find 316(8) = (?)10= (?)2
Multiply each digit by powers of 8
3X82 +1 X 8
1 +6 X 8
0
Calculate the sum
206(10)
Divide given numbers by 2 take the remainders
2 206
2 103- 0
2 51 - 1
2 25 - 1
2 12 - 1
2 6 - 0
2 3 - 0
2 1 - 1
= 11001110(2)
8
4. Subtract 25(10) - 14(10) using 1’s and 2’s complement
1’s complement method
Minuend=25 (binary =11001) subtrahend=14(binary=01110)
Find 1’s complement of subtrahend
10001
Add the result to minuend
1 1 0 0 1
1 0 0 0 1
1] 0 1 0 1 0
In case there is a carry add the carry to the LSB of the result
0 1 0 1 0
1
0 1 0 1 1
2’s complement method
Minuend=25 (binary =11001) subtrahend=14(binary=01110)
Find 2’s complement of subtrahend
10001
1
10010
Add the result to minuend
1 1 0 0 1
1 0 0 1 0
1] 0 1 0 1 1
In case there is a carry ignore the carry
0 1 0 1 1
5. Write a brief note on ASCII code
ASCII stands for American Standard Code for Information Interchange.
ASCII code is the numerical representation of a character such as ‘a’
9
SOFTWARE CONCEPTS
1. Explain different types of operating system.
The different types of Operating systems are
1.Single user operating systems-Only one user can use a system at a time.
2.Batch Operating system-Inputs are collected and submitted in batches and processes the jobs
in FIFO order.
3.Multiprogramming Operating systems-involves the use of two or more CPUs to perform work
efficiently.
3a.Multitasking Operating systems-Multitasking refers to the ability of the operating system to
have more than one program open at a time.
3b.Multiuser Operating systems-multiple users can use a system at a time.
3c.Time sharing systems-CPU time is share between different users.CPU swiches between
different jobs given by the users.
3d.Real time systems-it process the data with high speed.
4.Distributed Operating systems-represents a number of independent computers connected with
each other so that they can share data and resources.
5.Network Operating systems-which supports networking so that multiple users can work
simultaneously.
6.Multithreading models-A thread is a flow of execution of codes with its own program counter.
2. Explain the features of DOS OS.
File management features(to create,edit,write and delete files)
Directory management(creation,change,search and deletion of directories)
Memory management(allocation and de-allocation of memory)
3.Explain features of UNIX OS
Hierarchical file organization.
Portability,Multi-user,multitaskingsupport
Facilitates Kernel and Shell programming
Machine independent.
4. Differentiate between Interpreter and compiler.
A language processor that translates a statement of a high level language and immediately
executes it before translating the next source language statement.
Compiler is a translator that translate source code(user written program)to object code(machine
language program),the only form in which machine can execute.
b.Object code and Source code.
Object code is the converted source code to its equivalent machine language.
Source code is the code written by user in high level language.
c.Application software and System software.
A software that has been written to process or perform a specific job.
A computer program that controls the system hardware and interacts with application software.
5. What is Operating system? Mention some operating systems.
A collection of programs that controls the overall operation of a computer.
10
1.DOS-is a single user operating system developed by Bill Gates and Paul Allen in 1980 for IBM
PCs.
2.WINDOWS-is a multi-user developed by Microsoft.
3.Mac Os-It is based on the UNIX operating system and originally set standard for graphical
user interfaces.
4.UNIX-is a multi-user operating system developed by Dennis Ritchie and Ken Thompson in
1985 by Sun Micro systems.
5.LINUX-is a multi-user operating system developed by Linus Torvalds in 1991 when he was a
student at the university of Helsinki in Finland.
6.ANDROID-It is a Linux based operating system developed by the Open Handset
Alliance(OHA) and by Google.
7.SYMBIAN OS-It is a mobile operating system that supports multithreading and multitasking.
6. What are the functions of an Operating systems?
The functions of OS are
1.Memory management
2.Processor management
3.Device management
4.Information management
Memory management: is one of the most precious resources of present multiprogramming
environment. It is mainly concerned with the allocation of physical memory of finite capacity to
requesting processes.
Processor management: is concerned with assignment of processors to processes(process
scheduling).Process is defined as a program in execution.
Device management: The efficiency of operation of the I/O devices significantly contributes to
the system performance. The various device management functions are Traffic controller
function, device allocation policy, device allocation and device deallocation.
Information management: is responsible for managing files residing in secondary storage.Its
main functions are Management of secondary storage, providing privileges, loading information
from secondary memory to primary memory and deallocation.
11
PROBLEM SOLVING TECHNIQUES 1. What are the different stages of problem solving ?
The different stages of problem solving techniques are:
a. Problem definition
b. Problem analysis
c. Algorithm development
d. Coding
e. Program testing and debugging
f. Documentation.
Problem definition: Here we define the problem by answering the questions what the computer
does, what it will perform, what data it will use, what output, how the program will interact.
Problem Analysis: Analyzing the problem by identifying the inputs, output and additional
requirements to the solution.
Design of solution: Solution to any problem is done using tools such as algorithm and
flowchart.
Algorithm development: An algorithm is a step by step finite sequence of instructions to solve a
well defined problem.
Coding: it is the process of translating the algorithm or flowchart into the syntax of a given
programming language.
Testing and debugging: Running the program, executing all its instructions functions and
checking the logic by entering sample data to check the output.
Debugging is the process of finding and correcting program code mistakes that are called error.
Documentation and maintenance: Documentation is a reference material which explains the use
and maintenance of the program or application for which it has been written.
2. What is an algorithm? Explain the advantages and disadvantages.
An algorithm is a step-by-step finite sequence of instructions, to solve a well defined problem.
Characteristics of algorithm:
1. Input: It should accept one or more data to be processed.
2. Definite: Each operational step or operation must be definite.
3. Effective: It should consume less time.
4. Terminate: After some minimum number of operations algorithm must come to an end.
5. Output: It must produce one or more computed result as output.
Advantages: a. Easy to understand since it is written in English like language.
b. It has finite no of steps.
c. Easy to develop, easy to maintain.
Disadvantages:
a. It is time consuming and difficult to understand for larger and complex problems.
b. Understanding complex logic through algorithms would be difficult.
3.What is a flowchart? Write the advantages and disadvantages.
12
The diagrammatic representation of an algorithm is called flowchart. There are two
types of flowchart 1. Program flowchart and System flowchart.
Program flowchart specifies only the flow of operations of an algorithm, pictorially.
System flowchart gives an overall view of computer system environment.
Characteristic s of flowchart:
1. Communication: It is a better way to communicate .
2. Effective analysis: Problem can be analyzed in more effective way.
3. Proper Documentation: Program flowcharts serve as a good program
documentation.
4. Efficient coding: The flowchart acts as a guide or blueprint during the system
analysis and program development phase.
5. Proper Debugging: It helps in debugging process.
6. Efficient program maintenance
Advantages: Easy to understand.
Easy to convert into a program code.
Independent of programming language.
Easy to test the program for errors and easy removal of errors.
Disadvantages: it is time consuming
It is difficult to show the complex logic using a flowchart.
Any changes needs redrawing.
13
Object Oriented Concepts Important definitions in OOPS
Procedural programming: It mainly focuses on processing of sequential instructions to perform
a specific task. It gives more importance to procedure or logic used to solve the problem.
Ex: COBOL.
Structured programming: It is an organized approach for programming. It uses the basic control
structures such as sequence, selection and iteration and modularity.
Disadvantages of structured programming:
It is difficult to model the real world, Lack of encapsulation, lack of Information hiding.
OOPS: It views the problem in terms of objects involved rather than procedure for doing the
problem. It makes the software reuse, feasible and possible.
Object: A programming model that combines data and functions into a single unit is called an
Object.
Functions of an object are called member functions. These member functions are used to access
the data of an object.
Class: It is template which represents group of objects which share common properties and
relationships.
Characteristics of OOPS.
1. Modularity: It decomposes large and complex problem in to smaller units called modules.
Thus team work is easy.
Ex: Calculator.
2. Data Abstraction: The process of representing the essential features without including the
background details or explanations is called data abstraction.
Ex: The different features in a mobile.
3. Data encapsulation: It is a mechanism of combining the data and functions into single unit
called an object.
Encapsulation is used to hide the values or state of a structured data object inside a class,
preventing unauthorized access.
4. Inheritance: A mechanism by which classes can inherit properties and behaviors from pre-
existing classes. These pre-existing classes are called base classes.
Example: Consider a base class called shape and its derived class rectangle inherits the
characteristics such as height, width, area etc.
5. Polymorphism: An ability of using function or data in more than one form is called
polymorphism. In OOP‟s it is possible for s to use one function for many different purposes.
6. Data Binding: Binding means the code associated with a given procedure call is at known
until the time of the call at run time. It is associated with polymorphism and inheritance.
7. Message passing: It means request for execution of a procedure for an object. Invoking a
procedure by specifying the name of object and function.
Advantages:
1. Improved software development productivity
2. Improved software maintainability.
3. Faster development.
4. Lower cost of development.
14
Disadvantages:
1. Steep learning curve.
2. It is complex to create programs based on interaction of objects.
3. Some of the key programming techniques are challenging to manage initially.
4. Larger program size.
Applications.
1. Image processing.
2. Pattern recognition.
3. Computer Aided Design ad CAM.
4. Mobile computing.
5. Web based applications.
2. Mention the various benefits of OOP.
-Object oriented databases
-Hypermedia, expert text and hypertext
-Artificial Intelligence and expert systems
-Decision support systems and office automation systems.
-Parallel programming and neural networks.
-CAD, CAM, CIM systems
-Simulation and modeling
15
INTRODUCTION TO C++
1. Write the structure of C++ program with an example.
Comments or documentation section
Linker section
Definition section
Global declaration section
Void main ( )
{
declaration section
Executable statements section
……..
}
Example:
#include<iostream.h>
#include<conio.h>
#define p 3.14
void main( )
{
int r;
float cir,area;
cout<<”\n input radius”;
cin>>r;
area=p*r*r;
cir=2*p*r;
cout<<”\n Area….”<<area;
cout<<”\n Circumference…”<<cir;
}
DATA TYPES
1. What are data types? Explain.
Data types are the means to identify the type of data ad associated operations of handling it.
C++ data types are of two types 1. Fundamental data types. 2. Derived data types.
There are five fundamental data types: char, int, float, double and void.
Derived data types are array, functions, pointers, references, constants, classes, structures,
unions and enumeration.
Int: Integers are whole numbers. They have no fractional parts.
Char: Character can store any member of the C++ implementation‟s basic character set.
Float: A number having fractional part is a floating –point number.
16
Double: This is used for handling floating-point numbers which occupies twice as much memory
as type and precision.
Void data type: It specifies an empty set of values. It is used as the return type for functions that
do not return a value.
2. What are modifiers?
We can use a modifier to alter the meaning of the base type to fit various situations more
precisely.
The list of modifiers are signed, unsigned, long, short.
ARRAYS 1. What is an array? Explain.
Arrays are collection of elements of similar type of data ad under same name.
There are 3 different types of arrays:
1. One-dimensional array.
2. Two-dimensional array.
3. Multi-dimensional array.
One-dimensional array: It is an array in which each element is accessed by using only one
subscript. The subscript represents the position of the element in the array.
Declaration of array: data type array-name [size];
Example: int stud[10];
Two-dimensional array: It is an array in which the element is accessed using 2-subscripts. The
subscripts represent the position of the element.
Declaration: data type array-name [size]
Example int stud [3] [4]
Example: int a[4][3][2]………[n];
2. Explain how to initialize arrays.
We can give values to each array elements when the array is defined.
One dimensional array:
int a[5 ]= {9,-5,6,2,8};
Two-dimensional array:
int a[2][3]={1,2,3,4,5,6}; a[0][0]=1 a[0][1]=2 a[0][2]=3
. a[1][0]=4 a[1][1]=5 a[1][2]=6
3. Explain the how to access the elements in arrays.
One dimensional array:
To read the elements.
cout<<”enter the elements”;
for(i=0;i<5;i++)
cin>>a[i];
17
To print the elements.
cout<<”The elements are”;
for(i=0;i<5;i++)
cout<<setw()<<a[i];
Two dimensional array:
To read the elements:
cout<<”Enter the elements:”;
for(i=0; i<5;i++)
for(j=0; j<3;j++)
cin>>a[i][j];
To print the elements:
cout<<”The elements are:”<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
cout<<setw(5)<<a[i][j];
cout<<endl;
}
4. Explain the memory representation of one dimensional arrays.
Memory representation of one-dimensional array:
5000 5001 5002 5003 5004
. a[0] a[1] a[2] a[3] a[4]
The amount of storage space required to hold an array is directly related to its type and size of
the array.
The total size can be calculated using the relation.
Total-size=sizeof(type)*size-of-array.
CONTROL STATEMENTS
1. What are the different types of control statements? Explain.
Selection statements
Iteration statements.
Selection statements: This allows us to select a statement or set of statements for execution based
on some condition.
Different types of selection statements are:
I. if statement, ii. If-else statement, iii. Nested statement, iv. Switch statement.
Iteration statement or loop statement: Iteration is a loop that allows repeated execution of a
set of instructions certain condition is satisfied.
i. While loop, ii. Do-while loop, iii. For-loop.
18
2. Explain different types of selection statements.
Ans: If statement: This is the simplest if statement. is called as one-way branching. It is used to
decide a statement is true or false.
The general format is
if (condition)
{
Statement 1;
Statement2;
……..
Statement;
}
if else-if statement:
This structure is also called as else-if ladder. This statement allows a choice to be made between
different possible alternatives. A choice must be made between more than possibilities.
Syntax:
If (condition1)
Statement1;
else
If(condition2)
Statement2;
else
………………….
else
If (condition-n)
Statement n;
else
default statement;
Switch statement
This is a built in multiple-branch selection statement in which it successively test the value of an
expression against a list of integer or character constants. When a match is found the statement
associate with that constant are executed.
Syntax
switch(Expression)
{
case label-1: statement-1;
break;
case label2: statement-2;
break;
………………..
case label-n: statement-n;
break;
default: default statement;
19
}
3. Explain do and do-while and while –do statement.
While loop:
This looping structure is also called as pre-tested looping structure. This statement repeat the
execution of a set of statements while the condition is true.
General syntax:
while (test-condition)
{
Statement1;
Statement2;
…………….
Statement n;
}
Ex: while (n!=0)
{
Digit=n%10;
Sum=sum+digit;
. n=n/10;
}
Do-while loop
This is post tested loop. It checks the condition after the execution of the statement. This means
that the do-while loop always executes at least once.
Syntax:
do
{
Statement1;
Statement2;
……………
Statement-n;
} while (test-condition);
Example:
do
{
cout<<setw(4)<<I;
I=I+2;
} while(I<=25);
4. Explain for loop.
This statement is called fixed loop. It is used when we know in advance exactly how many times a
set of statements should be repeatedly executed again and again. It provide initialization, loop-
end –condition and increment statement in a single line.
The general format:
for(initialization; condition; increment)
{
20
Statement1;
Statement2;
…………..
Statement;
}
Example:
for(i=1; i<=n;i=i+1)
cout<<setw(4)<<I;
getch();
}
5. Explain selection constructs.
Simple if : if(test condition)
Statement1;
Statement2;
If-else statement:
If (test-condition)
Statement1;
else
Statement2;
If –else –if statement:
If (test-condition-1)
statement1
else
If test condition2
Statement-2
else
…….
else
If(test condition –n)
Statement-n;
else
default statement;
Nested if statement:
If and if statement has another if statement with it then it is called nested if.
Syntax:
if(testcondition-2)
Statement1;
else
21
Statement2;
else
if(statement 3)
Statement3;
else
Statement4;
Multiple selection statement:
If there are more than two alternatives the we use multiple selection statement.
switch(expression)
{
case label1: statement1;
break;
case label2: statement 2;
break;
………………..
case label-n: statement –n
break;
default: default statement;
}
6. What are the different approaches of problem solving?
1. Top –down design
Top down design involves dividing a problem into sub- problems and further dividing the
sub problems into smaller sub problem until it leads to sub-problems that can be
implemented as program statement.
Advantages:
It imitates the human tendency to solve a problem by outlining the broad concepts first
and the subsequently going into the details.
The assumptions at a level continues and the development of next level sub problems can
take place in parallel.
2. Step-wise refinement
The process of breaking down the problem at each stage to obtain a computer solution is
called stepwise refinement:
3. Bottom-up design:
This approach is the reverse of top-down design. This process starts with identification of
a set of modules which is either available or to be constructed.
FUNCTION
1. Explain any five string manipulation functions.
a.strlen( ) function:- It is used to find the length of the string.
Syntax: Var=strlen(string);
22
eg: l=strlen(“empress”); returns 7
b.strcat( ) – It is used to concatenate two strings.
Syntax:strcat(string1, string 2);
eg: char str1[]=”Win”; char str2[]=”dows8”;
strcat(str1,str2); str1 becomes “Windows 8”
c. strcpy( ) – It is used to copy a string into another string.
Syntax: strcpy(string1, string2);
eg: char str1[]=”Computer”; char str2[]=”Science”;
strcpy(str1,str2); str1 becomes “Science”
d.strcmp( )-It is used to compare a string with another string. This function is case
sensitive.
Syntax: strcmp(string1, string2); eg: char str1[]=”There”; char str2[]=”there”;
strcmp(str2,str1); gives a positive value.
e.strcmpi( )- It is used to compare a string with another string. But it is not case sensitive.
Syntax: strcmpi(string1, string2); eg: char str1[]=”There”; char str2[]=”there”;
strcmpi(str2, str1); gives 0.
2. Explain any five character manipulation functions.
a.isalpha( ) – It returns a non-zero value if the character is a letter. Otherwise it returns
zero.
Eg: isalpha(„h‟); returns 1. isalpha(„9‟); returns 0.
b. isdigit( )- It returns a non – zero value if the character is a digit. Otherwise it returns
zero. Eg: isdigit(„9‟); returns 1. Isdigit(„h‟); returns 0.
c.isalnum( )-It returns a non-zero value if the character is a letter or digit. Otherwise it
returns zero. Eg:isalnum(„9‟); returns 1 isalnum(„!‟); returns 0.
d.islower( )-it returns a non-zero value if the character is lowercase letter. Otherwise it
returns 0. Eg:islower(„s‟); returns 1. islower(„S‟); returns 0.
e.isupper( )-It returns a a non-zero value if the character is uppercase letter. Otherwise
it returns 0. Eg:isupper(„s‟); returns 0. isupper(„S‟); returns 1.
USER DEFINED FUNCTION
1.What are the advantages of functions?
a. If there is a set of statements to be repeated several times in the program, these statements can
be replaced as a function and called wherever required.
b. If a task is needed in more than one program or to a group of programmers, a function can be
developed and made available to other programs or other programmers.
c. Programs can be modularized into functions. Each function can be developed independently,
debugged and tested.
d. If a problem is divided into sub-problems, a team of programmers can be formed to solve each
sub-problem, rather solving by a single person.
e. If functions are developed in a program, the number of lines decreases.
2. Explain the structure of function with an example.
return-type function-name(argument with declaration)
{ local-variable declarations;
23
Executable statements1;
…………….
Executable statements2;
return (expression);
}
return type specifiers – the datatype of the value return by the function to another function when
it is called.
Function name – it is the name of the function .
Argument list with declaration – it is the list of arguments with their declaration.
Local variable declaration – It is the declaration of the variables that are used within the
function.
Executable statements – These are the statements that perform the necessary operations to solve
the problem.
Local declaration and executable statements are together called as body of the function. The
body of the function should be enclosed within the braces.
3.Mention different types of functions? Explain any one with syntax and example.
a. Functions with no arguments and no return value.
b. Functions with arguments and no return value.
c. Functions with no arguments and with return value.
d. Functions with arguments and with return values.
e. Recursive functions.
a. Functions with no arguments and no return value.
In this method, the function simply performs an independent task. The function does not receive
or send any arguments.
Syntax: void function( )
{ statements; }
Eg: void natural( )
{ for(int i=1;i<=10;i++)
cout<<i; }
4. What is function prototype? Explain with syntax and example.
The declaration of a function is called as a function prototype. It tells the program about the type
of the value return by the function and the number and type of arguments.
Syntax: return-type function-name(argument list);
Eg: float volume(int x,float y, float z);
5. What is the difference between actual arguments and formal arguments?
Actual arguments:-The function call statements contains name of the function and list of
arguments to be passed. These arguments or parameters are called as actual arguments. The
arguments can be constants, variables or expressions.
Eg: g=gcd(a,b); here a & b are the actual arguments.
Formal arguments:- The function header contains return-type specifier, function name and the
list of arguments with their declaration. These arguments are called as formal arguments or
dummy arguments. Formal arguments get their values from the actual arguments.
24
Eg: int gcd(int x,int y); here x & y are the formal arguments.
6. What is the difference between pass by value and pass by reference?
Pass by value:- A function can be called by passing arguments from the calling function into the
called function. Thus the data is transferred through argument list. The calling function sends
the data to the called function through actual parameters. The called function receives the data
into its corresponding formal parameters. This is pass by value. In pass by value, a copy of the
data sent by the calling function is stored in temporary storage locations. The called function
uses these values as the initial values of the formal parameters. The formal arguments are
processed or changed to generate the required results. However, these changes are affected to
the original stored in the actual parameters.
Pass by reference:- When we pass arguments by reference, the formal arguments in the called
function become the aliases to the actual arguments of the calling function. ie, the called
function is actually uses the original data with a different name.
STRUCTURE 1.Define a structure with syntax and example.
A structure is a collection of simple variables. The variables in a structure can be of same or
different types. The data items in a structure are called the members of the structure.
Syntax: struct structure-name
{ datatype member1;
datatype member2;
…….};
eg:struct emp
{ int idno;
char name[15];
};