CHAPTER NO 01
INTRODUCTION TO PROGRAMMING
Introduction to Programming
1. Q: What is programming?
A: Writing instructions (in the form of code) for a computer to perform tasks.
2. Q: Why is programming essential?
A: It automates tasks and solves problems efficiently.
1.1 Problem Solving
3. Q: What is problem solving in programming?
A: Breaking down complex issues into manageable steps for coding.
1.2 Program
4. Q: What is a program?
A: A set of coded instructions that a computer follows.
5. Q: What are the benefits of a computer program?
A: Speeds up tasks, reduces errors, and handles complex calculations.
1.3 Algorithms & Pseudo Code
6. Q: What is an algorithm?
A: A step-by-step solution to a problem.
7. Q: What are key properties of an algorithm?
A: Clarity, efficiency, and a finite sequence of steps.
8. Q: Why is pseudo code used?
A: pseudo code is a simplified way of representing an algorithm using a combination of
plain English and programming-like syntax. It simplifies complex algorithms into
readable steps before coding.
1.4 Flowchart
9. Q: What is a flowchart?
A: A visual diagram representing the steps of an algorithm or graphical representation of
a code.
10. Q: What are flowchart symbols used for?
A: To represent actions, decisions, and flow in a process.
11. Q: How do you create an effective flowchart?
A: Use standard symbols and keep the flow clear and simple.
12. Q: What is a drawback of flowcharts?
A: They can become complex and hard to read for large programs.
13. How does a flowchart differ from an algorithm?
A: A flowchart is a visual representation, while an algorithm is a written description of steps.
14. Explain the role of a language processor in programming.
A language processor is a program that translates source code into machine-readable code (object
code).
1.5 Program Development Process
13. Q: What is the program development process?
A: A series of steps: analysis, design, coding, testing, and maintenance.
1.6 Programming Languages
14. Q: What are low-level languages?
A: Languages close to machine code, like assembly language.
15. Q: What are high-level languages?
A: Languages closer to human language, like Python and Java.
16. Q: What is procedural programming?
A: A style focusing on sequences of instructions. It executes the code in chronological
order.
17. Q: What is object-oriented programming (OOP)?
A: A style that organizes code into objects representing real-world entities.
18. Q: What is non-procedural programming?
A: Focuses on what to achieve rather than how to achieve it.
19. Q: How do low-level and high-level languages differ?
A: Low-level is closer to machine code; high-level is more human-readable.
20. Q: What are natural programming languages?
A: They aim to use human language-like syntax for easier understanding.
1.7 Types of Codes
21. Q: What is source code?
A: The original code written by the programmer.
22. Q: What is object code?
A: The machine-readable code generated from source code.
23. Q: What is the difference between source and object code?
A: Source code is human-readable, while object code is machine-readable.
1.8 Language Processor
24. Q: What is a compiler?
A: A tool that converts source code into object code all at once.
25. Q: What is an interpreter?
A: A tool that translates and executes code line by line. that is why, it is slower than
compiler.
26. Q: What is an assembler?
A: It converts assembly language into machine code.
27. Q: How does a compiler differ from an interpreter?
A: A compiler translates the entire code at once, while an interpreter translates code line
by line.
1.9 Programming Techniques
28. Q: What is structured programming?
A: A technique that organizes code into clear, reusable blocks.
29. Q: What is object-oriented programming used for?
A: For organizing code around objects, which makes managing complex code easier.
30. Q: What is event-driven programming?
A: A technique that responds to user actions, like clicks and keystrokes.
31. Q: What is visual programming?
A: A technique that uses visual elements instead of text to create programs.
Additional Specifics
32. Q: What are guidelines for drawing a flowchart?
A: Use standard symbols, keep it simple, and ensure logical flow.
33. Q: What is the purpose of algorithms in programming?
A: To provide a clear, logical approach to solving a problem.
34. Q: Why is debugging important in the program development process?
A: It identifies and fixes errors to ensure the program functions correctly.
35. Q: What is a natural language example in programming?
A: Languages designed to be intuitive and closer to human language, like Apple’s Swift
Playgrounds for beginners.
36. Explain the difference between a problem and a solution.
A: A problem is a challenge or an issue that needs to be addressed. A solution is a way to
solve the problem.
CHAPTER NO 02
Introduction to C++
1. What is C++?
C++ is a programming language used to create software.
2. Who created C++?
Bjarne Stroustrup developed C++.
3. When was C++ created?
C++ was created in 1979.
4. What was the main goal of C++?
To add object-oriented features to C.
5. Name one key feature of C++.
Object-oriented programming.
6. What is a Preprocessor Directive?
Commands that start with #, like #include.
7. What is the purpose of #include?
It includes libraries needed for a program.
8. What is a Header File?
A file containing code libraries, like <iostream>.
9. Why are header files used?
To use predefined functions in programs.
10. What is the main() function?
The starting point of a C++ program (from where execution starts).
11. Why is main () important?
It tells the program where to begin.
12. What is a statement in C++?
A single line of code that performs an action.
13. Give an example of a C++ statement.
int a = 5;
14. What is a Token in C++?
The smallest unit in a program likes keywords or symbols.
15. Name a common C++ keyword.
int, return, or if.
16. What are white spaces in C++?
Spaces, tabs, or new lines in the code.
17. Do white spaces affect the code?
No, they only improve readability.
18. What is Turbo C++?
An older software for writing and compiling C++ programs.
19. Why was Turbo C++ popular?
It was simple and fast for learning C++.
20. How can you install Turbo C++?
By downloading and setting it up on a computer.
21. What file type does Turbo C++ use?
.cpp for C++ files.
22. What is a compiler?
A tool that translates code into machine language.
23. Why is a compiler needed?
To run C++ code on a computer.
24. What is an IDE?
An Integrated Development Environment for coding.
25. Name one alternative to Turbo C++.
Visual Studio or Code::Blocks.
26. What library is used for input and output in C++?
<iostream>.
27. What is cout used for?
To display output on the screen.
28. What symbol ends most statements in C++?
A semicolon (;).
29. What does return 0; do in main ()?
It ends the program successfully.
30. Is C++ a low-level or high-level language?
C++ is a high-level language
31. What is the Turbo C++ IDE?
An environment for writing and running C++ code.
32. What does initializing Turbo C++ mean?
Setting it up to start programming.
33. Why do we set up directories in Turbo C++?
To organize and save our files.
34. How do you create a new program in Turbo C++?
By choosing "New" in the file menu.
35. What is editing in Turbo C++?
Changing or writing code in the program
36. How do you save a C++ program in Turbo C++?
By selecting "Save" or pressing Ctrl + S.
37. Why is saving a program important?
To avoid losing your work.
38. What is compiling in Turbo C++?
Converting code into machine language.
39. What shortcut compiles the code in Turbo C++?
Alt + F9 compiles the code.
40. What happens if there is an error during compilation?
The program won’t run.
41. What is linking in Turbo C++?
Connecting compiled code with libraries.
42. Why is linking needed?
To make the program executable. linker connects different files to source code to generate .exe
file
43. What does executing a program mean?
Running the program to see results.
44. Which key executes the program in Turbo C++?
Ctrl + F9 run the program.
45. What is debugging?
Finding and fixing errors in the code.
46. Why is debugging important?
It ensures the program works correctly.
47. What are the types of errors in C++?
Syntax, logical, and runtime errors.
48. What is a syntax error?
A mistake in code structure or spelling.
49. Give an example of a syntax error.
Missing a semicolon (;).
50. What is a logical error?
When the code runs but gives wrong output.
51. What is a runtime error?
An error that happens when the program is running.
52. How can you fix syntax errors?
By checking code structure and spelling.
53. What is the debugging feature in Turbo C++?
Tools that help find and fix errors.
54. What is Dev-C++?
Another IDE for writing C++ code.
55. How is Dev-C++ different from Turbo C++?
Dev-C++ is newer and has a modern interface.
56. Can Dev-C++ be used for C++ programming?
Yes, it is also used for C++ coding.
57. What is a common use for Dev-C++?
Writing, compiling, and running C++ code.
58. What are debugging tools?
Tools to help identify and fix issues in code.
59. What is the purpose of debugging features?
To help make the program error-free.
60. Why should you learn debugging?
To improve problem-solving skills in programming.
Compilation process in c++: (assembler in the diagram is not included in
compilation system of c++)
CHAPTER NO 03
Programming in C++
1. What is an identifier in programming?
An identifier is a name used to identify elements like variables, functions, classes, etc., in a
program.
2. Can you name some types of identifiers?
Types of identifiers include variable names, function names, class names, array names, and
constant names.
3. Why are identifiers important in coding?
Identifiers are important because they help organize and uniquely reference different elements,
making the code readable and maintainable.
4.What is a keyword in programming?
A keyword is a reserved word in a programming language that has a specific meaning and cannot
be used as an identifier. Keyword cannot be used as a name of identifier.
5.Can you give examples of keywords?
Examples of keywords include if, else, while, return, and class.
6.Why are keywords important in a programming language?
Keywords are important because they define the structure and syntax of a programming
language, guiding how code should be written and executed. They are used in a program to
store different values.
7.How do data types affect memory allocation in a program?
Different data types require different amounts of memory; for example, integers and float
generally occupy 4 bytes in memory while char occupy 1 byte in memory.
8.What is the difference between primitive and non-primitive data types?
Primitive data types are basic types provided by the language (like int, float, char,bool), while
non-primitive data types are more complex structures created by combining primitive types (like
arrays, classes, and lists).
9.What is typecasting, and why is it useful?
Typecasting is converting a variable from one data type to another. It’s useful for performing
operations that require matching data types, like combining integers and floats in arithmetic.
10.How do data types impact the operations you can perform on data?
The data type determines the operations you can perform on data; for example, arithmetic
operations are typically valid for numbers but not for strings.
11.Can you explain what a Boolean data type is and where it’s used?
A Boolean data type holds true or false values (0 or 1). It’s commonly used in conditional
statements and logical operations.
12.What is a variable in programming?
A variable is a named storage location in memory that can hold a value, and this value can be
changed during program execution.
13.What is a constant, and how is it different from a variable?
A constant is a named value that cannot be changed once it is defined, unlike a variable which
can be modified.
14.Why are variables important in programming?
Variables are important because they allow you to store, retrieve, and manipulate data within a
program.
15.Can you give examples of when you might use a constant?
Constants are useful for fixed values, like PI in calculations or a maximum score in a game, that
should not change during program execution.
16.How do you declare a constant in your preferred programming language?
The method varies; for example, in C, you use const, while in Python, you usually use all caps
for variable names (e.g., MAX_SIZE) by convention to indicate a constant.
17.What are the benefits of using constants in your code?
Constants improve code readability, reduce errors by preventing unintended changes, and make
the code easier to maintain and understand.
18.What is an expression in programming?
An expression is a combination of variables, values, and operators that evaluates to a result.
19.What is an operator, and how is it used in expressions?
An operator is a symbol that performs a specific operation on one or more operands, such as
addition or comparison, within an expression.
20.What are relational operators, and how do they work?
Relational operators compare values and return a boolean result. Examples include == (equal to),
!= (not equal to), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or
equal to).
21.How are logical operators used in programming?
Logical operators are used to combine multiple boolean expressions. They include && (AND), ||
(OR), and ! (NOT), which help in creating complex conditions in conditional statements.
22.What is an assignment operator, and can you give examples?
Assignment operators assign values to variables. The basic one is = (simple assignment), but
there are also compound operators like +=, -=, *=, and /=, %= which combine assignment with
arithmetic.
23.What are bitwise operators, and where are they commonly used?
Bitwise operators perform operations on individual bits of numbers, like & (AND), | (OR), ^
(XOR), ~ (NOT), << (left shift), and >> (right shift). They are used in low-level programming,
such as handling binary data.
24.Can you explain what a ternary operator is and give an example?
The ternary operator ?: is a shorthand for an if-else statement. It takes the form condition ?
value_if_true : value_if_false. For example, int result = (a > b) ? a : b; assigns the greater of a or
b to result.
25.What are increment and decrement operators, and how do they work?
Increment (++) and decrement (--) operators increase or decrease a variable’s value by one,
respectively. They can be prefix (e.g., ++a) or postfix (e.g., a++), affecting the timing of the
value change in expressions.
27.What is type casting in programming?
Type casting is the process of converting a variable from one data type to another.
28.What are the types of type casting?
The main types are implicit casting (automatic conversion by the compiler) and explicit casting
(manual conversion by the programmer).
29.What is the difference between implicit and explicit type casting?
Implicit casting is done automatically when there’s no data loss, while explicit casting requires
the programmer’s intervention, often to convert incompatible types or when there may be data
loss.
30.Can you give an example of explicit type casting?
An example is converting a double to an int using (int) value, which truncates the decimal
portion of the number.
31.Why is type casting important in programming?
Type casting allows for compatibility between different data types, enabling operations and
functions to work across types.
32.What is a comment in programming?
A comment is a non-executable line or block of text in code that is used to explain or annotate
parts of the code for better understanding.
33. what are the types of comments, and how are they used?
The two main types are single-line comments (often marked with // in languages like C++ and
Java) and multi-line comments (enclosed with /* */).
34.Why are comments important in programming?
Comments improve code readability, making it easier for others (or yourself) to understand,
maintain, and debug the code.
35.When should you use comments in your code?
Comments should be used to explain complex code, outline logic, or provide information about
functions, variables, or classes.
36.Can too many comments be a bad thing? Why or why not?
Yes, excessive comments can increase the code, especially if they explain self-explanatory code.
Comments should add value without being redundant (repetition).
CHAPTER NO 04
Input and output
37.What is input in programming?
Input refers to the data or information provided to a program during its execution, which the
program uses for processing.
38.What is output in programming?
Output is the result or information produced by a program after processing the input data,
displayed to the user or stored for later use.
39.Can you explain the difference between standard input and standard output?
Standard input (stdin) is a stream from which a program reads input data, typically from the
keyboard, while standard output (stdout) is a stream where a program writes its output, usually
displayed on the screen.
40.How do you read input from the user in your preferred programming language?
In C++, you can use input() to read user input, while in C++, you can use std::cin for input
41.What is the purpose of standard error (stderr)?
Standard error (stderr) is a stream used for outputting error messages or diagnostics separate
from standard output, allowing error messages to be directed to a different destination if
needed.
42.Can you describe how to redirect standard input and output in a command-line
environment?
In a command-line environment, you can use the < operator to redirect standard input from
a file and > to redirect standard output to a file. For example, program < input.txt > output.txt
reads from input.txt and writes to output.txt.
43.Why is it important to handle input and output correctly in a program?
Proper handling of input and output is essential for ensuring data integrity, user interaction, and
error reporting, which affects the overall usability and reliability of the program.
44.What is an escape sequence in programming?
An escape sequence is a combination of characters that represents a special character within a
string, typically starting with a backslash (\).
45.Can you list some common escape sequences and their meanings?
Common escape sequences include:\n – New line
\t – Tab
\\ - Backslash
\’ – Single quote
\” – Double quote
46.How are escape sequences used in strings?
Escape sequences are used within string literals to insert special characters or to format the string
for better readability, like adding new lines or tabs.
47.What happens if you use a backslash at the end of a string?
If a backslash is placed at the end of a string, it escapes the next character, which can lead to
syntax errors or unintended behavior if the next character is not a valid escape sequence.
48.Why are escape sequences important in programming?
Escape sequences are important because they allow programmers to include special characters in
strings, control formatting, and manage user input effectively without causing errors in code.
49.Can you explain how to use escape sequences in a string for formatting output?
For example, in Python, using print(“Hello\nWorld!”) will print “Hello” on one line and
“World!” on the next line, demonstrating how \n creates a new line.
50.How do escape sequences vary between programming languages?
While many escape sequences are similar across languages, some may differ in their usage or
representation. For example, JavaScript also uses escape sequences like \b for backspace, which
may not be present in other languages.
51.What are manipulators in C++?
C++ manipulators are used to format output of a program in different styles.
Some important manipulators in C++ are:
A header file, iomanip, must be used in any program that uses setw() manipulator which
uses to set space between different outputs or display value of an expression in specific
column.
Floating-point values may be rounded to a number of significant digits, or precision,
which is the total number of digits that appear before and after the decimal point. You
can control the number of significant digits with which floating-point values are
displayed by using the setprecision manipulator.
A manipulator, fixed, forces cout to print the digits in fixed-point notation, or decimal.
If we want the numbers padded with trailing zeroes, we must use the showpoint
manipulator. With most compilers, trailing zeroes are displayed when the setprecision
and fixed manipulators are used together.
CHAPTER NO 05 & 06
Conditional structures
1. What is control structure and types of control structure?
Statement used to control flow of execution in a program. The instructions in a program
can be organized into three types of control structures.
In sequential structure, statements are executed in a same order in which they
are specified in a program.
A selection structure select a statement or set of statements to execute on the
basis of a condition. When condition is true, statement is executed otherwise not
executed.
A repetition structure execute a statement or set of statements repeatedly by
using loops.
Function call is a type of statement that moves the control to another block of
code. The control return backs after executing the statement in the block.
2. What are functions in c++ and why they are needed?
A function is a Block of code that performs a specific task, can be invoked whenever
needed. Functions are used to avoid repetition of same code in a program and increase
readability of program.
3. What is use of if-else statement?
The if/else statement will execute one group of statements if the expression is true, or
another group of statements if the expression is false .
4. Why we use switch statement?
Switch statement is alternate of nested if-else statements in C++. The switch statement
lets the value of a variable or expression determine where the program will branch .
5. Why break statement is used in switch?
Break statement is used in each block of case in switch statement to exit from that block
of code. if switch statement is not used, all the case labels coming after matching body
will execute.
6. Why we use default label in switch statement?
The statement in default label will execute when the result of each expression in switch
statement will not match with case label.
7. What is use of if/else-if statement?
The if/else if statement tests a series of conditions. It is often simpler to test a series of
conditions with the if/else if statement than with a set of nested if/else statements.
8. What is the use of nested if statement?
To test more than one condition, an if statement can be nested inside another if statement .
9. Write about different types of loops?
The while loop (pretest loop) can be used to create input routines that repeat until
acceptable data is entered. When programmer is concerned in checking specific
condition, he uses this loop.
The do-while loop is a posttest loop, which means its expression is tested after
each iteration. this loop terminates with semi-colon.
The for loop is ideal for performing a known number of iterations.
10. What happens when condition in do-while loop is false initially?
When condition in a do-while loop is false initially, the statement will execute once and
then program will terminate because it is posttest loop.
11. Write syntax of all loops.
for loop:
for ( initialization; test; update )
{
statement;
statement;
// Place as many statements here as necessary.
}
Do-while loop:
do { statement ;
statement ;
// Place as many statements here as necessary.
} while ( expression );
While loop:
while (condition)
{ // do some work
}
12. What is compound condition?
A compound condition is a combination of multiple conditions in a single statement
usually using logical operators such as AND , OR or NOT operators.
13. What are arithmetic operators in C++?
+, -, * ,%,/ ,++, -- are arithmetic operators in C++ to perform arithmetic operations.
14. Write about usage of modulus and division?
When a programmer needs quotient, he use division, while when he needs reminder, he
use modulus.