Search This Blog

Showing posts with label Computer Science x New. Show all posts
Showing posts with label Computer Science x New. Show all posts

Monday, 7 November 2022

UNIT 04: CONTROL STRUCTURE - Question Answers - Computer Science For Class X (2021 and Onward)

GO TO INDEX

Computer Science For Class X
Unit 04: Control Structure
Question Answers


Q.1: What are control structures?
Ans. CONTROL STRUCTURE / STATEMENTS:
Control structures control the flow of execution in a program or function. Control structure are used to repeat any block of code, transfer control to specific block of code and make a choice by selection. There are three basic control structures in C++ progamming.
  1. Selection / Decision making Control Structure
  2. Loops / Iteration Control Structure
  3. Jumps

Q.2: Define selection or decision making control structure and name its types.
Ans: SELECTION / DECISION MAKING CONTROL STRUCTURES / STATEMENTS:
The selection control structure allows a number of conditions which lead to a selection of one out of several alternatives. There are three types of selection control structure:
  1. If selection structure/ statement
  2. If-else selection structure/statement
  3. Switch selection structure / statement

Q.3: Define if selection structure with syntax, flow diagram and example.
Ans: SELECTION STATEMENT:
An if statement is conditional statement that test a particular condition. Whenever that condition evaluates as true, performs an action, but if it is not true, then the action is skipped.

SYNTAX:

  The general syntax of if statement is:
 if (condition)
 {
 Statement (s);
 }



FLOW DIAGRAM


if SELECTION STATEMENT EXAMPLE

 #include<iostream>
 using namespace std;
 int main()
 {
 cout << "Enter an integer number:";
 cin >> num;
 if(num>0)
 cout << "You Entered a positive integer:" << num << "\n";
 }
 return0;
 }



OUTPUT

 Enter an integer number: 10
 You entered a positive integer: 10



Q.4: Define nested if selection structure with syntax and example.
Ans: NESTED if STATEMENT:
An if condition can be written as deeply as needed within the body of another statement. This is called nested if statement.

SYNTAX:

 The general syntax of nested if statement is:
 if (condition 1)
 {
 if (condition 2)
 {
 statement;
 }
 }



NESTED if STATEMENT EXAMPLE

  #include<iostream>
 using namespace std;
 int main()
 {
 int exp, status;
 cout << "Enter experience:";
 cin >> exp;
 cout << "\n Enter status:";
 cin >> status;
 if(exp>=4)
 {
 if(status>=2)
 cout << "\n Bonus Given to Employee" <<"\n";
 }
 }
 return0;
 }



OUTPUT

 Enter experience: 6
 Enter status: 3
 Bonus Given to Employee



Q.5: Define if-else selection structure with syntax, flow diagram and example.
Ans: if-else SELECTION STATEMENT:
An if-else selection structure performs certain action when the condition is true and some different action when the condition is false.

SYNTAX:

 The general syntax of if-else statement is:
 if (condition)
 {
 statement(s);
 }
 else
 {
 statement(s);
 }


FLOW DIAGRAM


if-else SELECTION STATEMENT EXAMPLE

 #include<iostream>
 using namespace std;
 int main()
 {
 int number;
 cout << "Enter an integer:";
 cin >> number;
 if(number>=0)
 {
 cout << "\n The number is a positive integer:" << number << "\n";
 }
 else
 {
 cout << "\n The number is a negative integer:" << number << "\n";
 }
 cout << "This line is always printed.";
 return0;
 }


OUTPUT

 Enter an integer: -5
 The number is a negative integer: -5
 This line is always printed.


Q.6: Define else-if selection structure with example.
Ans: else-if SELECTION STATEMENT:
Nested if-else statements test for multiple conditions by placing if-else statement inside if-else statements. When condition is evaluated as true, the corresponding statements are executed and rest of structure is skipped. This structure is also referred as the if-else-if ladder.

else-if SELECTION STATEMENT EXAMPLE

 #include<iostream>
 using namespace std;
 int main()
 {
 int per;
 cout << "Enter your percentage:";
 cin >> per;
 if(per>=80)
 {
 cout << "Your grade is A*:";
 }
 else if(per>=70)
 {
 cout << "Your grade is A:";
 }
 else if(per>=60)
 {
 cout << "Your grade is B:";
 }
 else if(per>=50)
 {
 cout << "Your grade is C:";
 }
 else
 {
 cout << "Failed.";
 return0;
 }


OUTPUT

 Enter your percentage: 70
 Your grade is A:


Q.6: Define switch statement with syntax, flow diagram and example.
Ans: SWITCH STATEMENT:
Switch statements is a control statements that allows to select only one choice among the many given choices. The expression in switch evaluates to return an integer or character value, which is then compared to the values present in different cases. It executes that block of codes which matches the case value. If there is no, match, then default block is executed (if present).

SYNTAX

 The general form of switch statements is,
 switch(variable)
 {
 case constant 1:
 {
 statement (s);
 break;
 }
 case constant 2:
 {
 statement (s); 
 break;
 }
 default:
 {
 statement (s);
 break;
 }
 }


FLOW DIAGRAM


SWITCH STATEMENT EXAMPLE

 #include<iostream>
 using namespace std;
 int main()
 {
 char op;
 float num1, num2;
 cout << "Enter an operator (+, -, *, /):";
 cin >> op;
 cout << "Enter two numbers: " <<"\n";
 cin >> num1 >> num2;
 switch(op)
 {
 case '+':
 cout << num1 <<"+" << num2 << "=" << num1 + num2;
 break;
 case '-':
 cout << num1 <<"-" << num2 << "=" << num1 - num2;
 break;
 case '*':
 cout << num1 <<"*" << num2 << "=" << num1 * num2;
 break;
 case '/':
 cout << num1 <<"/" << num2 << "=" << num1 / num2;
 break;
 default:
 cout << "Error! The operator is not correct";
 }
 return0;
 }


OUTPUT

 Enter an operator: +
 Enter two numbers:
 10 15
 10 + 15 = 25


Q.8: Write down the difference between if-else and switch statement.
Ans: DIFFERENCE BETWEEN if-else & SWITCH STATEMENT:
S.NO. if-else SWITCH
1. if-else statement is used to select among two alternatives. The switch statement is used to select among multiple alternatives.
2. if-else statement can have values based on constraints. Switch statement can have values based on user choice.
3. Float, double, char, int and other data types can be used in if-else condition. only int and char data types can be used in switch block.
4. It is difficult to edit the if-else statement, if the nested if-else statement is used. It is easy to edit switch cases as, they are recognized easily.

Q.9: What are loops or iteration and define its types?
Ans: LOOP / ITERATION CONTROL STRUCTURE:
Iteration or loop in computer programming, is a process wherein a set of instructions or structures are repeated in a sequence a specified, number of times until a condition is true. When the set of instructions is executed again, it is called an iteration. A loop statement allow us to execute a statement or a group of statements multiple times. C++ provides the following types of loops to handle looping requirements.
  1. for loop
  2. while loop
  3. do-while loop

Q.10: Describe for loop with syntax, flow diagram and example.
Ans: for LOOP:
A for loop is a repetition or iteration control structure that repeats a statement or block of statement for a specified number of time. The for-loop statement includes the initialization of the counter, the condition, and the increment. The for loop is commonly used when the number of iteration is known.

SYNTAX
The general syntax of for loop is:

 for(initialization; test condition; increment/decrement)
 {
 statement(s);
 }


FLOW DIAGRAM


for LOOP EXAMPLE:

 #include<iostream>
 using namespace std;
 int main ()
 {
 int i;
 for(i = 1; <= 10; i++)
 {
 cout << i << "";
 }
 return0;
 }


OUTPUT

 1 2 3 4 5 6 7 8 9 10


Q.11: Describe while loop with syntax, flow diagram and example.
Ans: while LOOP:
The while loop allows the programmer to specy that an action is to be repeated while some conditions remain true. It is used when the exact numbert of loop repetitions befor the loop execution begins are not known.

SYNTAX

 The general syntax of while loop is:
 while(condition)
 {
 statement(s);
 }


FLOW DIAGRAM


while LOOP EXAMPLE:

 #include<iostream>
 using namespace std;
 int main ()
 {
 int i = 1;
 while(i <= 10)
 {
 cout << | << " ";
 i++, }
 return0;
 }


Q.12: Describe do while loop with syntax, flow diagram and example.
Ans: do while LOOP:
A do-while loop is similar to a while loop. except that a do-while loop is guaranteed to execute at least one time, even if the condition falls for the first time. Unlike for and while loops, which test the loop condition at the start of the loop, the do while loop checks its condition at the end of the loop.

SYNTAX

 The general syntax of a do-while loop is:
 while(condition)
 {
 do { statement(s);
 }
 while(condition);


FLOW DIAGRAM


do-while LOOP EXAMPLE:

 #include<iostream>
 using namespace std;
 int main ()
 {
 int i = 1;
 do {
 cout << i << " ";
 i++, }
 while (i <=10); return0;
 }


OUTPUT

 1 2 3 4 5 6 7 8 9 10


Q.13: Describe nested loop with example.
Ans: NESTED LOOP:
When one for, while or do-while loop is existed within another loop, they are said to be nested. The side loop is completely repeated for each repetition of the outside loop.

NESTED LOOP EXAMPLE:

 #include<iostream>
 using namespace std;
 int main ()
 {
 int row, column;
 for (row = 1; row <= 5; row++) {
 for (column = 1; column <= 3; column++) { cout << "+";
 cout << "\n";
 }
 return0;
 }


OUTPUT

+ + +
+ + +
+ + +
+ + +
+ + +


Q.14: Write down the differences between for, while and do-while loop.
Ans: DIFFERENCES BETWEEN for, while AND do-while LOOP:
S.NO. for loop while loop do-while loop
1. It is pre-test loop because condition is tested at the start of loop. It is pre-test loop because condition is tested at the start of loop. It is post-test loop because condition is tested at the end of loop which executes loop at least once.
2. It is known as entry controlled loop. It is known as entry controlled loop. It is known as exit controlled loop.
3. If the condition is not true first time then control will never enter in a loop. If the condition is not true first time then control will never enter in a loop. Even if the condition is not true for the first the control will never enter in a loop.
4. There is no semicolon; after the condition in the syntax of the for loop. There is no semicolon; after the condition in the syntax of the while loop. There is a semicolon; after the condition in the syntax of the do-while loop.
5. Initialization and updating is the port of the syntax. Initialization and updating is not the part of the syntax. Initialization and updating is not the part of the syntax.


Q.15: What re jumps statements.
Ans: Jump STATEMENTS:
These statements change the normal execution of program and jumps over the specific part of program.
Following are the jumps statements used in C++.
  1. break
  2. continue
  3. goto
  4. return
  5. exit()

Q.16: Define break statement with example.
Ans: break STATEMENT:
The break statement allows you to exit a loop or a switch statement from any point within its body, bypassing its normal termination expression. It can be used within any C++ structure.

break EXAMPLE:

 #include<iostream>
 using namespace std;
 int main()
 {
 int count;
 for(count = 1; count <=100; count++)
 {
 cout << count;
 if(count = 10)
 break;
 }
 return0;
 }


Q.17: Define continue statement with example.
Ans: continue STATEMENT:
The continue statement is just the opposite of the break statement. Continue forces the next iteration of the loop to take place, skipping the remaining statements of its body.

continue EXAMPLE:

 #include<iostream>
 using namespace std;
 int main()
 {
 int count;
 for(count = 1; count <=10; count++)
 {
 if(count = 5)
 cout << count;
 }
 return0;
 }


Q.18: Define goto statement with Example.
Ans: goto STATEMENT:
In C++ programming, the goto statement is used for altering the normal sequence of program execution by transferring control to some other parts of the program.

goto EXAMPLE:

 #include<iostream>
 using namespace std;
 int main()
 {
 float num, average, sum = 0.0;
 int i, n;
 cout << "Maximum number of inputs:";
 cin >> n;
 for(i = 1; i<=n; i++)
 {
 cout << "Enter number" <<|<<":";
 cin >> num;
 if(num < 0.0)
 {
 // Control of the program move to jump:
 goto jump;
 }
 sum +=num;
 }
 Jump:
 average = sum / (n);
 cout << "\n Average = " << average;
 return0;
 }


Q.19: Define return statement with syntax.
Ans: return STATEMENT:
The return statement returns the flow of the execution to the function from where it is called. This statement does not mandatory need any conditional statements. As soon as the statement is executed the flow of the program stops immediately and return the control from where it was called.

STNTAX:

 return (expression / value);


Q.20: Define exit() statement with Syntax.
Ans: exit() STATEMENT:
The exit function, declared in <stdlib.h>, terminates a C++ program. The value supplied as as argument to exit is returned to the operating system as the program's return code or exit code.

SYNTAX:

 void exit (int);




Tuesday, 11 October 2022

UNIT 03: INPUT/OUTPUT HANDLING IN C++ - Lab Activities - Computer Science For Class X

GO TO INDEX

Computer Science For Class X
Unit 03: Input / Output Handling In C++
Lab Activities

Q.1: Develop programs for manipulating the following formulas.
Title Formula Description
 Calculating speed of an objects=d/t Speed = distance / time
 Newton's second law of motionF=ma Force = mass x acceleration
 Calculating acceleration a = (vf-vi) / t Acceleration is equal to (final velocity - initial velocity) / time
 Area of trianglea = 1/2bh Area = 1/2 (base)(height)
 Convert the Celsius to FahrenheitF = (c*1.8) + 32-

Ans: (i) Calculating speed of an object

 #include<iostream>
 #include <conio.h>
 #include <stdio.h>
 using namespace std;
 int main()
 {
 float speed;
 float d;
 float t;
 cout << "\n \t Enter distance = ";
 cin >> d;
 cout << "\n\t Enter time = ";
 cin >> t;
 speed = d/t;
 cout << "\n\t The speed of the object is = " << speed <<" m/s";
 return 0;
 }



(ii) Newton's second law of motion

 #include <iostream>
 #include <conio.h>
 #include <stdio.h>
 using namespace std;
 int main()
 {
 float f;
 float m;
 float a;
 cout << "\n \t Enter mass = ";
 cin >> m;
 cout << "\n\t Enter acceleration = ";
 cin >> a;
 f = m*a;
 cout << "\n\t The value of F is = " << f <<" N";
 return 0;
 }



(iii) Calculating acceleration

 #include <iostream>
 #include <conio.h>
 #include <stdio.h>
 using namespace std;
 int main()
 {
 float in_velocity;
 float acceleration;
 float f_velocity;
 float time;
 cout << "\n \t Enter the initial velocity of an object in m/s = ";
 cin >> in_velocity;
 cout << "\n\t Enter the final velocity of an object in m/s = ";
 cin >> f_velocity;
 cout << "\n \t Enter the time in seconds = ";
 cin >> time;
 acceleration = (f_velocity - in_velocity)/ time;
 cout << "\n\t The Acceleration of the object is = " << acceleration <<" m/s2";
 return 0;
 }



(iv) Area of triangle

 #include <iostream>
 #include <conio.h>
 #include <stdio.h>
 using namespace std;
 int main()
 {
 float base;
 float height;
 float area;
 cout << "\n \t Enter the base of triangle = ";
 cin >> base;
 cout << "\n\t Enter the height of triangle = ";
 cin >> height;
 area = (base * height);
 cout << "\n\t The area of the triangle is = " << area<<" s2";
 return 0;
 }



(v) Convert the Celsius to Fahrenheit

 #include <iostream>
 #include <conio.h>
 #include <stdio.h>
 using namespace std;
 int main()
 {
 float celsius;
 float fahrenheit;
 cout << "\n \t Enter the temperature in Celsius = ";
 cin >> celsius;
fahrenheit = (celsius * 1.8) + 32;
 cout << "\n\t The temperature in Fahrenheit is = " << fahrenheit<<" F";
 return 0;
 }



Q.2: Write a program to calculate the volume of a box.
Ans: VOLUME OF A BOX:

 #include<iostream>
 #include<conio.h>
 #include<stdio.h>
 using namespace std;
 int main()
 {
 float length;
 float height;
 float volume;
 float width;
 cout << "\n \t Enter the length of box = ";
 cin >> length;
 cout << "\n \t Enter the height of box = ";
 cin >> height;
 cout << "\n \t Enter the width of box = ";
 cin >> width; 
 volume = (length*height*width);
 cout << "\n \t The volume of the box is = " <<volume;
 return 0;
 }



Q.3: Write a program of marksheet, take input of five subjects, print its total and percentage also.
Ans: Marks Sheet

 #include<iostream>
 #include<conio.h>
 #include<stdio.h>
 using namespace std;
 int main()
 {
 int phy, eng, comp, chem, urdu;
 int obt_marks, per;

 cout << "\n \t Enter Chemistry Marks = ";
 cin >> chem;
 cout << "\n \t Enter Physics Marks = ";
 cin >> phy;
 cout << "\n \t Enter Computer Marks = ";
 cin >> comp;
 cout << "\n \t Enter English Marks = ";
 cin >> eng;
 cout << "\n \t Enter Urdu Marks = ";
 cin >> urdu;
 obt_marks = chem + phy + comp + eng + urdu;
 per = (obt_marks*100) /500;
 cout << "\n \t The total marks are = " << obt_marks;
 cout << "\n \t The percentage is = " << per <<"%\n";
 return 0;
 }


Q.4: Write a code to calculate mathematical expression of a2 + 2ab +b2.
Ans: Mathematical Expression:

 #include<iostream>
 #include<conio.h>
 #include<stdio.h>
 using namespace std;
 int main()
 {
 float sol;
 int a, b;
 cout << "\n\t Program to calculate expression a2 + 2ab +b2";
 cout << "\n\t Enter the value of a. \t";
 cin >> a;
 cout << "\n\t Enter the value of b. \t";
 cin >> b;
 sol = (a*a) + 2*(a*b) + (b*b);
 cout << "\n\t The solution of expression a2 + 2ab +b2 for given a and b is. \t" << sol;
 return 0;
 }


Q.5: list out errors from the C++ program and remove those errors, write the output.
#include<iostream.h>
using namespace std
int main (void);
{
int x;
cout << "\n Enter the value of x........";
cin >> x
cout << "\n The square of x......." << a*a;
return 0;
}

Ans: List of errors:
  1. #include<iostream.h>
  2. using namespace std
  3. int main (void);
  4. {
  5. int x;
  6. cout << "\n Enter the value of x........";
  7. cin >> x
  8. cout << "\n The square of x......." << a*a;
  9. return 0;
  10. }


Line No. Error
1. iostream.h
2. Terminator (;) missing after std
3. Terminator (;) present after main function
7. Terminator (;) missing after cin function
8. Wrong variable used in square expression (a)

Correct Program:

 #include<iostream>
 using namespace std;
 int main (void)
 {
 int x;
 cout << "\n Enter the value of x .....";
 cin >> x;
 cout << "\n The square of x ....." << x*x;
 return 0;
 }

OUTPUT:
Enter the value of x ..... 5
The square of x ..... 25





Wednesday, 14 September 2022

UNIT 03: INPUT/OUTPUT HANDLING IN C++ - Question Answers - Computer Science For Class X

GO TO INDEX

Computer Science For Class X
Unit 03: Input / Output Handling In C++
Question Answers



Q.1: Describe basic structure of C++ program.
Ans: BASIC STRUCTURE OF C++ PROGRAM:
C++ is mainly divided in three parts:
  1. Preprocessor directive
  2. Main Function Header
  3. Body of program / Function

Basic Structure of C++ program is given below:


Q.2: Describe elements of basic structure.
Ans: EXPLANATION OF BASIC STRUCTURE:
1. #include<iostream>:
The statement starts with # symbol is called preprocessor directives. This statement tells preprocessor to include contents of "iostrearm" header file in the program before compilation. This file is required for input-output statements.

2. using namespace std;:
This statement is used to instruct compiler to use standard namespace. A namespace is a declarative location that provides a space to the Namespace std contains all the classes, objects and functions of the standard C++ library.

3. int main():
This statement is a function and used for the execution of C++ program. Int means it returns integer type value.

4. {:
This symbol represents the start of main function.

5. statements;:
Statements are instructions that performs particular task. Statement terminator (;) is used to end every statement in C++ program.
6. return0;:
This statement is used to return the value to the operating system. By default, main function returns integer value 0.

7. }:
This symbol represents the end of main function.

Q.3: Define comments in C++. Also define its types.
Ans: COMMENTS IN C++:
Comments are special remarks that helps to understand different parts of the code in C++ program. Comments are ignored by the compiler. In C++, there are two types of comments statement.

  1. Single line Comment
  2. Multi line Comment

Q.4: Define single line comment in C++.
Ans: SINGLE LINE COMMENT:
This type is used to write single line comment. Double slash (//) symbol is used at the start of each single line comment.

Example:

  // This is my first C++ program
 // This program displays a statement on screen
 #include<iostream>:
 int main( )
 {
 puts("My First C++ Program");
 return 0;
 }



Q.5: Define multi line comment in C++.
Ans: MULTI LINE COMMENT:
This type is used to write multi line comment. Symbols (/*and*) are used at the start and end of comment statements.

Example:

 /*This is my first C++ program
 This program display a statement on screen.*/
 #include<iostream>
 int main()
 {
 puts("My First C++ Program");
 return0:
 }



Q.6: What do you mean input / output statement in C++.
Ans: INPUT / OUTPUT STATEMENTS IN C++:
Input and output statements are used to perform input & output operations in C++. These input / output statements are stored in header files like <iostream>. At the beginning of every program these header files must be included.

Q.7: Define output functions or statements in C++. Define cout statement and puts statement with syntax and example in C++.
Ans: OUTPUT FUNCTION / STATEMENT IN C++:
cout STATEMENT:
cout stands for "Character Output". In C++, cout sends formatted output to standard outputdevices, such as the screen. cout bject is used along with the insertion operator (<<) for displaying output.

Syntax

   cout << variable; or cout << exp. / string;

Example:

 cout << This is C++ Programming';
 cout << num1;



puts() STATEMENT:
This function is used to print the string output. After printing the screen new line is automatically inserted.

Syntax:

 puts("string constant");


Example:

 puts("This is C++ Programming");


Q.8: Define input functions or statements in C++.
Ans: INPUT FUNCTIONS / STATEMENT IN C++:
Following are the input functions / statement in C++:
  • cin STATEMENT
  • getchar() STATEMENT
  • getch() STATEMENT
  • getche() STATEMENT
  • gets() STATEMENT

Q.9: Define cin statement with syntax and example in C++.
Ans: cin STATEMENT:
cin stands for "Character Input". In C++, cin reads formatted data as input from keyboard. cin object is used along with the extraction operator (>>) to accept data from standard input device.

Syntax:

 cin >>variable;


Example:

 #include<iostream>
 using namespaces std;
 int main()
 {
 int b;
 cin >> // cin takes input in "b" variable
 return0;
 }



Q.10: Define getchar() statement with example in C++.
Ans: getchar() STATEMENT:
The getchar() function reads the available character from the keyboard. This function reads only single character at a time. When the user presses the key. getchar() requires Enter key to be pressed. This function is defined in <stdio.h> header file.

Example:

 #include<iostream>
 using namespace std;
 int main()
 {
 char b;
 cout << "\n Enter a character,";
 b = getchar();
 cout << "\n Input character is" << b;
 return 0;
 }



Q.11: Define getch() statement with example in C++.
Ans: getc() STATEMENT:
The getch() function reads the character from the keyboard. This function reads only single character and not printed on the screen. This function takes input and does not requires Enter key to pressed. This function is defined in <conio.h> header file.

Example:

 #include<iostream>
 #include<conio.h>
 using namespace std;
 int main()
 {
 char ch;
 cout << "\n Enter a character";
 ch = getch();
 cout << "\n Input character is "<<ch;
 return0;
 }



Q.12: Define getche() statement with example in C++.
Ans: getche() STATEMENT:
The getche() function reads the character from the keyboard and echoes on the screen. It reads only single character and displays on the screen. This function takes input and does not require Enter key to be pressed. This function is defined in <conio.h> header flle.

Example:

 #include<iostream>
 #include<conio.h>
 using namespace std;
 int main()
 {
 char ch;
 cout << "\n Enter a character:";
 ch = getche();
 cout << "\n Input character is" << ch;
 return0;
 }



Q.13: Define gets() statement with syntax and example in C++.
Ans: gets() STATEMENT:
This function is used to reads characters or the string input and stored them until a newline character found. This function is defined in <conio.h> header file.

Syntax:

 gets("variable");


Example:

 #include<iostream>
 #include<conio.h>
 using namespace std;
 int main()
 {
 char name {25};
 cout << "\n Enter your name:";
 gets(name);
 cout << "\n Your Name is"<< name;
 return0;
 }



Q.14: What is statement terminator?
Ans: STATEMENT TERMINATOR (;):
In C++, statement terminator used to end the statement. Statements are terminated with semicolon (;) symbol. Every statement in C++ must be terminated otherwise an error message will occur.

Q.15: Write down in detail about escape sequences in C++.
Ans: ESCAPE SEQUENCES:
Escape sequences are used to control the cursor moves on screen by using special codes. An escape sequence is a special non-printing characters consists of the escape character (the backslash "\") and a second (code) character. The list of the escape sequences is given below:

Escape Sequence Explanation with Example
\n Newline. Position the cursor at the beginning of the next line.
Example: cout << "\n";
\t Horizontal tab. It move the cursor to the next tab stop.
Example: cout << "\t";
\\ Backslash. Insert a backslash character in a string.
Example: cout << "\\";
\a Alert. Produces a beep sound or visible alert.
Example: cout << "\a";
\b Backspace. It moves the cursor backspace.
Example: cout << "\b";
\r Carriage Return. Moves the cursor to the beginning of the current line. Example: cout << "\r";
\' Single Quotation. It is used to print apostrophe sign (').
Example: cout << "\'";
\" Double Quotation. It is used to print quotation mark (").
Example: cout << "\" ";

Q.16: What are operators? Write down the name of operators used in C++.
Ans: OPERATORS IN C++:
Operators are the symbols which tell the computer to execute certain mathematical or logical operations. A mathematical or logical expression is generally formed with the help of an operator. C++ Programming offers a number of operators which are classified into the following categories.

  1. Arithmetic Operators
  2. Increment Operators
  3. Decrement Operators
  4. Relational Operators
  5. Logical/Boolean Operators
  6. Assignment Operators
  7. Arithmetic Assignment Operators

Q.17: What are arithmetic operators?
Ans: ARITHMETIC OPERATORS:
Arithmetic operators are used to perform mathematical operations. All operators used integer & floating.point data type except remainder or modulas operator.

Operator Operation Example
+ Addition, It is used to perform addition.a+b
- Subtraction: It is used to perform subtraction.a-b
* Multiplication: It is used to perform multiplication.a*b
/ Division, It is used to perform division.a/b
% Remainder Or Modulas: Find remainder after integer division.a%b

Q.18: Define all arithmetic operators with examples.
Ans: SIMPLE CALCULATOR PROGRAMMING IN C++ USING ARITHMETIC OPERATORS:


Q.19: Define increment operators with example in C++.
Ans: C++ provides the unary increment operator. It is used to be incremented a variable by 1. Increment operator represented by ++ (double plus sign). The increment operators are used in two ways (Postfix & Prefix) summarized below:

Operator Explanation
++a
(Prefix)
 Increment a by 1. then use the new value of a in the expression in which a resides. i.e. x = ++a;

a++
(Postfix)
 Use the current value of a in the expression in which a resides, then increment a by 1.




Q.20: Define decrement operator in C++.
Ans: DECREMENT OPERATORS:
C++ also provides the unary decrement operator. It is used to be decremented a variable by 1. The decrement operator represented by -- (Double minus sign). are used in The decrement operators are used in two ways (Postfix & Prefix) summarize below:

Operators Explanation
--a
(Prefix)
 Decrement a by 1, then Use the new value of a in the expression in which a resides.

a--
(Postfix)
 Use the current value of a in the expression in which a resides, then decrement a by 1.


Q.21: Define Relational operators with example in C++.
Ans: RELATIONAL OPERATORS:
Relational operators are used when we have to make comparisons. It is used to test the relation between two values. The result of comparison is True (1) or false (0). C++ Programming offers following relational operators:

Operators Operations Example
< It checks the value on left is less than value on right. a<b
> It checks the value on left is greater than value on right. a>b
<= It checks the value on left is less than or equal to value on right.a<=b
>= It checks the value on left is greater than or equal to tbe value on right.a>=b
== It checks the equality of two values.a==b
!= It checks the value on left is not equal to value on right.a!=b

PROGRAM USING RELATIONAL OPERATOR IN C++

 #include <iostream>
 using namespace std;
 int main()
 {
 int x=20, y=10;
 if(x>y)
 cout <<"X is greater than Y;
 else
 return 0;
 }

 OUTPUT
 X is greater than Y


Q.22: Define logical operators with example in C++.
Ans: LOGICAL OPERATORS:
Logical operators are used when more than one conditions are to be tested and based on that result, decisions have to be made. C++ programming offers three logical operators. They are:
Operators Operations Explanation
&& Logical AND. The condition will be true if both expressions are true. 1 if a==b && c==d; else 0
|| Logical OR. The condition will be true if any of the expressions ere true. 1 if a==b || c>d; else 0
! Logic NOT. The condition, will be inverted, False becomes true & true becomes false. 1 if !(a==0); else 0

PROGRAM USING LOGICAL OPERATOR IN C++:

 #include<iostream>
 #include<conio.h>
 using namespace std;

 int main()

 {
 int num1 = 30, num2 = 40;
 cout<< "Logical Operators Example \n";
 if (nun1<=40 && num2>=40)
 {
 cout<< "Numl is less than and Num2 is greater than or equal to 40 \n";
 }
 if (nun1>=40 || num2>=40)
 {
 cout<< "Numl or Num2 is greater than or equal to 40 \n";
 }
 getch();
 return 0;
 }

 OUTPUT
 Logical Operators Example
 Numl is less than and Num2 is greater than or equal to 40
 Numl or Num2 is greater than or equal to 40


Q.23: write down the difference between relational end logical operators.
Ans: DIFFERENTIATE BETWEEN RELATIONAL OPERATOR AND LOGICAL OPERATOR:
RELATIONAL OPERATOR:
  • Relational operators compare any values in the form of expressions.
  • Relational operators are binary operators because they require two operands to operate.
  • Relational operators return results either 1 (TRUE) or 0 (FALSE).

LOGICAL OPERATOR :
  • Logical operators perform logical operations on boolean values 1 (TRUE) and 0 (FALSE).
  • Logioal operator is usually used te compare one or more relational expressions.
  • Logical operator also return output as 1 (TRUE) and 0 (FALSE).

Q.24: Define assignment operator.
Ans: ASSIGNMENT OPERATOR:
Assignment operator (=) are used to assign result of an expression or a value to a variable. The associativity of assignment operators is right to left means value or expressi at the right is assigned to the left side variable.

Q.25: Define arithmetic assignment operators with example.
Ans: ARITHMETIC ASSIGNMENT OPERATOR:
Arithmetic assignment operator is a combination of arithmetic and assignment operators. This operator first performs an arithmetic operation on the current value of the variable on left to the value on the right and then assigns the result to the variable on the left.

OPERATOR DESCRIPTION
 +=(Addition-Assignment) Adds the right operand to the left and assigns the result to the left operand.
 -=(Subtraction-Assignment) Subtracts the right operand to the left and assigns the result to the left. operand.
 *=(Multipication-Assignment) Multiplies the right operand to the left and assigns the result to the left operand.
 /=(Division-Assignment) Divides the right operand to the left and assign the result to the left operand.

PROGRAM USING ASSIGNMENT & ARITHMETIC OPERATORS IN C++:

 #include<iostream>
 #include<conio.h>
 using namespace std;

 int main()

 {
 int a = 10;
 cout<< "Value of a using assignment operator is "<<a<<" \n";
 a+= 10;
 cout<< "Value of a using addition assignment operator is "<<a<<" \n";
 a-= 10;
 cout<< "Value of a using subtraction assignment operator is "<<a<<" \n";
 a*= 10;
 cout<< "Value of a using multiplication assignment operator is "<<a<<" \n";
 a/= 10;
 cout<< "Value of a using division assignment operator is "<<a<<" \n";
 return 0;
 }

 OUTPUT
 Value of a using assignment operator is 10
 Value of a using addition assignment operator is 20
 Value of a using subtraction assignment operator is 10
 Value of a using multiplication assignment operator 100

Value of a using division assignment operator is 10






Monday, 12 September 2022

UNIT 02: BASICS OF PROGRAMMING IN C++ - Lab Activity - Computer Science For Class X

GO TO INDEX

Computer Science For Class X
Unit 02: Basics Of Programming In C++
Lab Activity


1. In groups, students learn to download, install and configure Dev C++.

INTRODUCTION TO DEV-C++:

Dev-C++ is a fully featured graphical IDE (Integrated Development Environment) for programming in C / C++. DEV-C++ is developed by Bloodshed software. It was originally developed by Colin Laplace and first released in 1998. It is written in Delphi. With Dev C++ programmer can write Windows or console-based C/C++ programs easily.

INSTALLING AND CONFIGURING DEV-C++ IDE:
Dev-C++ is free available for download on Internet. After downloading the package begin the installation process. Following are the steps for installing Dec-C++ IDE.

STEP 1:
  • Select "English" as the language to be used for installation process.


STEP 2:
  • Press " I Agree" button to agree the license agreement.


STEP 3:
  • Select "Full" from the drop-down menu "for type of Install". This will select all the necessary components required to run Dev-C++ and compile C++ source code.
  • Click on "Next" to proceed.


STEP 4:
  • Select the installation folder (directory) where all the necessary Dev-C++ files and libraries will be installed. Usually, the default specified path is used for installation but we can change it if desired.
  • Click on "Install" to start installation.




STEP 5:
  • After completing process, it will show a "Finish" dialog box.
  • Make sure the "Run Dev-C++ 5..." is checked.
  • Click 'Finish' button. This will automatically start Dev-C++ after installation completes.


CONFIGURING DEV-C++:
  • Dev-C++ will require some configuration when it runs first time.
  • Set "English (Original)". as default interface language in the Dev-C++ first time configuration dialogue.
  • Click "Next" to continue.
  • On the "Theme" selection dialog box leave the default setting and click on "Next" to continue.
  • Click "OK' to close first time configuration dialogue.



LINKER SETTING FOR DEBUGGING:
Linker setting for bugging is required first time to obtain information about problems in source code. The following steps are used to enable this configuration.
  • Click on ToolsCompiler Options.
  • Open the Setting tab from the Compiler Options dialogue box.
  • Under Setting tab, open Linker tab.
  • In Linker tab change the Generate Debugging Information (-g3) options to Yes.
  • Click on OK to save setting.



DEVELOPING PROGRAM IN DEV-C++:
Development of C++ program requires writing source and saving those files for compilation. The steps to create a new project in Dev-C++ are:
  • Click on File ⇨ click NewProject.
  • In New Project dialog, Select Empty Project.
  • From language option, select C++ Project. Also enter Name for project.
  • Click on OK.
  • Dev C++ will ask path to save the new project, enter path and save project.



ADD NEW FILES TO PROJECT IN DEV-C++:
The step to create a new file are:
  • Click on Project ⇨ New File. Alternatively we can also right-click on the Project Name in the Project Explorer and click on the New File.
  • Click on Yes on the confirm dialog box to add a file.
  • To save newly added file, click on File ⇨ Save
  • Enter the path and provide its name.
  • Click on Save to Store the file.


COMPILE AND EXECUTE PROJECT IN DEV-C++:
The steps to compile and execute project are:
  • Project needs to compile before execution. To compile, click on Execute ⇨ Compile or press F9 key. Compiler Log tab shows the compilation status. Compiler tab will show if there are any syntax errors.
  • After successfully compiling the project, run it by clicking on Execute ⇨ Run or by pressing F10 key.
  • A console window will open and show the output of the program.

2. Teacher demonstrate the use of IDE and its feature as given in this unit. Also explain the use of variables and constants.

INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):

  • An integrated development environment (IDE) is software for building applications or programs that combines common developer tools into a single graphical user interface (GUI).
  • IDE facilitates the development of applications designed to encompass all programming tasks in one application, one of the main benefits of an IDE is that they offer a central interface with all the tools, a developer needs.
  • For instance, Dev-C++, is used for making programs in C++ language.
  • However, there are many multiple language IDEs. Such as Eclipse (C, C++, Python, Perl, PHP, Java, Ruby and more) and Visual Studio Code (Java, JavaScript, PHP, Python, Ruby, C, C++ and more).

Explanation:
  • Integrated Development Environment (IDE):
  • IDEs provide interfaces for users to write code, organize text groups, and automate programming tools.
  • Instead of a simple plain-text editor, IDEs combine the functionality of multiple programming processes into one.
  • Most IDES come with built-in translators.
  • If any bugs or errors are found, users are shown which parts of code have problems.
  • Some IDEs are dedicated to a specific programming language or set of languages, having a set of tools and features which are helpful in writing codes for that language.

Key Benefits of Integrated Development Environments:
Serves as a single environment for most of a developer's needs such as compilation, linking, loading, and debugging tools.
Code completion capabilities improve programming workflow.
Automatically checks for errors to ensure top quality code.
Refactoring capabilities allow developers to make comprehensive and mistake-free renaming changes.

COMPONENTS OF INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):
IDEs increase programmer productivity by combining common activities of writing software into a single application: editing source code, building executable, and debugging.

EDITING SOURCE CODE:
Writing and editing source codes is a major part of programming. A text editor is used for writing and editing source codes with feature providing language specific autocompletion, and checking for bugs as code is being written.

SYNTAX HIGHLIGHTING:
Syntax highlighting is a feature of IDEs that provides visual cues, keywords, and other words that have special meaning in languages (like class in C++) are highlighted with different colors. This feature makes code easier to read by visually clarifying different elements of language syntax or understand.

CODE COMPLETION:
It is a feature of IDE that completely knows the language syntax that speeds up process of coding by reducing typos and other mistakes. Autocompletion popups while typing, querying parameters of functions, query hints related to syntax errors.

COMPILER:
Compiler is a component of IDEs that translate source code (programming language) into machine code, such as binary codes. IDEs provide automated build process for languages, so the act of compiling and executing code is done automatically. Thus this feature can help automate developer tasks that are more common to save time.

LINKER:
Linker opens the compiled program file and connects or links referenced library files with compiled code as needed. Unless all linker items are resolved, the process stops and returns the user to the source code file within the text editor with an error message. If no problem encountered, it saved the linked objects into an executable file.

LOADER:
The IDE directs the operating system's program called the loader to loads executable files into the computer's memory and directs the Central Processing System (CPU) to start running the program as directed by the IDE.

DEBUGGING:
The process of removing errors from a program is known as debugging. When a program does not run correctly, IDEs provide debugging tools that allow programmer to examine different variables and inspect their codes step by step. IDE also provide hints while coding to prevent errors before compilation.
Thus, debugging is a multi-step process that involves identifying a problem, isolating the source of the problem. The final step of debugging is to test the correction or work around and make sure it works. Programmers and engineers can usually test the various segment of codes and identify errors before the application is released.

CONSTANT:

A constant is an identifier whose value remains unchanged through out the program.
OR
Constants and Variables A constant is a data item whose value cannot change during the program's execution. Thus, as its name implies - the value is constant.
OR
A constant is a value that cannot be altered by the program during execution, i.e., the value is constant. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably.


TYPES OF CONSTANT:
Constants are used in two ways. They are:
  1. Literal Constants
  2. Defined Constants

LITERAL CONSTANT:
Literal constants are data used for representing fixed values. 'They can be used directly in the codes.
Example:
  • 1, 2, 5, "c", "good", "Hello World", false, null etc.

DEFINED OR SYMBOLIC CONSTANT:
In C++, we can create symbolic constant or named which are constant and represented by names. Symbolic constant value remains unchanged but used as a variable. A symbolic constant can be created using the #define preprocessor directive or const keyword.
Many programming languages use ALL CAPS to define name constant.
Example:
  • const int LIGHT_SPEED = 299792458;
  • #define LIGHT SPEED 29972458

VARIABLE:

A variable is nothing but a name given to a storage area that our programs can manipulate. In simple words, A variable is the memory location that can hold a value. Its value can change during program execution. Each variable C++ has a specified data type, which determine the size and layout of the variable's memory.
Example:
A class room with capacity of 20 students is a fixed placed or constant but the subject taught, the teacher and students may vary with each class and subject and are variables.

Variables do not require to be assigned initial value. Variables once defined may be assigned a value within the instructions of the program. Variables can be assigned different values at different time during execution.
Example:
x = 5:
x = 37;

RULES FOR NAMING VARIABLE:
The general rules for constructing names for variables (unique identifiers) are:
  • A variable name contains alphabets (letters), number, and underscores.
  • A variable name must start with a letter or an underscore (_).
  • Variable names are case sensitive. (myVar and myvar or Sum end sum are different variables)
  • Variable names cannot contain whitespaces or special characters like !, #, % etc.
  • Reserved words (Like C++ keyword, such as int cannot be used as names.
  • A variable name cannot be longer than 32 characters in C++ by default.

DECLARATION (CREATING) VARIABLE:
A variable declaration tells the compiler where and how much storage to create a variable. in other words, variable declaration is a process in which we create storage space for variable in memory.
A variable declaration consists of data type and name of the variable written as follow:
Syntax:
  • data_type variable_name,
  • int sum
Where type is one of C++ data type (such as int), and variable_ name is the name of the variable (such as x or myName)

INITIALIZATION:
Assign initial value to a variable is known as variable initialization. It can be initialized during declaration or separately. The initialization consists of an equal sign followed by a constant expression. The equal sign is used to assign value written as follows:
Syntax:
  • data_type variable_name value;
  • int sum = 3;

STRINGS IN C ++:
  • Variables that can store non numerical (alphanumeric) value that consist of multiple characters (longer than one single characters) are called strings.
  • The C++ language library provides supports for strings through the standard string class.  In C++, strings are used by one-dimensional array of characters, which is terminated by a null character \0.
  • This is not a fundamental type, but it behaves in a similar way as a fundamental types do in its most basic usage.
  • String can be declared without an initial value and can be assigned values during executions.


Tuesday, 6 September 2022

UNIT 02. BASICS OF PROGRAMMING IN C++ - Question And Answers - Computer Science For Class X

GO TO INDEX

Computer Science For Class X
Unit 02: Basics Of Programming In C++
Question And Answers


Q.1: Define Computer Program?
Ans: COMPUTER PROGRAM:
A computer program is a set of instructions that performs a specific task when executed by a computer. A computer requires programs to function and typically executes the program's instructions in a central processing unit. A computer program is usually written by a computer programmer in a programming language.

Q.2: Define syntax OR What is syntax in programming?
Ans: SYNTAX IN PROGRAMMING LANGUAGE:
Syntax refers to the rules that define the structure of a language. Syntax in computer programming means a set of keywords and characters that a computer can understand, interpret and perform task associated with them. The syntax of a language must be followed, and if it is not followed, the code will not be understood by a compiler or interpreter. Different programming languages have different types of syntax.

Q.3: Describe classification of programming language.
Ans: CLASSIFICATION OF PROGRAMMING LANGUAGE:
Based on the accessibility of hardware, programming languages can be classified into the following categories:
  1. Low-level language
  2. Middle-level language
  3. High level language

Q.4: Define low level language.
Ans: LOW-LEVEL LANGUAGE:
Low-level programming languages are those languages that are directly communicated with computer hardware. The two languages come under this category are Machine language and Assembly language.

Q.5: Define machine language.
Ans: MACHINE-LEVEL LANGUAGE:
Machine language is a collection of binary digits or bits that the computer reads and interprets. This language is the only language understood by computers while machine language is almost impossible for humans to use because they consist entirely of numbers (0s & 1s). Machine code doesn't require translator because machine code is directly executed by computer. It is also called first generation language.

Q.6: Define assembly language.
Ans: ASSEMBLY LANGUAGE:
A program written in assembly language consists of a series of instructions called mnemonics that correspond to a stream of executable instructions. Assembly language code is translated by a translator called assembler. Assembly language uses keywords and symbols much like English and are easy to read, write and maintain as compared to machine language. It is also called second generation programming language.


Q.7: Define middle level language.
Ans: MIDDLE-LEVEL LANGUAGE:
The middle-level language lies in between the low level and high-level language. Middle-level language actually binds the gap between a machine level language and high-level languages, these languages are now become obsolete and are not in used.

Q.8: What do you know about high level language?
Ans: HIGH-LEVEL LANGUAGE:
High-level languages are relatively new and drastically revolutionized the programming world. It allows us to write computer code using instructions resembling everyday spoken language, usually English (for example: print, if, while). Programs written in a high-level language need to be translated by a translator (compiler or interpreter) into machine language before execution.

Q.9: write down the advantages or benefits of high-level language.
Ans: ADVANTAGES OF HIGH-LEVEL LANGUAGE:
  • High level language is much closer to human language so it is more suitable to write code in high level language.
  • It is more or less independent or portable of the particular type of computer used.
  • It is easier to read, write and maintain.

Q.10: Write down the differences between low-level and high-level languages.
Ans: DIFFERENCES BETWEEN LOW-LEVEL LANGUAGE AND HIGH-LEVEL LANGUAGE:
Low Level Language High Level Language
 In low level language machine codes (0 and 1) are used as an instruction to the computer. In high level language English like words are used as an instruction to the computer.
 The execution of programs is quite fast. The execution of programs is not very fast.
 Instructions are directly understood by the CPU.  Instruction are not directly understood by the CPU.
 No need to translate program. In case of assembly language assembler is required. Translation of program is required.
 The programs written in low level languages are machine dependent and are difficult to modify. The programs written in high level languages are machine independent and are easy to modify.
 The examples of low-level languages are:
  1. Machine language
  2. Assembly language
 The examples of high-level languages are: BASIC, FORTRAN, COBOL, PASCAL, C languages etc.


Q.11: Define translators or language translators.
Ans: TRANSLATORS OR LANGUAGE TRANSLATORS:
Language translator is a computer program that converts high level language program into low level program (1s & 0s), or machine language. It transforms the source code into the object code (machine code) which understands directly by the computer processor. Translators also detect and report errors in the process of translation. There are three types of language translators.
  • Interpreter
  • Compiler
  • Assembler


Q.12: What is compiler?
Ans: COMPILER:
Compiler is a program bat translates the high, level language program into machine language. Complier translates the whole Program at a time at once before it executed and makes a separate object file for the translated program. Translated program can he used multiple time without the need of retranslation of source code. Each high-level language has its own compiler.


Q.13: Define Interpreter?
Ans: INTERPRETER:
Interpreter is a language translator program, which converts high level program into machine language. It translates one instruction at a time. Interpreter does non make any object file and it translates the program every time when executed. An interpreter is faster than a compiler as It immediately executes the codes.


Q.14: Define Assembler.
Ans: ASSEMBLER:
An assembler is a translator that converts assembly language program iNto machine language. An assembler translates assembly language code directly Into machine code that can he understood by the CPU.


Q.15: Define source program or source code?
Ans: SOURCE PROGRAM /SOURCE CODE:
A Program or A program written by a programmer in any language other than machine language is called a source program or source code.

Q.16: Define object.
Ans: OBJECT PROGRAM /OBJECT CODE:
Object program is a program or code that is converted into machine language. (OR) The output from a language translator, which consists of machine language instructions, is called the object program.

Q.17: Write down the differences between interpreter and compiler?
Ans: DIFFERENCES BETWEEN INTERPRETER AND COMPILER:
Compiler Interpreter
 Interpreter translates high level language program into machine language line by line. Compiler translates high level language program into machine language as a whole.
 The interpreter translates the program every time when executed. The compiler translates the program once at a time.
 The interpreter does not make any object file. The compiler makes a separate object file for the translated program.
 Errors are displayed for every instruction interpreted if any. Errors are displayed after entire program is checked.
 Examples: BASIC, LISP etc.  Examples: C Compiler, C++ compiler etc.

Q.18: Define errors or programming errors.
Ans: ERROR:
An error describes any issue that arises unexpectedly that causes a program to not function properly. In general, there are three types of errors that occur in a computer program. Syntax Error, logical Error and Runtime Error.

Q.19: What Is syntax error?
Ans: SYNTAX ERROR:
A syntax error is an error in the syntax due to violation of rules of whatever language program is being written. These are sometimes caused by simple typing mistakes.

Q.20: What is logic error?
Ans: LOGIC ERROR:
In computer programming, a logic error is a bug or error in planning the program's logic. They do not cause the program to crash or simply not work at all, they cause it to 'misbehave' in some way, rendering wrong output of some kind. The computer does not tell us, what is wrong.

Q.21: What is runtime error?
Ans: RUNTIME ERROR:
A runtime error is a program error that occurs when a program is run on the computer and the result are not achieved due to some misinterpretation of a particular instruction. The code doesn't have any syntax or logic error but when it executes it cannot perform specific task.

Q.22: What is Programming Environment of C++?
Ans: PROGRAMMING ENVIRONMENT OF C++:
Programming environment is an environment which supports execution of programming language smoothly and efficiently on a local computer to compile and run programs.

Q.23: Define IDE or Integrated development environment?
Ans: INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):
An integrated development environment (IDE) is software for building applications or programs that combines common developer tools into a single graphical user interface (GUI). IDE facilitates the development of applications designed to encompass all programming tasks in one application, one of the main benefits of an IDE is that they offer a central interface with all the tools, a developer needs. Dev-C++, is used for writing programs in C++ language, however there are many multiple language IDEs.

Q.24: Write down the benefits or advantages of integrated development environment.
Ans: BENEFITS / ADVANTAGES OF INTEGRATED DEVELOPMENT ENVIRONMENT:
IDE combines all tools that need for development. Programmers don't need to switch between different tools to design a layout, write the code, debug, build,etc.
Many IDEs incorporate basic spelling checkers, so automatically check for errors to improve code.
Libraries provide for functions in IDEs that are not included in the core part of the programming language.

Q.25: What are the components of Integrated Development Environment?
Ans: COMPONENTS OF INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):
IDEs combining common tools that are necessary for a programmer to develop program, these are:
EDITING SOURCE CODE:
Writing and editing source codes is a major part of programming. A text editor is used for writing and editing source codes with feature providing language specific autocompletion, and checking for bugs as code is being written.

SYNTAX HIGHLIGHTING:
Syntax highlighting is a feature of IDEs that provides visual cues, keywords, and other words that have special meaning in languages are highlighted. This feature makes code easier to read or understand.

CODE COMPLETION:
It is a feature of IDE that completely knows the language syntax that speeds up process of coding by reducing typos and other mistakes. Autocompletion popups while typing, querying parameters of functions, query hints related to syntax errors.

COMPILER:
Compiler is a component of IDEs that translate source code into machine code. IDEs provide automated build process. This feature can help automate developer tasks that are more common to save time.

LINKER:
Linker connects or links referenced library files with compiled code. It saved the linked objects into an executable file.

LOADER:
This is the operating system's program that loads executable files into memory and directs the CPU to start running the program as directed by the IDE.

DEBUGGING:
The process of removing errors from a program is known as debugging. Debugging is a multistep process that involves identifying a problem, isolating the source of the problem. The final step of debugging is to test the correction or workaround and make sure it works.

Q.26: Define Linker, Loader and Debugging?
Ans: LINKER:
Linker connects or links referenced library files with compiled code. It saved the linked objects into an executable file.

LOADER:
This is the operating system's program that loads executable files into memory and directs the CPU to start running the program as directed by the IDE.

DEBUGGING:
The process of removing errors from a program is known as debugging. Debugging is a multistep process that involves identifying a problem, isolating the source of the problem. The final step of debugging is to test the correction or workaround and make sure it works.

Q.27: What do you know about Dev C++?
Ans: INTRODUCTION TO DEV-C++:
Dev-C++ is a fully featured graphical IDE (Integrated Development Environment) for programming in C / C++. DEV-C++ is developed by Bloodshed software. It was originally developed by Colin Laplace and first released in 1998. It is written in Delphi. With Dev C++ programmer can write Windows or console-based C/C++ programs easily.

Q.28: Write down the installation procedure of Dev C++:
Ans: INSTALLING AND CONFIGURING DEV-C++ IDE:
Dev-C++ is free available for download on Internet. After downloading the package begin the installation process. Following are the steps for installing Dec-C++ IDE.

STEP 1:
  • Select "English" as the language to be used for installation process.


STEP 2:
  • Press " I Agree" button to agree the license agreement.


STEP 3:
  • Select "Full" from the drop-down menu "for type of Install". This will select all the necessary components required to run Dev-C++ and compile C++ source code.
  • Click on "Next" to proceed.


STEP 4:
  • Select the installation folder (directory) where all the necessary Dev-C++ files and libraries will be installed. Usually, the default specified path is used for installation but we can change it if desired.
  • Click on "Install" to start installation.




STEP 5:
  • After completing process, it will show a "Finish" dialog box.
  • Make sure the "Run Dev-C++ 5..." is checked.
  • Click 'Finish' button. This will automatically start Dev-C++ after installation completes.


CONFIGURING DEV-C++:
  • Dev-C++ will require some configuration when it runs first time.
  • Set "English (Original)". as default interface language in the Dev-C++ first time configuration dialogue.
  • Click "Next" to continue.
  • On the "Theme" selection dialog box leave the default setting and click on "Next" to continue.
  • Click "OK' to close first time configuration dialogue.



LINKER SETTING FOR DEBUGGING:
Linker setting for bugging is required first time to obtain information about problems in source code. The following steps are used to enable this configuration.
  • Click on ToolsCompiler Options.
  • Open the Setting tab from the Compiler Options dialogue box.
  • Under Setting tab, open Linker tab.
  • In Linker tab change the Generate Debugging Information (-g3) options to Yes.
  • Click on OK to save setting.



Q.29: Write down the procedure to develop a program in Dev C++.
Ans: DEVELOPING PROGRAM IN DEV-C++:
Development of C++ program requires writing source and saving those files for compilation. The steps to create a new project in Dev-C++ are:
  • Click on File ⇨ click NewProject.
  • In New Project dialog, Select Empty Project.
  • From language option, select C++ Project. Also enter Name for project.
  • Click on OK.
  • Dev C++ will ask path to save the new project, enter path and save project.



ADD NEW FILES TO PROJECT IN DEV-C++:
The step to create a new file are:
  • Click on Project ⇨ New File. Alternatively we can also right-click on the Project Name in the Project Explorer and click on the New File.
  • Click on Yes on the confirm dialog box to add a file.
  • To save newly added file, click on File ⇨ Save
  • Enter the path and provide its name.
  • Click on Save to Store the file.


COMPILE AND EXECUTE PROJECT IN DEV-C++:
The steps to compile and execute project are:
  • Project needs to compile before execution. To compile, click on Execute ⇨ Compile or press F9 key. Compiler Log tab shows the compilation status. Compiler tab will show if there are any syntax errors.
  • After successfully compiling the project, run it by clicking on Execute ⇨ Run or by pressing F10 key.
  • A console window will open and show the output of the program.

Q.30: What do you know about C++ programming language?
Ans: C++ PROGRAMMING LANGUAGE:
C++ is a powerful general-purpose programming language. It was created lay Bjarne Stroustrup in 1979 at Bell Laboratories. It is used to develop operating systems, browsers, games, and other applications. C++ mainly supports programming like object oriented. C++ is a flexible language aims to make writing programs easier and more pleasant for the individual programming.

Q.31: Define reserved words in C++.
Ans: RESERVED WORDS IN C++:
Reserved words are keywords that have standard predefined meanings in C++ language. These keywords can only be used for their intended purpose; they cannot be used as programmer defined identifiers.
The following list the keywords or reserved words of the C++ language:

 and new
 asm nullptr
 auto Operator
 bool Or
 break private
 case protected
 catch public
 char register
 class reinterpret_cast
 const requires
 const_cast return
 continue short
 default  signed
 delete sizeof
 do static
 double static_cast
 dynamic_cast struct
 else switch
 enum template
 explicit this
 export Throw
 extern true
 false try
 float typedef
 for typeid
 friend typename
 goto union
 if unsigned
 inline Using
 int virtual
 long void
 mutable volatile
 namespace wchar_t
 not while

Q.32: Define data types in C++.
Ans: C++ DATA TYPES:
Data values passed in a program may be of different types. Each of these data types are represented differently within the computer's memory and have different memory requirements. These data types can be augmented by the use of data type qualifiers / modifiers.
The data types supported in C++ are described below:


Q.33: What ls constant? Also define its types.
Ans. CONSTANT:
A constant is an identifier whose value remains unchanged through out the program.
OR
Constants and Variables A constant is a data item whose value cannot change during the program's execution. Thus, as its name implies - the value is constant.
OR
A constant is a value that cannot be altered by the program during execution, i.e., the value is constant. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably.


TYPES OF CONSTANT:
Constants are used in two ways. They are:
  1. Literal Constants
  2. Defined Constants

Q.34: Define literal constant.
Ans: LITERAL CONSTANT:
Literal constants are data used for representing fixed values. 'They can be used directly in the codes.
Example:
  • 1, 2, 5, "c", "good" etc.

Q.35: Define symbolic constant.
Ans: DEFINED OR SYMBOLIC CONSTANT:
In C++, we can create symbolic constant whose value remains unchanged but used as a variable. A symbolic constant can be created using the #define preprocessor directive or const keyword.
Example:
  • const int LIGHT_SPEED = 299792458;
  • #define LIGHT SPEED 29972458

Q.36: Define variable and rules for naming variables.
Ans: VARIABLE:
A variable is nothing but a name given to a storage area that our programs can manipulate. Its value can change during program execution. Each variable C++ has a specified data type, which determine the size and layout of the variable's memory.

RULES FOR NAMING VARIABLE:
The general rules for constructing names for variables (unique identifiers) are:
  • A variable name contains alphabets (letters), number, and underscores.
  • A variable name must start with a letter or an underscore (_).
  • Variable names are case sensitive. (myVar and myvar or Sum end sum are different variables)
  • Variable names cannot contain whitespaces or special characters like !, #, % etc.
  • Reserved words (Like C++ keyword, such as int cannot be used as names.
  • A variable name cannot be longer than 32 characters in C++ by default.

Q.37: Define Declaring (Creating) and initializing Variables.
Ans: DECLARATION (CREATING) VARIABLE:
Variable declaration is a process in which we create storage space for variable in memory. A variable declaration consists of data type and name of the variable written as follow:
  • data_type variable_name,
  • int sum

INITIALIZATION:
Assign initial value to a variable is known as variable initialization. It can be initialized during declaration or separately. The equal sign is used to assign value written as follows:
  • data_type variable_name value;
  • int sum = 3;

Q.38: Define strings in C++.
Ans: STRINGS IN C ++:
Variables that can store alphanumeric value that consist of multiple characters are called strings. In C++, strings are used by one-dimensional array of characters, which is terminated by a null character \0.