Plus Two Computer Application Chapter Wise Previous Questions Chapter 2 Arrays

Kerala State Board New Syllabus Plus Two Computer Application Chapter Wise Previous Questions and Answers Chapter 2 Arrays.

Kerala Plus Two Computer Application Chapter Wise Previous Questions Chapter 2 Arrays

Plus Two Computer Application Arrays 1 Mark Important Questions

Question 1.
Write C++ initialization statement to initialize an integer array name ‘MARK’ with the values 70,80,85,90. (MARCH-2017)
Answer:
MARK[4] = {70,80,85,90};
MARK[ ] = {70,80,85,90};
MARK[0] = 70;
MARK[1] = 80;
MARK[2] = 85;
MARK[3] = 90;

Plus Two Computer Application Arrays 2 Mark Important Questions

Question 1.
How memory is allocated for a float array? (MARCH-2016)
Answer:
Memory allocated for the float data type is 4.
Total byte = size of array *4
eg. float n[10];
Here total byte = 10*4
That means 40 bytes.

Question 2.
How can we initialize an integer array? Give an example. (MARCH-2016)
Answer:
Array elements can be initialised at the time of declaration and values are included in braces,
eg: ing n[5]={10,20, 30,40, 50};

Question 3.
Answer any of the following questions 4(a) or 4(b). (MARCH-2016)
a) Define an array. Give an example of an integer array declaration.
b) Consider the following C++ code char text [20]; cin>>text;
If the input string is “Computer Programming”, what will be the output? Justify your answer.
Answer:
a) An array is a collection of elements with the same data type.
eg:- int n[100]; This is an array namely n. We can store 100 elements. The index of the first element is 0 and the last is 99.
b) The output is “Computer”. This is because of c in reads the characters up to space. That means space is the delimiter, The character after space is truncated.

Plus Two Computer Application Arrays 3 Mark Important Questions

Question 1.
Write a C++ program to input 10 numbers into an integer array and find the sum of numbers which are an exact multiple of 5. (MARCH-2017)
Answer:
#include <iostream>
using namespace std;
int main()
{
int n[10],i,sum=0;
for(i=0;i<10;i++)
{
cout<<“Enter value for number”<<i+1
cin>>n[i];
if(n[i]%5==0)
sum+=n[i];
}
cout<<“The sum of numbers which are exact multiple of 5 is“<<sum;
V;
}

Plus Two Computer Application Arrays 5 Mark Important Questions

Question 1.
Write a C++ program to accept a string and count the number of words and vowels in that string. (MARCH-2016)
Answer:
(a) #include(iostream>
# include <cstdio>
# include<cctype>
using namespace std;
void main ()
{
int i, vowel =0, words=1; ,
charstr[80];
cout<< “Enter a string \n”;
gets (str);
for (i=0, str[i]! = ‘\0’; i++)
{
if (str [i] ==32) words ++;
’ switch (to lower(str[i]))
{
case ‘a’: case ‘e’: case ‘i’: case ‘O’: case ‘u’: vowel ++;
}
count<<“The number of words is” <<words; count<<“\n the number of vowels is”<<vowel;
}

Question 2.
Write a C++ program to accept N integer numbers and find the sum and average of even numbers. (MARCH-2016)
Answer:
# include <iostream>
using namespace std;
void main ()
{
float avg, sum = 0.0;
int N, i, no;
cout <<“Enter how many numbers”;
cin>>N;
for(i=0; i<N; i++)
{
cout<< “Enter number”<<i+1; cin >> no; if (no % 2 == 0) sum+=no;
}
avg=sum/N;
cout<< “The sum of even numbers is”<<sum; cout<<“\n the average of even numbers is” <<avg;
}

Question 3.
Answer any of the following questions 8(a) or 8(b). (MAY-2016)
a) Write a C++ program to accept a string and find the length of the string without using built in function. Use a character array to store the string.
b) Write a program to input ‘N’ numbers into an integer array and find the largest number in the array.
Answer:
a) # include <iostream>
# include <cstdio>
using namespace std;
int main ()
{
charstr [80]; int i;
cout <<“Enter a string:”;
gets(str);
for(i=o;str[i]!= ‘\0’;i++)
cout <<“The length of the string is “<<i;
}
OR

b) # include <iostream>
using namespace std;
int main ()
{
int N, no[50], i, largest = 0;
cout<< “Enter how many numbers”;
cin>>N;
for (i=0; i<N; i++)
{
cout <<“Enter number”<<i+1;
cin>>no[i];
if (no[i]> largest)
largest = no[i];
}
cout <<“The largest number is” <<largest;
}

Question 4.
Write a C++ program to enter 10 numbers into an array and find the second largest element. (MAY-2016)
Answer:
#include<iostream>
using namespace std;
int main()
{
int i,j,n[10],temp;
for(i=0;i<10;i++)
{
cout<<“Enter a value for number”<<i+1 cin>>n[i];
}
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
if(n[i]<n[j])
{
temp=n[i];
n[i]=n[j];
n[j]=temp;
}
}
cout<<“The second largest number is “<<n[1];
}

Question 5.
Write a C++ program to convert all lowercase alphabets stored in a string to uppercase. (MAY-2016)
Answer:
#include<cstdio>
using namespace std;
int main()
{
charline[80];
int i;
puts(“Enter the string to convert”);
gets(line);
for(i=0;line[i]!=’\0′;i++)
if (line[i]>=97 && line[i]<=122)
line[i]=line[i] – 32;
puts(line);
}