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
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( )
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);
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.