+1 and +2 Computer Science

Previous Question paper answered , and Questions from Textbook

+1 and +2 Computer Application

Previous Question paper answered , and Questions from Textbook

Diploma in Computer Application (DCA)

Previous Question paper answered , and Questions from Textbook.

Master of Computer Applications (MCA)

Previous Question paper answered , and Questions from Textbook

True IQ Computer Online Academy

Contact : +91 9036433020 , mail2trueiq@gmail.com

Pageviews

Saturday, 7 September 2019

+1]7 . Control Statements - Solved Questions from text book


                     PLUS ONE 
COMPUTER APPLICATION / COMPUTER SCIENCE

                                            Chapter 7. Control Statements

                           (+1. Computer Application Questions and   answers from text book)     



1. Write a program to input an integer and check whether it is positive, negative or zero.

        #include <iostream>
using namespace std; int main() { signed long num1 = 0; cout << "\n\n Check whether a number is positive, negative or zero :\n"; cout << "-----------------------------------------------------------\n"; cout << " Input a number : "; cin >> num1; if(num1 > 0) { cout << " The entered number is positive.\n\n"; } else if(num1 < 0) { cout << " The entered number is negative.\n\n"; } else { std::cout << " The number is zero.\n\n"; } return 0; }
Output


Check whether a number is positive, negative or zero :                
-----------------------------------------------------------            
 Input a number : 8                                                    
 The entered number is positive.

 2.Write a program to input three numbers and print the smallest one.

       #include <iostream>
using namespace std;

int main()
{
    int a, b, c, d;
    cout << "Enter the value of a: ";
        cin >> a;
    cout << "Enter the value of b: ";
        cin >> b;
    cout << "Enter the value of c: ";
        cin >> c;

   if (a < b)
        d = a;
    else
        d = b;

        cout << "the smallest of the numbers is: " << ((d < c) ? d : c) << endl; //


    return 0;

}

3. Write a program to input an integer number and check whether it is positive, negative or zero        using     if…else if statement.

     
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int number;
  6. cout << "Enter an integer: ";
  7. cin >> number;
  8. if ( number > 0)
  9. {
  10. cout << "You entered a positive integer: " << number << endl;
  11. }
  12. else if (number < 0)
  13. {
  14. cout<<"You entered a negative integer: " << number << endl;
  15. }
  16. else
  17. {
  18. cout << "You entered 0." << endl;
  19. }
  20. cout << "This line is always printed.";
  21. return 0;
  22. }

 4. Write a program to input a character (a, b, c or d) and print as follows: a - "abacus", b - "boolean", c - "computer" and d - "debugging"

5. Write a program to input a character and print whether it is an alphabet, digit or any other character.

   #include<iostream>
using namespace std;

int main()
{
    char ch;
    cout << "Enter any character";
    cin >> ch;

    // Alphabet checking condition
    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        cout << ch << " is an Alphabet";
    }
    else if(ch >= '0' && ch <= '9')
    {
        cout << ch << " is a Digit";
    }
    else
    {
        cout << ch << " is a Special Character";
    }

    return 0;
}

Result

C language techstudy.org
6. Write a program to input a number in the range 1 to 12 and display the corresponding month of the year. (January for the value 1, February for 2, etc.)

        #include <iostream>
#include <string>

using namespace std;
char chr;

int main()
{
 int month;

 cout<<" Enter a number from 1-12."<<endl;
 
 if (month ==1)
  cout<< "January";
 else if (month==2)
  cout<< "February";
 else if (month==3)
  cout<<"March";
 else if (month==4)
  cout<<"April";
 else if (month==5)
  cout<<"May";
 else if (month==6)
        cout<<"June";
 else if (month==7)
  cout<<"July";
 else if (month==8)
  cout<<"August";
 else if (month==9)
  cout<<"September";
 else if (month==10)
  cout<<"October";
 else if (month==11)
  cout<<"November";
 else if (month==12)
  cout<<"December";
 else 
  cout<<"Sorry I need a number from 1-12.";
 cout<< "The month is "<<month;
 cin>>chr;
 return 0;

7. What is the significance of break statement within a switch statement?

     When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. It can be used to terminate a case in the switch statement.

8. Rewrite the following statement using if...else statement result= mark>30 ? 'p' :' f';

  Ans. 

      if(mark>30)

    {

        cout<<result="p";

else

      cout<<result="f";

}

9. Write the significance of break statement in switch statement. What is the effect of
absence of break in a switch statement?

          The break keyword causes the entire switch statement to exit, and the control is passed to statement following the switch.. case construct. Without break, the control passes to the statements for the next case.

10. What will be the output of the following code fragment?

for(i=1;i<=10;++i) ;

cout<<i+5;

 Ans.

11. Write a program using for loop that will print the numbers between 1000 and
2000 which are divisible by 132.

12. Rewrite the following statement using while and do...while loops.

for (i=1; i<=10; i++)

 cout<<i;

Ans.

    int   i=1;

      do

    {

      cout<<i;

      i++;

}

     while(i<=10);


 13. How many times the following loop will execute?

int s=0, i=0;
while(i++<5)
s+=i;

14. Briefly explain the working of a for loop along with its syntax. Give an example of for loop to support your answer.

         Syntax:
  for (initialization ; test expression; update statement)
        {
 body of the loop;
         } 
 eg. 
 for  ( n=1;  n< = 10;  ++n)
  cout << n ;
  At first initialization takes place     n=1
Then test expression evaluated   n<=10
If it is true body of the loop executed, otherwise the program control goes out of the for loop.
After execution of loop body update expression is executed   ++n.  it will repeated until test expression become false

 15. Compare and discuss the suitability of three loops in different situations.

 16. What is wrong with the following while statement if the value of z = 3. while(z>=0) sum+=z;

17. Consider the following if else if statement. Rewrite it with switch command.

 if (a==1) 

cout << “One”; 

else if (a==0)

 cout << “Zero”;

 else 

cout << “Not a binary digit”;

Ans.
        
               switch (a) 
 { 
  case  1: cout <<  “One”; 
    break; 
  case   0: cout<< “Zero”; 
    break; 
  default: cout    <<  “ Not a binary digit”; 
 } 

 18. Write the importance of a loop control variable. Briefly explain the different parts of a loop.

19.1. Explain different types of decision statements in C++.

  2. Explain different types of iteration statements available in C++ with syntax and examples.

                 Iteration statements are used to perform repeated execution of a set of one or more statements in a program. They are also known as looping statements.
  A looping statement has four parts
a). initialization of control variable
b). test expression
c). update statement for control variable
d). body of the loop
eg.  for loop, while loop, do while loop

for loop:
 
      It is an entry – controlled loop in C++.


 Syntax:
  for (initialization ; test expression; update statement)
        {
 body of the loop;
         } 
 eg. 
 for  ( n=1;  n< = 10;  ++n)
  cout << n
  At first initialization takes place     n=1
Then test expression evaluated   n<=10
If it is true body of the loop executed, otherwise the program control goes out of the for loop.
After execution of loop body update expression is executed   ++n.  it will repeated until test expression become false.

     while loop:

          It is an entry – controlled loop in C++.
 Syntax
      Initialization of loop control variable
while ( test expression)
        {
 body of the loop;
 updating of loop control variable;
         } 
 eg. 
 n=1;
             while( n< = 10)

       {
  cout << n ;
    ++n;
                }
  At first initialization takes place     n=1
Then test expression evaluated   n<=10
If it is true body of the loop executed, otherwise the program control goes out of the while loop.
After execution of  update expression   ++n . repetition takes place   until test expression become false.

         do----while loop:

         It is an exit – controlled loop in C++.
 Syntax
      Initialization of loop control variable;
do
                   {
          body of the loop;
          updating of loop control variable;
                 }  ( test expression);
 eg. 
 n=1;
             do
                 {
  cout << n ;
    ++n;
                }   while(n<= 10);
  At first initialization takes place     n=1
Then test expression evaluated   n<=10

If it is true body of the loop executed, otherwise the program control goes out of the while loop.
After execution of  update expression   ++n . repetition takes place   until test expression become false.




























Friday, 6 September 2019

+1].6 . Introduction To Programming - Previous Questions chapter wise



                         PLUS ONE COMPUTER APPLICATION 
            First Year Computer Application(Commerce) Previous Questions Chapter wise ..


                                         Chapter  6  Introduction  To Programming



1.  What is the name files created to support C++ programs and kept in the  standard library 

2.  In C++ which among the following is NOT a rule for a valid idea

a)The first character must be a letter or underscore(_).

 b)White space and special characters are not allowed

 c)Keywords can be used as an identifier

d)Upper and lower case can be treated differently. 

Ans. c

3.  The arithmetic assignment operation Y/=10 is equivalent to ...................

 a) Y=10

 b) Y=Y+10

 c) Y=Y/10

 d) None of these

    Ans. c

4. .Which of the following is not a C++ statement?

a). x = x + 10;

 b). x + = 10;

c). x + 10 = x; 

d). x = 10+ x;

 Ans. c

5.  Which header file is responsible for cout and cin objects?

   Ans. <iostream>

6.  C++ program execution starts and ends within ......... function

   Ans. main( )

7. Write output of the following program?

# include <iostream>

 using namespace std;

 int main ()

{  Int  a = 10 ;

cout<<”\n a= “ << a--;

  cout<<”\n a= “ << --a;

 return 0;
             }

Ans. output

         10, 8

8.  The following program finds the sum of three numbers. Modify the program  to find the average. (Average should display fractional part also).

 #include<iostream>

using namespace std;

int main ( )

  { int x ,y , z, result;

 cout<<"Enter values f or x ,y, z" ;

 cin>>x>>y>z;

result=x+y+z;

cout<<"The answer is ="<<result;

 return 0; 

} 

 Average of 3 numbers

#include<iostream>

using namespace std;

int main ( )

  {
 int x ,y , z;

 float avg;

 cout<<"Enter values for x ,y, z" ;

 cin>>x>>y>z;

avg = (x+y+z)/3;

cout<<"The answer is ="<<avg;

 return 0; 

} 

9.  Detect and correct the errors in the following C++ code.

  #include<iostream>

 using namespace std;

int main ( )

 {   

int a, b; 

 cout<<” Enter two numbers: “;

   cin>>a and b; 

 a + b = c;

  cout<<"Sum = “<<c;

  return 0;     

  }   


 Ans.

    #include<iostream>

 using namespace std;

int main ( )

 {   

int a, b,c; 

 cout<<" Enter two numbers:'';

   cin>>a >> b; 

  c= a+b;

  cout<<"Sum = “<<c;

  return 0;     

  }

10. .In the following program,some lines are missing.Fill the missing lines and      complete it.

     #include<iostream.h>

...............................................

{

Int num1,num2,sum;

cout<<”Enter two numbers:”;

..................................................................

..................................................................

Cout<<”Sum of numbers are =”<<sum;

}   


Ans.

        #include<iostream.h>

using namespace std;
 int main( )
{

int num1,num2,sum;

cout<<”Enter two numbers:”;

cin>>num1>>num2;

sum= num1+num2;

Cout<<”Sum of numbers are =”<<sum;

return 0;

} 


11.  a). Consider the structure of C++ program given below and answer the following question.
                   #include<iostream>
            using namespace std;
           int main( )
   {
    Statements;
   }
  Write the preprocessor directive statement in the code?   
       b). Explain the header files in a program


Ans. a. #include

   b. Header files contain  information  about functions, objects or derived data types and are available along with compiler.

12. Explain the difference between float g=9.8 ; and const float g=9.8?

           The const key word is used in the variable declaration  to make its access read only, ie we can’t change its value.
 example const float g= 9.8

     So const is known as access modifier.

  But float g=9.8 is not a constant value.It change its value.


+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.   

          

+1]5 . Data Types And Operators - Previous Questions from chapter wise



               PLUS ONE 
COMPUTER APPLICATION / COMPUTER SCIENCE

            First Year Computer Application(Commerce) Previous Questions Chapter wise ..


                                         Chapter  5 (6 for CS) Data Types And Operators




1. Given that x= 5  y=5. What will be the value of the expression x > y|| y > x? 

     Ans. False

2.  While writing a C++ program, a student forget to put semicolon at the end of a   declaration                  statement.What type of error can he expect during compilation ? 

     Ans. Syntax Error

3.   The memory size of float data type in C++ is ...............  bytes.


    a)2

     b)4 

     c)8 

      d)10 

   Ans. b

4.  Explain different types of  logical operators on C++

   and (&&):( Result will be true  only if both the combined expressions have true value)      

  or(||):Result will be true  only if any of  the combined expressions have true value )     

 not(!): To get the negation of the give expression

 d). input/out put operators: input(get from or extract operator), output (put to or  insertion operator) 

e). Assignment operator: = (to assign a value to a variable). 

5.  What is the difference between “=” and “= =” operators?

           When we have to store a value in a memory location, assignment operator (=) is used. This is a binary operator and hence two operands are required. The first operand should be a variable where the value of the second operand is to be stored.

         The = symbol assigns a value to a variable, whereas == symbol compares two values and gives True or False as the result.

6.   What is the difference between  x= 5  and x ==5 in C++

          x=5 means the value 5 is assigned or stored the variable X but X==5 means both values are compares and it gives true or false as the result. 

7. Identify the name of following operators in C++. 
      && , || , !

  Ans. && : Logical And

           ||  : Logical Or

            ! : Logical Not

8.  .Write the declaration in C++ for a variable that can be used to store height of  a   student.                    Justify, why you  have selected this data type in the declaration. 

  Ans. float Height ;

9.  Which of the following is not a character constant in C++? 
      a) ‘a’

      b) a

      c) ‘8’

       d)’\a’  

    Ans. b

10. . Memory requirement of void data type in C++ is .......... byte(s

     Ans. 0 byte

11. .Let X and Y are two variables of int data type, then correct the following  input                               statement.  

  cin<< X >> Y;

   Ans. cin>>X>>Y;

12. Write the output of the following C++ expressions. Let a=7,b=2.

     a) a+b *3/ ++b;    

     b) a<=7&&b>1;

   Ans. a) 7+2*3/++2 = 7+2*3/3 =7+2*1 =7+2=9

            b) 7<=7&&2>1 ----->True statement 

13.  Write value returned by the C++ expressions

      a). 60 % 25;

      b).  22 / 7; 


     Ans. a. 10

              b. 3


14.  How do the type modifiers affect the size and range of int and char data types?

          By using different number of bytes to store values, C++ offers three types of integers : short, int, and long that can represent up to three different integer sizes. Each comes in both signed and unsigned versions.In integer 4 bytes are used,ranges from 2147483648 to +2147483647.

     

The char type can also be signed or unsigned. Unlike int, char is neither signed nor unsigned by default. The choice is left to the C++ implementation in order to allow the implementer to best fit the type to the hardware properties.

However, these distinctions are particularly important if you are using char as a numeric type. The unsigned char represents the range 0 to 256 and signed char represents the range -128 to 127.In char 1 byte is used.

15 . Explain the difference between float g=9.8 ; and const float g=9.8?

             ref 6th chapter QS 12

16. What is implicit type conversion?Why it is called type promotion ?

             Implicit Type Conversion also known as 'automatic type conversion'. Done by the compiler on its own, without any external trigger from the user. Generally takes place when in an expression more than one data type is present. In such condition type conversion (type promotion) takes place to avoid lose of data.

17.  Distinguish between float and double data types in C++.

            Float : They are numbers with fractional part. It uses four bytes of memory. It  can be                                      represented either by scientific notation or mantissa exponential  method. 

          Double: It is used for handling large floating point numbers. It uses 8 bytes of memory.

18. . What is a variable ?Differentiate between memory address and content of the variable.

           Name given to a memory location is known as variable. It is use to store and retrieve data. It have three part: a) variable name  b). Memory address(starting address of the allocated memory)       c). Content .

       The RAM of a computer consists of collection of cells each of which can store one byte of data. Every cell (or byte) in RAM will be assigned a unique address to refer it. All the variables are connected to one or more memory locations in RAM. The base address of a variable is the starting address of the allocated memory space.

    The value stored in the location is called content of the variable. This is also called the R-value of the variable. Type and size of the content depends on the data type of the variable. Here the variable name is Num and it consumes 4 bytes of memory at memory addresses 1001, 1002, 1003 and 1004. The content of this variable is 18. That is L-value of Num is 1001 and R-value is 18.


           Image result for memory allocation of a variable images    
19.  Briefly explain any two expressions in C++. 

         expressions are composed of operators and operands. It is evaluated to get a         value(returning of value) On the basis of operators expressions can be divided into,

 a). Arithmetic expression: Expression in which arithmetic operators are used ( may be integer  or             floating point expression)

 b). Relational expression : Expression in which relational operators are used 

20.  Predict the output of the following operations. x = -5 and y = 3 initially.           

a). –x 

b). x/y  

c). x % y 

d). –x + -y 

Ans.a.  -(-5) = 5

         b.  -5/3 =-1

           c. -5%3 = -2

            d. -(-5)+-3 =2

21. . Consider the following statement.  int length;          
Then what is the difference between (a) and (b)?  a). length = 50; b). length = = 50; 

         refer Qs no.s 5 and 6

22.  Write sample statements in C++ for the cascading of input and output operators

            Multiple use of Input / Output operators in a single statement is called cascading of I/O Operator. Here the values are assigned to the variables from left to right.

 Eg. cout << x <<y <<z;

         cin >> x >> y;

23.  Explain the operations involved in the following C++ expressions and write the output.

 a) 5/2+3

 b) (10%3)/2.0

   Ans. a. 5

           b. 0.5

24. Write four different C++ statements to add 1 to the value stored in the variable     
   Num.

25.  What is the output of the following C++ statements.
   X= -7    Y = 3
   a) add –x with –y
   b) x  modulus  y

  Ans. a. -(-7)+3 =10

          b. -7%3 = -1

26. . What are data types ?Explain the fundamental data types in C++.

            Data types are the means to identify the nature of the data and the set of operations that can be performed on the data.

    There are three types of data types C++,

a). Fundamental data type (built in Data types):

 They are defined in the C++ compiler. They can not be further broken down. There are 5 types of Fundamental data types,

1). Char: They are symbols covered by the character set of C++ language. It uses only one byte                       of memory (storing in memory with its ASCII value). 

2). Int  : Whole numbers without fractional part. It can be positive or negative, or zero. It uses                       Four bytes of memory based on GCC compiler.

 3). Float : They are numbers with fractional part. It uses four bytes of memory. It  can be                            represented either by scientific notation or mantissa exponential  method.

 4). Double: It is used for handling large floating point numbers. It uses 8 bytes of memory.

 5). Void : uses zero bytes of memory.

27.  Classify the identifiers given below as valid and invalid .Give reason for invalidity.

sum

if

_Num 1

Switch

stud Age

   Ans. Valid: sum,_Num1

          Invalid : if ,Switch,stud Age

       if and Switch are keywords. stud Age is invalid identifier because white space is prohibited.

28.If a=5, b=7 and c=3.  Predict the output of the following expresssions.

a) a<c

b) b%a

 c) (a<c) && (a<b)

 d) a/c

  Ans. a. False

            b. 7%5 = 2

             c. False

              d. 5/3 =1

29.  Predict the value of 'b' in the following C++ code after execution of each code snippet

   a) and  b) Justify your answer.

 a) a = 5; b = a++;

 b) a = 5; b = ++a;

Ans. a. b=5

          b. b=6

30.   List the three numeric data types in C++ with an example for each

31.  If a = 5,   b = 4,   c = 3,  d = 4 then what is the result in x after following operation?

       X=a + b – c * d;

        Ans. X =5+4-3*4 = 5+4-12 = -3

32.  Is there any difference between (a) and (b) by considering the following statement?   char             Gender;        a). Gender  = ‘M’;        b). Gender = “M”;

          In Gender='M' means  Characters are the symbols covered by the character set of the C++ language. All letters, digits, special symbols, punctuations, etc. come under this category. When these characters are used as data they are considered as char type data in C++. We can say that the keyword char represents character literals of C++. Each char type data is allowed one byte of memory.

        Gender="M" is wrong statement because single character representation using single quote.

33.  Write a short note on arithmetic And logical operators in C++.

          Arithmetic operators are defined to perform basic arithmetic operations such as addition, subtraction, multiplication and division. The symbols used for this are +, -, * and / respectively. C++ also provides a special operator % (modulus operator) for getting remainder during division. All these operators are binary operators. Note that + and - are used as unary operators too. The operands required for these operations are numeric data. The result of these operations will also be numeric.

         Using relational operators, we can compare values. Examples are 3<5, num!=10, etc. These comparison operations are called relational expressions in C++. In some cases, two or more comparisons may need to be combined. In Mathematics we may use expressions like a>b>c. But in C++, it is not possible. We have to separate this into two, as a>b and b>c and these are to be combined using the logical operator &&, i.e. (a>b)&&(b>c). The result of such logical combinations will also be either True or False (i.e. 1 or 0). The logical operators are && (logical AND), || (logical OR) and ! (logical NOT).

34.  Write the equivalent arithmetic operations for the given C++ short hands.

 i) x% =20;    il) a+=2;   Iii)p / = 5;

 b) What is the difference between a = 20 and a = = 20?

     Ans. X=X%20
    
            b. a=a+2

             c. p=p/5


          a=20 means  the constant 20 is assigned to the variable a. a==20 means compares two values and it gives may true or false as the result.

35.  Classify the following identifiers valid or invalid. If invalid give reason.

 a). Length_1

 b). _Length1

c). Length 1

d). 1Length 

Ans. Valid: Length_1 ,_Length1

          Invalid : Length 1 ,1Length. Because identifiers are not using digit in first and Between words white spaces are not  alloweded.
       

Sunday, 1 September 2019

+1]5. Data Types And Operators - solved Questions from text book

PLUS ONE 
COMPUTER APPLICATION / COMPUTER SCIENCE                    
Chapter 5 (6 for CS) Data Types And Operators

(+1. Computer Application Questions and answers from text book)



1. Predict the output of the following operations if x=5 and y=3.

a. x>=10 && y>=4                       

 b. x>=1 && y>=3

c. x>5 && y>=2

 d. x<10 && y>2

e. x<10 && y>x

f. x>=10 || y>=4

g. x>=1 || y>=3

h. x>5 || y>=2

 i. x<10 || y>2

 j. x<10 || y>x

Ans.   a. FALSE                   

          b. TRUE

         c. FALSE

         d. TRUE

         e. FALSE

          f.  FALSE

           g. TRUE

           h.  TRUE

            i. TRUE

            j. TRUE

 2. Predict the output if p=5, q=3, r=2

 a. p-q*r/2                       

b. p*q/r                               

c. p-q-r*2+p

d. p+5*q+r*r/2

  Ans. a. 5-3*2/2 = 5-3*1 =2

            b. 5*3/2 =7.5
 
            c. 5-3-2*2+5 =5-3-4+5 =10-7=3

            d. 5+5*3+2*2/2 = 5+15+2 =22

3. What are data types? List all predefined data types in C++?

          Image result for different types of expressions in c++ images

            Data types are the means to identify the nature of the data and the set of operations that can be performed on the data.

            There are 5 types of Fundamental data types,
1). Char: They are symbols covered by the character set of C++ language. It uses only one byte                       of memory (storing in memory with its ASCII value).
 2). Int  : Whole numbers without fractional part. It can be positive or negative, or zero. It uses                       Four bytes of memory based on GCC compiler.
 3). Float : They are numbers with fractional part. It uses four bytes of memory. It  can be                            represented either by scientific notation or mantissa exponential  method.
  4). Double: It is used for handling large floating point numbers. It uses 8 bytes of memory. 
5). Void : uses zero bytes of memory.

4. What is the use of void data type?

        The data type void is a keyword and it indicates an empty set of data. Obviously it does not                   require any memory space.
5. What is a constant?

       Constants are like a variable, except that their value never changes during execution once defined. ...Constants in C are the fixed values that are used in a program, and its value remains the same during the entire execution of the program. Constants are also called literals. Constants can be any of the data types.

6. What is dynamic initialization of variables?

        Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable. Example, ... That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

7. Define operators.

        Tokens constituted by predefined symbols that can trigger to carry out operation. The participants of the operation are called operands. The operators either be constant or literal

6. What is meant by a unary operation?

         only one operand( eg +(positive),-(negative)

example:+x,-y etc.

7. What is declaration statement?

           It is used to declare the type of the variable or constant used in  the program. 

           Eg. int   x, y ; int a=10;
8. What is the input operator ">>" and output operator "<<" called ?

           extract operator(>>) and  insertion operator(<<)

9. What will be the result of a = 5/3 if a is
(i) float

 (ii) int

    Ans. i. 1.66

             ii. 1
 
10. Write an expression that uses a relational operator to return true if the variable
total is greater than or equal to final.

11. Given that i =4, j =5, k =2 what will be the result of following expressions?

(i) j <k          ------------                 False

(ii) j <j         -----------                     False

 (iii) j <= k    -----------                    False

(iv) i == j         ------------                 False

(v) i == k          -----------                  False

(vi) j > k            ----------                   True

(vii) j >= i          ----------                 True

(viii) j! = i          ------------              True

 (ix) j! = k          ---------------           True

(x) j <= k           ---------------            True


12. What will be the order of evaluation for following expressions?

(i) i+5>=j-6

 (ii) s+10<p-2+2*q

   Ans. i.

13. What will be the result of the following if ans is 6 initially?

(i) cout <<ans = 8 ;

(ii) cout << ans == 8


Ans. i.

14. What is a variable? List the two values associated with a variable.

        Name given to a memory location is known as variable. It is use to store and retrieve data. It have three part: a) variable name  b). Memory address(starting address of the allocated memory)       c). Content 4

 15. Explain logical operators.

      and (&&):  ( Result will be true  only if both the combined expressions have true value).

     or(||):  Result will be true  only if any of  the combined expressions have true value ).   

      not(!): To get the negation of the give expression.

16. Find out the errors, if any, in the following C++ statements

 (i) cout<< "a=" a;

(ii) m=5, n=l2;015

(iii) cout << "x" ; <> y 

(viii) break = x 

(v) cin >> "\n" >> y ;

(vi) cout >> \n "abc"

17. What is the role of relational operators? Distinguish between == and =.

       Relational operators are used for comparing numeric data. These are binary operators. The result of any relational operation will be either True or False. In C++, True is represented by 1 and False is represented by 0. There are six relational operators in C++. They are < (less than), > (greater than), == (equal to), <= (less than or equal to), >= (greater than or equal to) and != (not equal to). Note that equality checking requires two equal symbols (==).

       Both are not same, = is an Assignment Operator it is used to assign the value of variable or expression, while == is an Equal to Operator and it is a relation operator used for comparison (to compare value of both left and right side operands).

 18.  Explain the operators used in C++ in detail.

                        Image result for operators in c++ images

           Operators are tokens constituted by predefined symbols that can trigger computer to carry out operations. The participants of an operation are called operands. An operand may be either a constant or a variable.For example, a+b triggers an arithmetic operation in which + (addition) is the operator and a, b are operands. Operators in C++ are classified based on various criteria. Based on number of operands required for the operation, operators are classified into three. They are unary, binary and ternary.

        Unary operators : A unary operator operates on a single operand. Commonly used unary operators are unary+ (positive) and unary- (negative). These are used to represent the signs of a number. If we apply unary+ operator on a signed number, the existing sign will not change. If we apply unary- operator on a signed number, the sign of the existing number will be negated.

        Binary operators: Binary operators operate on two operands. Arithmetic operators, relational              operators, logical operators, etc. are the commonly used binary operators.

        Ternary operator :Ternary operator operates on three operands. The typical example is the conditional operator (?:).

       Arithmetic operators

 Arithmetic operators are defined to perform basic arithmetic operations such as addition, subtraction, multiplication and division. The symbols used for this are +, -, * and / respectively. C++ also provides a special operator % (modulus operator) for getting remainder during division. All these operators are binary operators. Note that + and - are used as unary operators too. The operands required for these operations are numeric data. The result of these operations will also be numeric.

       Modulus operator (%)

 The modulus operator, also called as mod operator, gives the remainder value during arithmetic division. This operator can only be applied over integer operands.

          Relational operators

Relational operators are used for comparing numeric data. These are binary operators. The result of any relational operation will be either True or False. In C++, True is represented by 1 and False is represented by 0. There are six relational operators in C++. They are < (less than), > (greater than), == (equal to), <= (less than or equal to), >= (greater than or equal to) and != (not equal to). Note that equality checking requires two equal symbols (==).

          Logical operators

Using relational operators, we can compare values. Examples are 3<5, num!=10, etc. These comparison operations are called relational expressions in C++. In some cases, two or more comparisons may need to be combined. In Mathematics we may use expressions like a>b>c. But in C++, it is not possible. We have to separate this into two, as a>b and b>c and these are to be combined using the logical operator &&, i.e. (a>b)&&(b>c). The result of such logical combinations will also be either True or False (i.e. 1 or 0). The logical operators are && (logical AND), || (logical OR) and ! (logical NOT).

            Input / Output operators

 Usually input operation requires user's intervention. In the process of input operation, the data given through the keyboard is stored in a memory location. C++ provides >> operator for this operation. This operator is known as get from or extraction operator. This symbol is constituted by two greater than symbols. Similarly in output operation, data is transferred from RAM to an output device. Usually the monitor is the standard output device to get the results directly. The operator << is used for output operation and is called put to or insertion operator. It is constituted by two less than symbols.

             Assignment operator (=)

When we have to store a value in a memory location, assignment operator (=) is used. This is a binary operator and hence two operands are required. The first operand should be a variable where the value of the second operand is to be stored.

 19. Explain different types of expressions in C++.

             An expression is composed of operators and operands. The operands may be either constants or variables. All expressions can be evaluated to get a result. This result is known as the value returned by the expression. On the basis of the operators used, expressions are mainly classified into arithmetic expressions, relational expressions and logical expressions.

            Arithmetic expressions

 An expression in which only arithmetic operators are used is called arithmetic expression. The operands are numeric data and they may be variables or constants. The value returned by these expressions is also numeric. Arithmetic expressions are further classified into integer expressions, floating point (real) expressions and constant expressions.

           Integer expressions

 If an arithmetic expression contains only integer operands, it is called integer expression and it produces integer result after performing all the operations given in the expression.

          Floating point expressions (Real expressions)

An arithmetic expression that is composed of only floating point data is called floating point or real expression and it returns a floating point result after performing all the operations given in the expression.

            Relational expressions

 When relational operators are used in an expression, it is called relational expression and it produces Boolean type results like True (1) or False (0). In these expressions, the operands are numeric data.

         Logical expressions

 Logical expressions combine two or more relational expressions with logical operators and produce either True or False as the result. A logical expression may contain constants, variables, logical operators and relational operators.


20. Arrange the fundamental data types in ascending order of size.

           Int,Float,Double,Char.

21. The name given to a storage location is known as ___________.

    Ans. Memory Address

 22. Name a ternary operator in C++.

   Ans. Conditional Operator 

23. Predict the output of the following operations if x = -5 and y = 3 initially

 a. -x

b. -y

 c. -x + -y

 d. -x - y

 e. x % -11

f. x+y

g. x%y

 h. x/y

i. x * -y

j. -x %-5

Ans.      a. 5

             b. -3

           c. -(-5)+-3 = 2

            d. -(-5)-2 =2

             e. -5%-11 = -5

               f. -5+3 = -2

                g. -5%3 = -2

                h. -5/3 = -1

                 i.   -5*-3 =15

                  j. -(-5)%-5 =0