1. 1. What is computer?
ANS: A computer is a device that can be instructed to carry out sequences of
arithmetic or logical operations automatically via computer programming.
2. What is computer program?
ANS: A computer program is a set of instructions for a computer to follow
3. What is Computer software?
ANS: Computer software is the collection of programs used by a computer
4. Discuss Computer Vs Human?
ANS: Computers understand a language variously known as computer language or machine language.
Therefore, computers and humans have agreed to sort of meet in the middle, using intermediate
languages
• Humans can speak C++ (sort of), and C++ is converted into machine language for the computer to
understand
5. What is Compilers?
ANS: Translate high-level language to machine language
6. What is source code?
ANS: Sourcecode: the original program in a high level language
7. What is object code?
ANS: the translated version in machine language
• Object code is also referred to as binary code or machine code
8. What is Linker?
• ANS: A Linker combines
• The object code for the programs we write
and
• The object code for the pre-compiled routines
into
The machine language program the CPU can run.
9. Why Do We Need Object-Oriented Programming?
ANS: Object-oriented programming was developed because limitations were discovered in earlier approaches
to programming. To appreciate what OOP does, we need to understand what these limitations are and how
they arose from traditional programming languages.
10. What is procedural language?
ANS: C, Pascal, and similar languages are procedural languages. That is, each statement in the language tells the
computer to do something.
11. What is class?
ANS: A class is a description of a number of similar objects.
12. What is instance of class?
Chapter 1: Object Oriented Programming in C++
2. ANS: specific people with specific names are members of this class if they possess certain characteristics. An
object is often called an “instance” of a class.
13. What are oo p characteristics?
14. What are the benefits of oop?
ANS:
15. What is Algorithm?
ANS: Algorithms
◦ A sequence of precise instructions which leads to a solution
Program
◦ An algorithm expressed in a language the computer can understand
16. How many types the problem solving in c++?
ANS: Problem Solving Phase
Implementation Phase
17. What is Problem solving Phase?
Develop the algorithm before implementation
18. What is implementation Phase?
ANS: Translate the algorithm into a programming
language
19. What are the three errors of programming language?
3. Syntaxerrors
Run-time errors
Logicerrors
END Chapter1
20. What is Function?
ANS: Functions are one of the fundamental building blocks of C++. The FIRST program consists almost
entirely of a single function called main ( ).
21. What is comment?
ANS: Comments help the person writing a program, and anyone else who must read the source file,
understand what’s going on.
22. Two types of comment?
ANS: Single-line comment which begins with // and terminates at the end of the current line.
Multi-line comment which begins with /* and ends with */.
23. What is Variable?
ANS: A variable is a location in the computer's memory where a value can be stored for use by a
program.
All variables must be declared with a name and a data type before they can be used in a program
Declarations of variables can be placed almost anywhere in a program
That value is actually placed in the memory space assigned to the variable.
Chapter2 C++Programming Basics
4. 24. Tell the Basic Data base
25. Tell Their Basic Range
26. What is difference B/wee Expressions and Statements?
ANS: Any arrangement of variables, constants, and operators that specifies a computation is called an
expression.
Statements tell the compiler to do something and terminate with a semicolon.
27 Tell the rules of operator precedence?
ANS: PEDMAS (Parentheses, Exponents, Division, Multiplication, Addition and Subtraction)
END Chapter2
5. Q1: what is called operator that compares two values?
A1: A relational operator.
Q2: what do loops cause?
A2: Loops cause section of your program to be repeated a certain number of times.
Q3: what are three kinds of loops in C++?
• A3:There are three kinds of loops in C++:
• the for loop
• the while loop
• and the do loop
Q4: what is for loop?
A4: The for loop executes a section of code a fixed number of times.
Q5: when for loop used?
A5:It’s usually used when you know, before entering the loop, how many times you want to execute the code.
Q6: when while loop used?
A6: The while loop is used when you do not know how many times you want to do something before you start
the loop.
Q7: when test of while loop is evaluated?
A7: The test expression is evaluated at the beginning of the loop.
Q8: which have higher precedence arithmetic and rational operators?
A8: Note that arithmetic operators have a higher precedence than relational operators
Example (a < b / 2)
Q8: when do loop used?
A8: Use do loop when you want to guarantee that the loop body is executed at least once.
Chapter3 C++Programming Loops
6. Q9: when test of do while is evaluated?
A9: The test expression is evaluated at the end of the loop.
Q10: what do break and continue statement are used?
A10: break and continue statements are used to alter the flow of loops.
Q11: what are three types of decisions?
A11:
The if statement
The if...else statement
Nested if...else statement
The switch statement
Q12: what does if statement performs?
A12: The if statement performs an action if a condition is true or skips the action if the condition is false.
END Chapter3
Q1. Define function? And tell the most important reason to use functions?
A1. A function groups a number of program statements into a unit and gives it a name.
The most important reason to use functions is to:
Chapter4 C++ Programming Function
7. • Divide a program into units (divide & conquer).
• Reduce program size: the function’s code is stored in only one place in memory,
even though the function is executed many times.
Q2.What is the three components necessary to add a function to a program?
A2.The three components necessary to add a function to a program are:
a. the function declaration
b. the calls to the function
c. And the function definition.
Q3.Distinguish the different b/w function declaration, calling and function Definition?
A3. Function Declaration
Declare the function before it is called
Notice that the function declaration is terminated with a semicolon.
Function declarations are also called prototypes, since they provide a model or
blueprint for the function.
The keyword void specifies that the function has no return value, and the empty
parentheses indicate that it takes no arguments
Function calling
• To call a function we need: the function name, followed by parentheses.
• The syntax of the call is very similar to that of the declaration, except that the
return type is not used.
• The call is terminated by a semicolon.
Function definition
• The definition contains the actual code for the function.
• The definition consists of a line called the declarator, followed by the function
body.
8. • The declarator must agree with the declaration: It must use the same function
name, have the same argument types in the same order (if there are arguments),
and have the same return type.
• Notice that the declarator is not terminated by a semicolon.
Q4.Define declaration and tell some library functions?
A4.The declaration is in the header file specified at the beginning of the program (conio.h
for getche () and cmath.h for sqrt()).
Some library function such as getche () or sqrt ()?
Q5.What is an argument and parameters?
• An argument is a piece of data passed from a program to the function.
• Arguments allow a function to operate with different values, or even to do
different things, depending on the requirements of the program calling it.
The variables used within the function to hold the argument values are called
parameters.
Q6. What is the different b/w passing by value and passing by reference?
A6.Passing by value
• Passing by value means that the function creates copies of the arguments passed
to it. The called function creates a new variable of the same type as the argument
and copies the argument’s value into it.
• The function cannot access the original variable in the calling program, only the
copy it created.
• Passing arguments by value is useful when the function does not need to modify
the original variable in the calling program.
• In fact, it offers insurance that the function cannot harm the original variable.
Passing by reference
9. • In passing arguments by reference, a reference to the original variable, in the
calling program, is passed. (It is actually the memory address of the variable that
is passed).
• An important advantage of passing by reference is that:
The function can access the actual variables in the calling program.
It provides a mechanism for passing more than one value from the function
back to the calling program.
Q7.Describe Overloaded Functions with example?
A7.An overloaded function performs different activities depending on the kind of data
sent to it. It is more convenient to use functions with the same name even though they
each have different arguments.
Examples
• Declaration:
Voiddrawchar ();
Voiddrawchar (char);
Voiddrawchar (char, int);
• Calling:
Draw char ();
Draw char ('=');
Draw char ('+', 30);
Q8.What is Recursion?
A8.Recursion involves a function calling itself. Recursion is much easier to understand
with an example than with lengthy explanations.
10. Q9. What is Default Arguments?
A9.A function can be called without specifying all its arguments.
• The default argument follows an equal sign, which is placed directly after the type
name.
• Remember that missing arguments must be the trailing arguments—those at the
end of the argument list.
Q10. Differentiate Scope and Storage Class?
A10.scope
• The scope of a variable determines which parts of the program can access it, and
its storage class determines how long it stays in existence.
• Two different kinds of scope are important here: local and file.
Variables with local scope are visible only within a block.
Variables with file scope are visible throughout a file.
Storage Class
• A block is basically the code between an opening brace and a closing brace. Thus
a function body is a block.
• There are two storage classes: automatic and static.
• Variables with storage class automatic exist during the lifetime of the function in
which they are defined.
• Variables with storage class static exist for the lifetime of the program.
END Chapter4