+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

Monday, 15 July 2019

+2] 4. Web Technology - Previous questions chapter wise


PLUS TWO COMPUTER APPLICATION

(Second year +2 Computer Application / Computer Science , 
Previous Questions and Answers)

Chapter  4. Web Technology


1.The default port number of http is


(a) 20

(b) 80

(c) 110

(d) 53 .      

 Ans. b

2. Write HTML tag to set the colour of hyperlink to red .


(a) <A colour=”red” >

(b) <A colour=”FF0000” >

(c) <BODY LINK=”Red” >

(c)<BODY ALINK=”Red” > 

Ans. b

3. A webpage is created to display the result of engineering entrance examination. 
(a)What type of webpage it is ? 

(b) Mention any two features of it. 

Ans. a) Dynamic web page

         b) The content and layout may change during run time.Database is used to generate dynamic                 content through queries.

4. ……….. tag is used to make the size of the text smaller than current text  in HTML. 

(a) <b>

 (b) <small>

 (c) <sub>

 (d) <sup> . 

Ans. b

5. Compare client side scripting and server side scripting.

 
 Client side scripting                                                               Server side scripting

Script is copied to the client browser.                                
                                                                                            Script is executed in the web server and the                                                                                               web page produced is returned to the client  Script is executed in the client browser.                                browser
                                                                                                Server side scripts are usually used to         Client side scripts are mainly used for                                   databases and return data connect to       
validation of data at the client.                                                  from the web server.                                                                                                                                                                                                                                                                                                                                                                        Users can block client side scripting.                                    Server side scripting cannot be blocked                                                                                                        by  a user                                                                                                  
The type and version of the web browser                               The features of the web browser does not    affects the working of a client side script.                       affect the working of server side script
                                                                                                                                                                                                                                                                                                                                        6.  DNS stands for ………. 

    Domain name system.

9.  … …. … is a server that act as a bridge between merchant server and bank server.      

10.  Compare client side scripting and server side scripting languages. 

Client side scripting cannot be used to connect to the databases on the web server. ... Response from a client-side script is faster as compared to a server-side script because the scripts are processed on the local computer.  Examples of Server side scripting languages : PHP, JSP, ASP, ASP.Net, Ruby, Perl n many more.

11. What are the difference between static and dynamic web pages?
     
Static web page:

The content and layout of a web page is fixed. . Static web pages never use databases. Static web pages directly run on the browser and do not require any server side application program.  Static web pages are easy to develop.

Dynamic web page:
  
 The content and layout may change during run time.Database is used to generate dynamic content through queries. Dynamic web page runs on the server side application program and displays the results. Dynamic web page development  requires programming skills.  

12.   Name any two client side scripting languages.

          Java script and VB script.

13.  What do you mean by container tag in HTML?Give examples.
        Tags that require opening tag as well as closing tag are known as container tags .

Eg. <HTML>
         <HEAD>

14. a)  Name the tag used to create HyperLink.

      b) Write HTML code to show the page "Address.HTML" by clicking on the text "Address".

Ans. a) <a> tag
    
     b) To illustrate <ADDRESS> tag

<HTML>
 <HEAD> 
<TITLE> Address tag </TITLE> 
</HEAD> 
<BODY Bgcolor= "#DDA0DD">

The contact details of the "SCERT" is the following:
 <ADDRESS> State Council of Educational Research and Training (SCERT),<BR> 
Poojappura,<BR>
 Thiruvananthapuram,<BR>
 PIN: 695012, KERALA.<BR> 
Tel : 0471 - 2341883
 </ADDRESS>
 </BODY> 
</HTML>

15.  Name the two attributes of the following tags.

a)< HTML>

b) <FONT>

c) <MARQUEE>

Ans. a) The main attributes of the tag are Dir and Lang.

        b) 1. Color : This attribute sets the text colour 
           2. Face : This attribute specifies the font style. 
          
          c)  1.Behaviour : This specifies the type of scrolling of the marquee. Values: scroll, slide, alternate.etc. 
               2. Scrolldelay : This specifies time delay between each jump.
          




                                                

                                                                                            


                                






















Friday, 12 July 2019

+2].3. Functions - Solved questions from text book


                                                              Chapter 3. Functions
(+2 Computer Application , Text book Questions and Answers)


1.  What is modular programming?

     In programming, the entire problem will be divided into small sub problems that can be solved by writing separate programs. This kind of approach is known as modular programming. Each sub task will be considered as a module and we write programs for each module. The process of breaking large programs into smaller sub programs is called modularization.

2. What is meant by a function in C++?

    Function is a named unit of statements in a program to perform a specific task as part of the solution.  There are two types of functions in C++.

 a). Predefined functions or Built in Functions : Functions that are already written , compiled and their definitions are grouped and stored in header files.
  Eg. sqrt(),  toupper()

b). User Defined Functions: Functions that are written by the user to carry on some task.
  Eg.  main( )

3.  Name the header file required for using character functions.

  ctype

4.  Predict the output of cout<<sqrt(49).

output
   7

5. Pick the odd one out and give reason:

a. strlen()

b. pow()

c. strcpy()

d. strcat( )

Ans b.

6.   Name the header file needed for the function pow( ). 

    math

7. Predict the output when we compare the strings "HELLO" and "hello" using the function strcmpi(). 

Returns strings are same.Because  the uppercase and lowercase letters will be treated as same during the comparison.

8.   What will be output of the statement
 cout<<strlen("smoking kills"); ? 

output

 13

9. Which function converts the alphabet 'P' to 'p'? 

    tolower( )

10.  Identify the name of the function which tests whether the argument is an aphabet or number.

      isalpha( )

11. Identify  the most essential function in C++ programs?

      function is a group of statements that together perform a task. Every C++ program has at least one function, which is main(), and all the most trivial programs can define additional functions.

12.  List the three elements of a function header.

data_type function_name(argument_list)
 {
 statements in the body;
 }

The data_type is any valid data type of C++. The function_name is a userdefined word (identifier). The argument_list, which is optional, is a list of parameters, i.e. a list of variables preceded by data types and separated by commas. The body comprises of C++ statements required to perform the task assigned to the function.

13.  What is function prototype? 
         
        . A function prototype is the declaration of a function by which compiler is provided with the information about the function such as the name of the function, its return type, the number and type of arguments, and its accessibility. 
data_type function_name(argument_list);

14.  Which component is used for data transfer from calling function to called function? 

          Parameters or Arguments

 15. What are the two parameter passing techniques used in C++? 

         Call by value and Call by reference.

16. Identify the name of the function call where & symbol is used along with formal arguments.

      Reference variable

17.  The built-in function to find the length of a string is  _________. 

      strlen( )

18.  Write down the role of header files in C++ programs.

       In C++ the header file contain the group of function declarations that may need for the proper working of a program. So there is no need to add the function definitions of all the functions separately. 
Eg.  cmath  for mathematical functions. 

19.  When will you use void data type for function definition? 

        In most of the functions, return is placed at the end of the function. The functions defined with void data type may not have a return statement within the body. But if we use return statement, we cannot provide any value to it.Void means nothing to return datatype.

20.  Distinguish between actual parameters and formal parameters. 

         The arguments given at the calling of a function is called actual (original) arguments or actual parameters since they are the actual data passed to the function for processing.   
 Eg.  a = SimpleInterest(x, y, z);
 The arguments used in the function definition are known as formal parameter. 

 Eg.  float SimpleInterest(int P, int N, float R) 

21.  Construct the function prototypes for the following functions

 a. Total() takes two double arguments and returns a double
 b. Math() takes no arguments and has no return value

Ans.  a).      double Total (double  ,  double );
  b).      void Math(); 

22.   Discuss the scope of global and local variables with examples.

        A local variable  is one that declared within a function or a block of statements. It is available only within that function or block.
 If a variable  is declared before the main() function t is the function can be used at any place in the program. This scope is known as global scope. Also declaration of a variable outside  all functions also have global scope.

23.  How a local function differs from a global function?

 A function which is declared inside the function body of another function is called   a  local function as it can be used within that function only. A function declared outside the function body of any other function is called a   global function and its scope is the entire program



eg. #include <iostream>

using namespace std;

int cb; //global variable

void test() //global function

{

int cube(int n); // local function

cb=cube(x); //Invalid call. x is local to main()

cout<<cb;

}

int main()

{

int x=5; //local variable

test(); //valid call since test() is a global function

cb=cube(x); //Invalid call. cube() is local to test()

cout<<cb;

}

int cube(int n) //Argument n is local variable

{

int val= n*n*n; //val is local variable

return val;

} 24.  Identify the built-in functions needed for the following cases



a. To convert the letter 'c' to 'C'

b. To check whether a given character is alphabet or not.

c. To combine strings "comp" and "ter" to make "computer"

d. To find the square root of 25

e. To return the number 10 from -10




a. To convert the letter 'c' to 'C'

Ans: toupper()

b. To check whether a given character is alphabet or not.

Ans: isalpha()

c. To combine strings "comp" and "ter" to make "computer"

Ans: strcat()

d. To find the square root of 25

Ans: sqrt()

e. To return the number 10 from -10

Ans: ab

25.  Look at the following functions:

int sum(int a,int b=0,int c=0) 

{ 
return (a + b + c); 
} 

a. What is the speciality of the function regarding the parameter list?
 b. Give the outputs of the following function calls by explaining its working and give reason if the function call is wrong. 

i. cout << sum (1, 2, 3); 
ii. cout << sum(5, 2); 
iii. cout << sum(); 
iv. cout << sum(0); 

26.  The prototype of a function is: int fun(int, int); 

The following function calls are invalid. Give reason for each. 
a. fun("hello",4);
 b. cout<<fun(); 
c. val = fun(2.5, 3.3); 
d. cin>>fun(a, b); 
e. z=fun(3); 

Ans:  a). In Prototype declaration formal variables are integers but actual parameters contains string type.
  b). No actual parameters. 
 c). Actual parameters are not integer type.  
d). calling a function by cin is error. 
 e). Not enough actual parameters. 

27.  Consider the following program and predict the output if the radius is 5. Also write the reason for the output.

#include<iostream>
using namespace std;
float area(float &);
int main()
{
float r, ans;
cout<<"Enter radius :";
cin>>r;
ans = area(r);


cout<<area;
cout<<r;
return 0;
}
float area(float &p)
{
float q;
q = 3.14 * p * p;
 p++;
return q;
}

         output

 Enter the radius: 78.5
 







DEL +2 ] 1.Review of C++ programming - Solved questions from text book



                                        Chapter 1.Review of C++ programming

(+2 Computer Application , Text book Questions and Answers)


1.What is meant by token in C++?

          Tokens are the basic building blocks of a C++ program. There are five types of tokens in C++.

The are Keywords,literals,punctuators,operators&identifiers.

2.  Read the following tokens and identify the type of token to which each of these belongs:


a. number

b. 23.98

c. "\0"

d. cin

e. ++

f. void

g. '\\'

h. ;

i. =

j. a
Ans. 
     
a. identifer

b. floating point literal

c. string literal
   
d.  keywod

e.  increment operator

f. keyword

g. character literal

h. punctuators

i.  assignment operator

j.identifier


3.  What is the role of #include statement in C++ program?

  # is a pound sign which helps to pre-process the program before the compilation &include is a simple directive that tells pre-processor to include the library's data(i.e.function declarations). You might have seen, the number of line compiled are more than that of actual written code.

4.  What is wrong in the statement: cin>>25; ?

         The first operand is the pre-defined identifier cin that identifies keyboard as input object. The second operand is strictly a variable. We can use more than one variable in the same statement to receive more than one input. The following are valid examples:

cin>>r;
cin>>a>>b>>c;

5.  List the type modifiers of C++.

          Type modifiers are used to modify the size of memory space and range o data supported by the basic data types.   Eg. long, short, signed, unsigned

6. What are the selection statements of C++?

     The Selection  statements are based on a condition. They are also known as branching statements. The flow of control depends on the result of a particular condition. C++ supports three types of decision statements.

a) if statement
 b) if – else statement
c) switch statement


 a). if statement The if statement is a single path statement, which executes statement only if the condition is true.
 Syntax :

if(condition or expression)
 statement1; If the condition is true then the statement1 will be executed.

  if (mark >=18)
 cout <<”You have Passed “ ;

In the above example the message You have passed will be displayed only when the condition is true ie, mark >=18 is true.
b). if – else statements
The if... else statement is used to test a logical condition and choose one of the alternatives based on the result of logical condition.

The syntax :
  If (condition or expression)
statement 1; else statement 2;

eg.        if (a > b)
 cout << “First number is largest: ” ; 
  else
 cout <<”Second number is largest: ” ;

c). Nested if
An if – else statement can be placed inside another if – else statement, is called nesting of if. Example 
if (mark >=80) 
 {   
  if (age>18)       
  cout<<”Eligible for higher studies” ; 
        else

        cout <<”Not Eligible” ;
 }
d). else-if ladder

The else-if ladder helps to select one out of many alternative block of statements.

Syntax :
  if (test-expression)
{
Statement 1;
}
else if (test-expression)
{
Statement 2;
 }
else if (test-expression)
{
 Statement 3;
 }
 else
{
 Statements;
}

Eg.
 if ( percentage>=90)
     cout<<”A+”’
 else  if   ( percentage>=80) 
   cout<<”A”’
 else  if ( percentage>=70) 
    cout<<”B+”’
  else  if ( percentage>=60)   
  cout<<”B’
else  if ( percentage>=50) 
   cout<<”C+”’
 else     
cout<<”Low Score”’     

c.  Switch statement

The Switch enables to select one among several alternatives. It is a multipath statement.
 Syntax:
 Switch (expression)
 {
case value1 :Statement 1;
break;
 case value2 :Statement 2;
break;
case value3 :Statement 3;
break;
----------------------
 default : Statement n;
 }
The expression is evaluated and statements are executed according to the value . If no match is
found, then default statement is executed.
Eg. 
switch(day_no) 
{
 case  1 : cout<<”Sunday”;
 break;
case 2 : cout<<”Monday”;
  break;
 case  3 : cout<<”Tuesday”; 
break;
  ……………………..   ……………………..                     
 default  : cout<<”Invalid entry”;

7.  What are the four components of a loop?

     Loop statements usually have four components: initialization (usually of a loopcontrol variable), continuation test on whether to do another iteration, an update step, and a loop body.

8.  Give examples for entry-controlled loop.

    for loop,while loop

9.   Which control transfer statement is equivalent to the conditional operator (?:)?
   
       if-else statement.

10.   All switch statements can be replaced by any form of if statement. State whether it is true or false.

     Ans: False. Reason: In some cases switch statement can't replaced by if...else.

11.  What is wrong with the following code segment?

 for (short i=1; i<5; ++i)
 for (i=5; i>0; --i) 
cout<<i<<"\t"; 

12. Distinguish between break and continue statements

   Break statement is used to terminate a loop or switch statement. 
 Continue statement is used to continue to the beginning of a loop. When a continue statement is executed in a loop it skips the remaining statements in the loop and proceeds with the next iteration of  the loop.

13. The default case in switch is equivalent to the else block of else if ladder. Justify this statement with the help of example. 

 if ( percentage>=90)       
cout<<”A+”;
 else  if   ( percentage>=80)   
    cout<<”A”;
 else  if ( percentage>=70)   
    cout<<”B+”; 
else  if ( percentage>=60)    
   cout<<”B";
 else  if ( percentage>=50)     
  cout<<”C+”;
  else     
  cout<<”Low Score”;

Corresponding switch statement

Switch(percentage)
 case

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

for (outer=10; outer>5; --outer)
 for (inner=1; inner<4; ++inner) 
cout<<outer<<"\t"<<inner<<endl; 

Ans. 10 9 8 7 6
          1 2 3

15.  Write a program to produce the following output using nested loop:

 A
 A B
 A B C
A B C D
A B C D E

#include<iostream.h>
#include<conio.h>

int main()
{
char ch='A';
int n;
cout<< "\n Enter the height of the triangle :";
cin>> n;
for(int i=1; i< = n ; i++)
{
ch = 'A';
for(int j = 1; j< = i; j++)
{
cout<< ch<< " ";
ch++;
}
cout<< "\n";
return 0;
}


16. Read the following C++ code snippet:

for (n=1; n<5; ++n)

{ 
cout<<i;
if (i==2)
continue;
if (i%3==0)
break;
cout<<"Hello";
}

Choose the correct output of this code from the following:

a. 1Hello2Hello3Hello4Hello

b. 1Hello2Hello3

c. 1Hello23

d. 1Hello23Hello 

Ans d


17.  Read the following C++ code segment and replace it with a looping statement:

cin>>n; 
loop: r=n%10; 
s=s*10+r; 
n=n/10; 
if (n!=0) goto loop;
 cout<<s;

Ans
cin>>n;
for(int n=1;n!=0;n=n/10)
r=n%10;
s=s*10+r;
cout<<s;

18. Which of the following is not a character constant in C++? 

a. '\t' 
b. 'a'
 c. '9'
 d. '9a' 
Ans. d

19. Some of the following identifiers are invalid. Identify them and give reason for the invalidity.

 a. unsigned
 b. cpp
 c. 2num
 d. cout 

unsigned is not an identifier.This is a keyword.
2num is not an identifier. Starting with digit is not allowed in program

20.  What happens if break is not used in switch statement?

Switch case statements are used to execute only specific case statements based on the switch expression. If we do not use break statement at the end of eachcase, program will execute all consecutive case statements until it finds next break statement or till the end of switch case block.












Tuesday, 9 July 2019

+2 ] 3.Functions.- Previous questions Chapter wise


PLUS TWO COMPUTER APPLICATION

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

Chapter 3  Function



1.  . ………. Function is used to check whether a character is alphanumeric.

  • (a) isdigit( )
  •  (b) isalnum( ) 
  • (c) isupper( )
  •  (d) islower( )
  Ans. b

2.  Consider the following code : 

char s1[ ]=”program” 
char s2[ ]=”PROGRAM” 
int n; 
n=strcmpi(S1,S2) 
What is the value of n ? 
  • (a) n=0  
  • (b) n=1 
  • (c) n>1     
  •  (d) n< 0 
Ans.  a

3. Explain any three string function with example  

          i. strlen() : This function is used to find the length of a string(Number of characters ). Its return value is an integer.

 n = strlen(str); 

ii. strcpy() : This function is used to copy one string into another. 

 Syntax : strcpy(string1, string2);
Eg: strcpy(s1,s2);

 iii. strcat() : This function is used to append one string to another string. The length of the resultant string is the total length of the two strings.

 Syntax: strcat(string1, string2);
 Eg. strcat(s1,s2); 

4. . Explain any three stream functions for I/O operation

         Stream functions allow a stream of bytes (data) to flow between memory and objects like Key Board or Monitor A.

 Input functions 

a). get() : It can accept a single character or multiple characters (string) through the keyboard. To accept a string, an array name and size are to be given as arguments.

 Eg cin.get(str,10) 

b). getline() : It accepts a string through the keyboard. The delimiter will be Enter key, the number of characters or a specified character.
 Eg. cin.getline(str,len); 
 cin.getline(str,len,ch); 

 Output functions

 a). put() : It is used to display a character constant or the content of a character variable given as argument. 
 Eg. cout.put('B'); cout.put(65); 

b). write() : This function displays the string contained in the argument.
 Eg. cout.write(str,10); 8

5. . Write a code to do the following : 
(a)A function named largest accept two integer numbers and return the  Largest number.  
 (b)Use this function to find the largest of two numbers

#include <iostream>
using namespace std;
int largest(int a, int b)
 {
 Int large;

 if(a > b)
 large = a;
 else
 large = b;
 return large;
 }
int main()
{
 int n,m, p;
 cout<<"Enter the Number for checking :";
 cin>>n<<m;
 p = largest(n,m);
 cout<< “ The largest number is : “<<p<<endl; 
return0;
}

6.  Write a function that accept 3 numbers of type float as argument     And   return the  average of three numbers.      
 Write program which use this function  to  find the average of three numbers using C++

#include <iostream>
using namespace std;
int average(float a, float b, float c)
 {
 float av;
 av=(a + b + c) / 3;
 return av;
 }
int main()
{
 float n, m, o, p;
 cout<<"Enter 3 Number for finding Average :";
 cin>>n<<m<<o;
 p = largest(n,m,o);
 cout<< “ The average is : “<<p<<endl; 
return0;
}

7.  ---------------- function used to append one string to another string in C++

Ans. strcat( )

8. Define the term  function  in C++

          Function is a named unit of statements in a program to perform a specific task as part of the solution.  There are two types of functions in C++.

 a). Predefined functions or Built in Functions : Functions that are already written , compiled and their definitions are grouped and stored in header files.
 Eg. sqrt(),  toupper()

b). User Defined Functions: Functions that are written by the user to carry on some task'
 eg. main( )

9. In C++ declare a function prototye "Display" with two arguments?

 int add(int a, int b);

It is not necessary to define prototype if user-defined function exists before main() function.

10. Define the function "calcsum( )" with return value as sum of three integer variables?

11. What are the difference between Call by reference and Call by value of function calling in   C++? 
Call by Value Method                                              Call by Reference Method
Ordinary variables are used as formal                   Reference variables are used as formal parameters. 
 parameters. 

Actual parameters may be constants,                    Actual parameters will be variables only. 
 variables or expressions.

The changes made in the formal                         The changes made in the formal arguments do  
arguments do not reflect in actual                        reflect in actual arguments.
arguments. 

Exclusive memory allocation is required            Memory of actual arguments is shared by formal 
for the formal arguments                                       arguments.    
     
12. Differentiate between global and local variables?

              If a variable  is declared before the main() function t is the function can be used at any place in the program. This scope is known as global scope. Also declaration of a variable outside  all functions also have global scope. 
           
                  A local variable  is one that declared within a function or a block of statements. It is available only within that function or block.
  



Friday, 5 July 2019

+2 ] 2. Arrays - Solved Questions from Text Book

Chapter 2: Array
(+2 Computer Application , Text book Questions and Answers)



1. Write array declarations for the following:

a. Scores of 100 students : int score[100];

b. English letters : char a[10];

c. A list of 10 years : int year[12];

d. A list of 30 real numbers : float n[30];


2. Write array initialization statements for the following:

a. An array of 10 scores: 89, 75, 82, 93, 78, 95, 81, 88, 77,and 82

Ans: int score[10] = {89, 75, 82, 93, 78, 95, 81, 88, 77, 82};


b. A list of five amounts: 10.62, 13.98, 18.45, 12.68, and 14.76

Ans: float amt[5] = { 10.62, 13.98, 18.45, 12.68, 14.76 };


c. A list of 100 interest rates, with the first six rates being 6.29, 6.95,

7.25, 7.35, 7.40 and 7.42.

Ans: float rate[100] = { 6.29, 6.95, 7.25, 7.35, 7.40, 7.42};


d. An array of 10 marks with value 0.

Ans: int mark[10]={NULL}; or int mark[10]={0,0,0,0,0,0,0,0,0,0};


e. An array with the letters of VIBGYOR.

Ans: char c[7]={'V','I','B','G','Y','O','R'};


f. An array with number of days in each month.

Ans: int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};

  • 3. Write a C++ code to input values into the array: int ar[50];
int i , ar[50];

for (i=0;i<50;i++)

{

cout << ”Enter value”;

cin << ar[i];

}

  • 4. Write a C++ code fragment to display the elements in the even positions of the array
float val[100];

int i;

float val[100];

for (i = 0; i <100; i += 2)

{

cout << ”Enter value”;

cin << ar[i];

}

  • 5. The elements of an array with ten elements are numbered from ____ to ____.
 Ans. 0 to 9 

  • 6. An array element is accessed using _____.

Ans. Index value

  • 7. If AR is an array, which element will be referenced using AR[7]?

  Ans.  Element at the position 8.

  • 8. Consider the array declaration int a[3]={2,3,4}; What is the value of a[1]?

     Ans. 3

  • 9. Consider the array declaration int a[]={1,2,4}; What is the value of a[1]?

   Ans. 2

  • 10. Printing all the elements of an array is an example for _____ operation.

 Ans. Array traversal

  • 11. What does the declaration int studlist[1000] mean?

studlist is an array which can hold 1000 integer values.

  • 12. How is memory allocated for a single dimensional array?

The elements of a single dimensional array will store in continues memory locations according

to its data type

Eg. int n[5]; Here consider n[0] is in the memory location of address 1000. An integer data

need 2 bytes of memory. So n[1] will be at 1002, n[2] at 1004 and so on.

  • 13. Read the following statements:

char name[20];

cin>>name;

cout<<name;

What will be the output if you input the string “Sachin Tendulkar”? Justify your answer.

Sachin. The letters of the word Sachin is stores in the array name as first 6 char elements.

The input is completed due to the blank space and the word Tendulkar is skipped.

  • 14. Write C++ statements to accept two single dimensional arrays of equal length

and find the difference between corresponding elements.

#include<iostream>

using namespace std;

int main()

{

int n[10],m[10],i;

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

{

cout <<"Enter elements for First Array ";

cin>>n[i];

}

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

{

cout <<"Enter elements for Second Array ";

cin>>m[i];

}

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

{

if(n[i] |= m[i])

cout<<endl<<" At the possition "<< i+1<< " First Array

elementis :" << n[i]<<"and the Second Array Element is :"<<m[i]<<endl;

}

return 0;

}

  • 15. Write a program to check whether a string is a palindrome or not.

#include<iostream>

#include <cstring>

using namespace std;

int main()

{

int n,i,flag=0 ;

char s[25];

cout <<"Enter the string for palindrome checking ";

cin>>s;

n=strlen(s);

for ( i = 0 ; i <= n/2 ; i++ )

{

If ( s[i] != s[ n-(i+1)] )

{

cout<<" The given string is not a palindrome " <<endl;

flag=1;

break;

}

}

if (flag==0)

cout <<"\nThe given string is a palindrome\n";

}

}

if (flag==0)

cout <<"\nThe given string is a palindrome\n";

return 0;

}

  • 16. Write C++ statements to accept an array of 10 elements and display the count

of even and odd numbers in it.

#include<iostream>

using namespace std;

int main()

{

int i,r,even=0,odd=0,no[10];

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

{

{

cout<<"Enter no ";

cin>>no[i];

}

}

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

{

r=no[i]%2;

if(r==0)

even++;

else

odd++;

}

cout<<" \n No of even numbers among the given numbers :"<<even<<endl;

cout<<" \n No of even numbers among the given numbers :"<<odd<<endl;

return 0;

}

  • 17. Write down the output of the following code segment:

puts(“hello”);

puts(“friends”);

output:

hello

friends

  • 18. Write the initialisation statement to store the string "GCC".

Ans. char[3]={'G','C'.'C'};

  • 19. Define an array?

  Arrays are used to store a set of values of the same type in contiguous memory locations under

a single variable name. Each element in an array can be accessed using its position in the list,

called index number or subscript.

Eg. int a[10];

Thursday, 4 July 2019

+2 ] 2. Arrays - Previous Questions Chapter wise

PLUS TWO COMPUTER APPLICATION

Second Year Computer Application(Commerce) Previous Questions Chapter wise ..
Chapter 2: Arrays



1. char s1[10] =”hello”, s2[];

      strcpy(s1,s2);

      cout<<s2;

  What will be the output?
  • a) hello
  •  b) hel
  • c)hell
  • d) no output
Ans. d.

2. How memory is allocated for a float array?

If it is a float array then its elements will occupy 8 bytes of memory each. But this is not the total size or memory allocated for the array. They are the sizes of individual elements in the array.

3. How we can initialize an integer array ?Give an example?

     Giving values to the array elements at the time of array declaration is known as array initialization  .

Example An array of 10 scores: 89, 75, 82, 93, 78, 95, 81, 88, 77,and 82
 int score[10] = {89, 75, 82, 93, 78, 95, 81, 88, 77, 82};

4.  Define an array.Give an example of an integer array declaration?

        Arrays are used to store a set of values of the same type in contiguous memory locations under a single variable name. Each element in an array can be accessed using its position in the list, called index number or subscript.

    Score of 100 marks : int score[100];

5.   Write C++ initialization statement to initialize an integer array name ‘MARK’ with the values            70,  80 , 85 , 90.

                 int MARK[4]={70,80,85,90};

6 .    Explain how allocation of string takes place in memory?
 
                 A sting can be considered as an array of characters.Character array ,characters will occupy          1 byte of memory each.Null character('/0') is stored in the end of the string.

            example: "computer" is a string.It can be stored in memory by 1byte of each character.

7.     Explain gets( ) and puts( ) functions?

                 gets() function is used to accept a string of characters including whitespace from standard   input device(eg. Keyboard) and store it in a character array.

Syntax: gets(String_data)
Eg. gets(str);

puts() function is used to display a string data on a standard output device(eg. Monitor)    
    Syntax: puts(String_data) 
   
    Eg. puts(“ Hello “); 

8 .  Consider the following C++ code

      char text[20];
      cin≫text; cout≪text;

 If the input string is “Computer Programming”; what will be the output ?justify your answer.
 
    Ans. output- Computer Programming

           Character array name text is the size 20.That is 20 characters can allocate to the memory.If the input string is "computer programming"total characters are 20 including one white space between computer and programming.so the output will print computer programming.Null character is stored at the end of the string.

9.   Write the output of the C++ code segment

          char s1[10] = “Computer”;
        char s2[10] = “Application”;
       strcpy(s1,s2);
        cout<< s2;

Output : -Applicatio

10.   Write a C++ program to accept a string and find its length without using built in function. Use a character array to store the string .
 
          /* C Program to find the length of a String without using built in function
 *  using any standard library function 
 */
#include <stdio.h>
int main()
{
    /* Here we are taking a char array of size 
     * 100 which means this array can hold a string 
     * of 100 chars. You can change this as per requirement
     */
    char str[100],i;
    printf("Enter a string: \n");
    scanf("%s",str);

    // '\0' represents end of String
    for(i=0; str[i]!='\0'; ++i);
       printf("\nLength of input string: %d",i);
    
    return 0;
}

output
  
          string_length_output


11.  Write a program to input ‘N’ numbers into an integer array and find the largest  number in the array.
   
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int i, n;
  6. float arr[100];
  7. cout << "Enter total number of elements(1 to 100): ";
  8. cin >> n;
  9. cout << endl;
  10. // Store number entered by the user
  11. for(i = 0; i < n; ++i)
  12. {
  13. cout << "Enter Number " << i + 1 << " : ";
  14. cin >> arr[i];
  15. }
  16. // Loop to store largest number to arr[0]
  17. for(i = 1;i < n; ++i)
  18. {
  19. // Change < to > if you want to find the smallest element
  20. if(arr[0] < arr[i])
  21. arr[0] = arr[i];
  22. }
  23. cout << "Largest element = " << arr[0];
  24. return 0;
  25. }

output

    Enter total number of elements: 8

Enter Number 1: 23.4
Enter Number 2: -34.5
Enter Number 3: 50
Enter Number 4: 33.5
Enter Number 5: 55.5
Enter Number 6: 43.7
Enter Number 7: 5.7
Enter Number 8: -66.5

Largest element = 55.5
12. Write C++ program to input 10 numbers in an integer array and find the sum of numbers which           are exact multiples of 5.

 13.   Write C++ program to input 10 numbers in an integer array and find the second largest element.
 
#include <iostream>
using namespace std;
int main(){
   int n, num[50], largest, second;
   cout<<"Enter number of elements: ";
   cin>>n;
   for(int i=0; i<n; i++){
      cout<<"Enter Array Element"<<(i+1)<<": ";
      cin>>num[i];
   }
   /* Here we are comparing first two elements of the
    * array, and storing the largest one in the variable
    * "largest" and the other one to "second" variable.
    */
   if(num[0]<num[1]){ 
      largest = num[1];
      second = num[0];
   }
   else{ 
      largest = num[0];
      second = num[1];
   }
   for (int i = 2; i< n ; i ++) {
      /* If the current array element is greater than largest
       * then the largest is copied to "second" and the element
       * is copied to the "largest" variable.
       */
      if (num[i] > largest) {
         second = largest;
         largest = num[i];
      }
      /* If current array element is less than largest but greater
       * then second largest ("second" variable) then copy the
       * element to "second"
       */
      else if (num[i] > second && num[i] != largest) {
         second = num[i];
      }
   }
   cout<<"Second Largest Element in array is: "<<second;
   return 0;
}
Output:
Enter number of elements: 5
Enter Array Element1: 12
Enter Array Element2: 31
Enter Array Element3: 9
Enter Array Element4: 21
Enter Array Element5: 3
Second Largest Element in array is: 21

Explanation:
User enters 5 as the value of n, which means the first for loop ran times to store the each element entered by user to the array, first element in num[0], second in num[1] and so on.

14. Consider the following C++ code
          
      int main()
{
 char str[20];
cout<<"Enter the string";
cin>>str;
puts(str);
return 0;
}

a) Write the value of str if the string "HELLO WORLD" is input to the code.Justify?

Ans. HELLO 
           The letters of the word HELLO is stores in the array str as first 6 char elements The  input  is completed due to the blank space and the word "WORLD" is skipped

b)  Write the amount of memory allocated for storing  the arr str.Give reason?
         The amount of memory allocated for storing the arr str is 20.
       Note that a null character '\0' is stored at the end of the string. This character is used as the string terminator and added at the end automatically. Thus we can say that memory required to store a string will be equal to the number of characters in the string plus one byte for null character.
 c) Write an alternative we can use to input the string in place of cout?
Ans. gets(str );

15. Write a C++ statement to declare with an array size  25 to accept the name of a student

Ans.  char name[25];

16. -------------- is a collection of elements of same type place in a contigious memory locations

Ans. Array

17. Write C++ statement for the following
       a) Declare an integers array "MARK" to store marks of five pupils
       b) Initialize the array "MARK" with values 30,50,65,25,70

Ans.a) int MARK[5];

        b) int MARK[5]={30,50,65,25,70};