Pageviews

Friday 6 September 2019

+1] 6 . Introduction To Programming - Solved Questions from text book

                        PLUS ONE COMPUTER APPLICATION

Chapter 6  Introduction To Programming
                           (+1. Computer Application Questions and  answers from text book)                                                                                         

1. What is dynamic initialisation of variables?

        A variable can also be initialised during the execution of the program and is known as dynamic initialisation. This is done by assigning an expression to a variable as shown in the following statements: 
float product = x * y;
 float interest= p*n*r/100.0;

   In the first statement, the variable product is initialised with the product of the values stored in x and y at runtime. In the second case, the expression p*n*r/100.0 is evaluated and the value returned by it will be stored in the variable interest at runtime.

 2. What is type promotion?

         Implicit type conversion is performed by C++ compiler internally. In expressions where different types of data are involved, C++ converts the lower sized operands to the data type of highest sized operand. Since the conversion is always from lower type to higher, it is also known as type promotion. Data types in the decreasing order of size are as follows: long double, double, float, unsigned long, long int, unsigned int, int and short int. The type of the result will also be the type of the highest sized operand. 

 3. What do you mean by type casting? What is type cast operator?

   Unlike implicit type conversion, sometimes the programmer may decide the data type of the result of evaluation. This is done by the programmer by specifying the data type within parentheses to the left of the operand. Since the programmer explicitly casts a data to the desired type, it is also known as explicit type conversion or type casting.
A cast is a special operator that forces one data type to be converted into another. As an operator, a cast is unary and has the same precedence as any other unary operator. The most general cast supported by most of the C++ compilers is as follows − (type) expression.

4. What type of variable declaration is used in the following program code ?

 { int area, length = 10, width = 12, perimeter; 

 area = length * width;

 perimeter = 2*(length + width);

 }

 2. Modify the above program code to have dynamic initialisation for variables area and perimeter.

    {
       int area =length*width;

       int perimeter =2*(length*width);

}

 3. Explain type modifiers in C+ +.

          In C++ too, we need data types that can accommodate data of slightly bigger/smaller size. C++ provides data type modifiers which help us to alter the size, range or precision. Modifiers precede the data type name in the variable declaration. It alters the range of values  permitted to a data type by altering the memory size and/or sign of values. Important modifiers are signed, unsigned, long and short. The exact sizes of these data types depend on the compiler and computer you are using. 

It is guaranteed that:

 • a double is at least as big as a float. 

• a long double is at least as big as a double.
 4. Why are so many data types provided in C++? 

5. What is the role of the keyword 'const'? 

         The keyword const is used to create such symbolic constants whose value can never be changed during execution.

6. Explain pre increment and post increment operations. 

               Increment operator (++) This operator is used for incrementing the content of an integer variable by one. This can be written in two ways ++x (pre increment) and x++ (post increment). Both are equivalent to x=x+1 as well as x+=1.

7. Explain the methods of type conversions.

         Type conversion and can be done in two ways: implicitly and explicitly.

 Implicit type conversion (Type promotion) :Implicit type conversion is performed by C++ compiler internally. In expressions where different types of data are involved, C++ converts the lower sized operands to the data type of highest sized operand. Since the conversion is always from lower type to higher, it is also known as type promotion. Data types in the decreasing order of size are as follows: long double, double, float, unsigned long, long int, unsigned int, int and short int. The type of the result will also be the type of the highest sized operand.

Explicit type conversion (Type casting) : Unlike implicit type conversion, sometimes the programmer may decide the data type of the result of evaluation. This is done by the programmer by specifying the data type within parentheses to the left of the operand. Since the programmer explicitly casts a data to the desired type, it is also known as explicit type conversion or type casting. Usually, type casting is applied on the variables in the expressions. The data type compatibility is to be seriously considered in assignment statements where expressions are involved.

 8. If the file iostream.h is not included in a program, what happens?

         The header file iostream contains the information about the objects cin and cout. Eventhough header files have the extension .h, it should not be specified for GCC. But the extension is essential for some other compilers like Turbo C++ IDE. 

 9. What would happen if main() is not present in a program? 

         Every C++ program consists of a function named main(). The execution starts at main() and ends within main(). If we use any other function in the program, it is called (or invoked) from main(). Usually a data type precedes the main() and in GCC, it should be int. The function header main() is followed by its body, which is a set of one or more statements within a pair of braces { }. This structure is known as the definition of the main() function. Each statement is delimited by a semicolon (;). The statements may be executable and non-executable.

10. Identify the errors in the following code segments

 i. int main ( ) 


 cout << "Enter two numbers" ---------->

cin >> num >> auto  -------------->

float area = Length * breadth ; 



ii.

 #include <iostream>

using namespace; -------------->

 int Main()  --------------------->

{

 int a, b ------------------->

 cin <<a> >b  ------------->

 max = a % b  --------------->

 cout > max  -------------->



 Arrow marks all are errors. you find out and correct it.


11. Write the working of an assignment operator? Explain all arithmetic assignment operators with the help of examples.