· web viewwrite a driver program to test class savingsaccount. instantiate two different objects...

24
KENDRIYA VIDYALAYA DRDO C V RAMAN NAGAR BENGALURU 560093 HOLIDAY HOMEWORK IN COMPUTER SCIENCE FOR CLASS XII Q 1. i. What is the difference between Run Type error and Syntax error? Give one example of each. ii. When will you make function inline and why? iii. What are actual arguments and formal arguments in C++? Explain with example. iv. Differentiate between call by reference and call by value, with example? v. Explain the concept of inheritance in OOPs with example? vi. Illustrate the use of local and global variables in C++, with an example. vii. What is this pointer? Give an example to illustrate the use of it in C++. viii. What is the significance of private, protected and public specifiers in a class? With an example explain in detail. ix. Differentiate between a default and a parameterized constructor in context of class and object. Give suitable example in C++. x. What is the similarity and difference between break and continue statements? xi. What is the difference between abstract class and concrete class? xii. What do you mean by static variable? Explain with help of example. xiii. How member functions and nonmember functions differ? Explain with example. xiv. What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to illustrate both. xv. What do you understand by Polymorphism? Give a suitable example of the same. xvi. Give the difference between the type casting and automatic type conversion .Also, give a suitable C++ code to illustrate both. Q 2. i. Define a class TAXPAYER in C++ with following description : Private members : Name of type string PanNo of type string Taxabincm (Taxable income) of type float TotTax of type double A function CompTax( ) to calculate tax according to the following slab: Taxable Income Tax% Up to 160000 0

Upload: vocong

Post on 29-Apr-2018

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

KENDRIYA VIDYALAYA DRDO C V RAMAN NAGAR BENGALURU 560093

HOLIDAY HOMEWORK IN COMPUTER SCIENCE FOR CLASS XII

Q 1.

i. What is the difference between Run Type error and Syntax error? Give one example of each.

ii. When will you make function inline and why?iii. What are actual arguments and formal arguments in C++? Explain with example.

iv. Differentiate between call by reference and call by value, with example?v. Explain the concept of inheritance in OOPs with example?vi. Illustrate the use of local and global variables in C++, with an example. vii. What is this pointer? Give an example to illustrate the use of it in C++.viii. What is the significance of private, protected and public specifiers in a class? With an example explain in detail.ix. Differentiate between a default and a parameterized constructor in context of class and object. Give suitable

example in C++.x. What is the similarity and difference between break and continue statements?xi. What is the difference between abstract class and concrete class?xii. What do you mean by static variable? Explain with help of example.xiii. How member functions and nonmember functions differ? Explain with example.xiv. What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to

illustrate both.xv. What do you understand by Polymorphism? Give a suitable example of the same.xvi. Give the difference between the type casting and automatic type conversion .Also, give a suitable C++ code to

illustrate both.

Q 2.

i. Define a class TAXPAYER in C++ with following description : Private members :Name of type stringPanNo of type stringTaxabincm (Taxable income) of type floatTotTax of type doubleA function CompTax( ) to calculate tax according to the following slab:Taxable Income Tax% Up to 160000 0 >160000 and <=300000 5 >300000 and <=500000 10 >500000 15Public members:

A parameterized constructor to initialize all the members A function INTAX( ) to enter data for the tax payer and call function CompTax( ) to assign TotTax. A function OUTAX( ) to allow user to view the content of all the data members.

ii. Define a class ELECTION with the following specifications. Write a suitable main ( ) function also to declare 3 objects of ELECTION type and find the winner and display the details.

Private Members :

Page 2:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

Data : Candidate_Name , Party , Vote_Received

Public members :Functions : Enterdetails ( ) – to input dataDisplay ( ) – to display the details of the candidatesWinner ( ) – To display the details of the winner through the object after comparing the votes received by three candidates.

iii. Define a class Stock in C+ + with the following description:Private Members

ICode of type integer (Item Code) Item of type string (Item Name) Price of type float(Price of each item) Qty of type integer (quantity in stock) Discount of type float (Discount percentage on the item) A member function FindDisc( ) to calculate discount as per the following rule:

If Qty<=50 Discount is 0 If Qty (51 and100) Discount is 5 If Qty>100 Discount is 10

Public Members: A constructor to assign all values with 0 and null respectively A function Buy( ) to allow user to enter values for ICode, Item, Price, Qty and call function FindDisc( ) to

calculate the discount. A Function ShowAll( ) to allow userto view the content of all the data members.

iv. Define a class BATSMAN with the following specifications: Private members

bcode integer typebname (20 characters)innings,notout, runs integer typebatavg it is calculated according to the formula : batavg= runs/(innings-notout)calcavg function to calculate batavg.

Public membersreaddata( ) function to accept values for bcode, name, innings, notout and invokem the function

calcavg( )displaydata( ) function to display data members on the screen.

v. Define a class BALANCED_MEAL in C++ with following description: Private Members:

Access_no IntegerFood_Name String of 25 characters

Calories Integer Food_type String Cost Float AssignAccess( ) Generates random numbers between 10 and 99 and return it. Public Members

A function INTAKE( ) to allow the user to enter the values of Food_Name, Calories, Food_type, cost and call function AssignAccess( ) to assign Access_no.

A function OUTPUT( ) to allow user to view the content of all the data members, if the Food_type is Fruit. Otherwise display message, “Display only for fruit”.

vi. Define a class TEST in C+ + with following description:Private MembersTestCode of type integerDescription of type stringNoCandidate of type integerCenterReqd (number of centers required) of type integer A member function CALCNTR ( ) to calculate and return the number of centers as (NoCandidate/100+1)Public Members

Page 3:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

A function SCHEDULE( ) to allow user to enter values for TestCode, Description, NoCandidate & call function CALCNTR( ) to calculate the number of centres.A function DISPTEST ( ) to allow user to view the content of all the data members.

vii. Define a class REPORT with the following specification.Private:

Adno 4 digit admission numberName 20 charactersMarks an array of floating point valuesAverge average marks obtainedGetavg() to compute the average obtained in five subjects

Public:Readinfo() funtion to accept values for adno,name,marks and Invoke the function getavg()Displayinfo() function to display all data members on the screen.

viii. Define a class named DRAMA in C++ with the following description Private membersSHOW_NO integerNAME_OF_THE_DRAMA Array of characters (String)DAY integer (Total number of days the same drama is shown)DAILY_COLLECTION floatTOTAL_COLLECTION floatPublic Members input_data : A user defined function to read an object of ENTRY typeprint_data : A function to display the details of an object update_data: A function to update the total collection and daily collection once the day changes. Total collection will be incremented by daily collection and daily collection is made Zero

ix. Define a class DEPARTMENTAL with the following specification : private data members Prod_name string (45 charactes) [ Product name] Listprice long Dis_Price long [ Discount Price] Net long [Net Price ] Dis_type char(F or N) [ Discount type] Cal_price() – The store gives a 10% discount on every product it sells. However at the time of festival season the store gives 7% festival discount after 10% regular discount. The discount type can be checked by tracking the discount type. Where ‘F’ means festival and ‘N’ means Non- festival .The Cal_price() will calculate the Discount Price and Net Price on the basis of the following table.

Public members Constructor to initialize the string elements with “NULL”,

numeric elements with 0 and character elements with ‘N’Accept() - Ask the store manager to enter Product name, list Price and discount type . The function will invoke Cal_price() to calculate Discount Price and Net Price .ShowBill() - To generate the bill to the customer with all the details of his/her purchase along with the bill amount including discount price and net price.

x. Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the savers. Each member of the class contains a private data member savingsBalance indicating the amount the saver currently has on deposit. Provide member function calculateMonthlyInterest that calculates the monthly interest by multiplying the balance by

Product Name List Price(Rs.)Washing Machine 12000Colour Television 17000Refrigerator 18000OTG 8000CD Player 4500

Page 4:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value.

Write a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00, respectively. Set the annualInterestRate to 3 percent. Then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 4 percent, calculate the next month's interest and print the new balances for each of the savers.

xi. Create a class ANGLE that includes three member variables: an int for degrees, a float for minutes, and a char for the direction letter(N, S, E, or W). This class can hold either a latitude variable or a longitude variable. Member functions:

to obtain an angle value (in degrees and minutes) and a direction from the user, and a second to display the angle value in 179859.9’E format. Also write a three–argument constructor. Write a main() program that displays an angle initialized with the constructor, and then, within a loop, allows the user to input any angle value, and then displays the value.You can use the hex character

constant ‘\xF8’ which usually prints a degree (°) symbol.Q 3.(a) Write a function SWAP2BEST(int ARR[ ],int Size) in C++ to modify the content of the array in such a way that the elements,which are multiples of 10 swap with the value present in the very next position in the array. For Example: If the content of array ARR is 90 , 56 , 45, 20 ,34 , 54 The content of array ARR should become 56 , 90 , 45 ,34 ,20 ,54 (b) Write a function in C++ to perform sort operation in an array containing Players information (represented with the help of an array of structure PLAYER) and put players in alphabetical order of names. struct PLAYER

{ long PID ; // Player ID char Pname [20] ; // Player Name};

(c) i. Write a function TRANSFORM ( int A[ ][3],int N,int M) in C++ to swap the elements of first and last row.

ii. Write a function TRANSFORM(int A[4][3]) in C++ to swap the elements of the first column with the corresponding elements of last column of array A.

(d) Write a user defined function Upper_half() which takes a two dimensional array A, with size N rows and N columns as arguments and point the upper half(diagonally) of the array. eg. (2

2 3 1 5 0 2 3 1 5 07 1 5 3 1 1 5 3 1

If A is 2 5 7 8 1 The Output Will be 7 8 10 1 5 0 1 0 13 4 9 1 5 5

(e) Write the function Add Array() in C++ to club the values( ascending order) of two arrays.(f) Write the definition for a function Sumseries ( ) in c++ with two Arguments/parameters double x and int n .The function should return a value of type double and it should perform sum of the following series.

x- x2 /3!+ x3 /5!- x4/ 7!+x5/9!-……..n.

Page 5:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

(g) Define a function SwapArray ( int [ ], int), that would accept a one dimensional integer array Numbers and its size N. The function should rearrange the array in such a way that the values of alternate locations of the array are exchanged (assume the size of the array to be even)

If the array initially contains : ( 2,5,9,14,17,8,19,16) Then after rearranged the array should contain: (5, 2, 14, 9, 8, 17, 16, 19)(h)Write a function in C++ which accepts an integer array and its size as arguments and assigns the elements into a two dimensional array of integers in the following format.

If the array is1,2,3 The resultant 2D array should be 1 2 31 2 01 0 0

(i) Write a function Sortscore in c ++ to sort an array of structure “Examinee” in descending order of Score using Bubble Sort. Assume the following definition of structure.

struct Examinee{ long rollno;

char name[20];float score;

};(j)Write a function TRANSFER(int A[], int B[], int Size) in C++ to copy the elements of array A into array B in such a way that all the negative elements of A appear in the beginning of B, followed by all the positive elements, followed by all the zeroes maintaining their respective orders in array A. For example:

If the contents of array A are:7, -23, 3, 0, -8,-3,4, 0The contents of array B should be-23 , -8, -3, 7, 3, 4, 0, 0

(k) Write a function SWAP2BEST(int ARR[ ],int Size) in C++ to modify the content of the array in such a way that the elements, which are multiples of 10 swap with the value present in the very next position in the array.

For Example: If the content of array ARR is 90 , 56 , 45, 20 ,34 , 54

The content of array ARR should become56 90 , 45 ,34 ,20 ,54

(l) Write a function in C++ which accepts an integer array and its size as arguments/parameters and exchanges the values of first half side elements with the second half elements of the array. Example:

If an array of ten elements has initial content as : 8, 10, 1, 3, 17, 90, 13, 60, 16, 5

The function should rearrange the array as: 90, 13, 60, 16, 5, 8, 10, 1, 3, 17.

(m) Write definition for a function SUMSEQUENCE() in C++ with two arguments/parameters – double x and int n. The function should return a value of type double and it should perform sum of the following series :

1/x – 3!/x2 + 5!/x3 – 7!/x4 + 9!/x5 - …………………. Up to n terms.

(Note : The symbol ! represents Factorial of a number i.e. 5! = 5*4*3*2*1)

(n) Write a C++ function that converts a decimal number to the hexadecimal number.

Page 6:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

(o)Write a C++ function SUMFUN() having parameters X (of type double) and n (of type integer) with a result type as double to find the sum of the series given below :

X + X2/3! + X3/5! + ………….+ Xn/(2N-1)!

(p)Assume an array E containing elements of structure Student is required to be arranged in descending order of the marks. Write a C++ function to arrange the same with the help of bubble sort the array and its size is required to be passed as parameters to the function. Definition of structure Student is as follows:

struct Student{ int Rollno;

char Name[25];float Marks;

};

(q) Write a user defined function in C++ to display the multiplication of column elements of a 2 dimensional array MATRIX [6][6] containing integers.

(r) Write a user defined function in C++ to display those elements of 2 dimensional array T[4][4] which are divisible by 100.

(s) Write a function in C+ + to find sum of rows from a two dimensional array.

Subject: Computer Science Class -XII

-----------------------------------------------------------------------------------------------------------------------AQ1.

(a) What is the function overloading? Explain example the term “default arguments”. ? Give an example in C++ to illustrate both types. 2

(b) Write the names of the header files to which the following belong:void main(){ randomize();int val= random(5);char name =’F’;for (char ch= ‘A’; ch<=name; ch=ch+2)cout<<setw(4)<<name<<”\t”<<val;}

(c ). Rewrite the given snippet after removing the syntactical error(s), if any. Underline each correction 2 include<iostream.h>

#define MAX 10void main(){ int AY[MAX]=(5,10,15,20,25);

const int loop 5;for[int m=0; m<loop,m++]switch(m):

{ case 0:case 4: cout<<AY[m]*5case 2:

Page 7:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

case 1 cout>>AY[m]>>endl;}

} (d) Find the output of the following program (Assuming that all required header files are included) 2

#include <iostream.h>struct School{ int year;

float topper;};void change( School *s, int x=15)

{ s->topper=(s->topper+25)-x;s->year++;

}void main(){School arr[]={{2012,170},{2012,75})School *pointer=arr;Change(pointer,150);Cout<<arr[0].year<<”- ”<<arr[0].topper<<endl;Change(++pointer);Cout<<pointer->year<<”- ”<<pointer->topper<<endl;}

(e) Find the output of the following program 3#include <iostream.h>#include <string.h>#include <ctype.h>void swap(char &c1,char &c2){char temp;temp=c1;c1=c2;c2=temp;}void update(char *str){int k,j,l1,l2;l1 = (strlen(str)+1)/2;l2=strlen(str);for(k=0,j=l1-1;k<j;k++,j--){ if(islower(str[k]))

swap(str[k],str[j]);}for(k=l1,j=l2-1;k<j;k++,j--){ if(isupper(str[k]))

swap(str[k],str[j]);}}void main(){char data[100]={"bEsTOfLUck"};cout<<"Original Data : "<<data<<endl;update(data);

Page 8:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

cout<<"Updated Data "<<data;}

f) In the following program, find the correct possible output(s) from the options and justify your answer: 3#include <iostream.h>#include <stdlib.h>#include <string.h>struct card { char suit[10];

int digit; };card cards[52]; // Allocate Memoryvoid createdeck(){char temp[][10] = {"Clubs","Spades","Diamonds","Hearts"};int i,m=0,cnt=1;for(i=1;i<=52;i++){ strcpy(cards[i].suit,temp[m]);

cards[i].digit=cnt;cnt++;if(i % 13 == 0){ m++; cnt=1; }

}}card drawcard(int num){int rndnum;randomize();rndnum = random(num)+1;return (cards[rndnum]);}void main(){ createdeck();

card c;c = drawcard(39);if(c.digit > 10 || c.digit == 1){ switch(c.digit)

{ case 11: cout<<"Jack of "; break;case 12: cout<<"Queen of "; break;case 13: cout<<"King of "; break;case 1: cout<<"Ace of ";

}}elsecout<<c.digit<<" of ";cout<<c.suit;}

Outputs:i) Kind of Spades ii) Ace of Clubsiii) Ace of Diamondiv) Queen of Hearts

AQ2 (a) What is the Data Abstraction and Data Hiding Concept ? 2

(b) Define a class Departmental with the following specification : 4

Page 9:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

private data members Prod_name string (45 charactes) [ Product name] Listprice long Dis_Price long [ Discount Price] Net long [Net Price ] Dis_type char(F or N) [ Discount type]

Cal_price() – The store gives a 10% discount on every product it sells. However at the time of festival season the store gives 7% festival discount after 10% regular discount. The discount type can be checked by tracking the discount type. Where ‘F’ means festival and ‘N’ means Non- festival .The Cal_price() will calculate the Discount Price and Net Price on the basis of the following table.

public members

Constructor to initialize the string elements with “NULL”, numeric elements with 0 and character elements with ‘N’ Accept() - Ask the store manager to enter Product name, list Price and discount type . The function will invoke Cal_price() to calculate Discount Price and Net Price .

ShowBill() - To generate the bill to the customer with all the details of his/her purchase along with the bill amount including discount price and net price.

(c) Answer the questions (i) and (ii) after going through the following program: 2

class Match{ int Time;

public:Match() //Function 1{Time=0;cout<<”Match commences”<<end1;

}void Details() //Function 2

{cout<<”Inter Section Basketball Match”<<end1;}

Match(int Duration) //Function 3{Time=Duration;cout<<”Another Match begins now”<<end1;

}Match(Match &M) //Function 4

{Time=M.Duration;cout<<”Like Previous Match ”<<end1;

}};

i) Which category of constructor - Function 4 belongs to and what is the purpose of using it?ii) Write statements that would call the member Functions 1 and 3

Product Name List Price(Rs.)

Washing Machine 12000

Colour Television 17000

Refrigerator 18000

OTG 8000

CD Player 4500

Page 10:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

BQ1.(a) Give the difference between the type casting and automatic type conversion .Also, give a suitable C++ code to illustrate both. 2(b) Which C++ header file(s) will be essentially required to be included to run /execute the following C++ source code (Note : Do not include any header file, which is/are not required): 1void main(){char Text[ ]="SomeThing";cout<<”Remaining SMS Chars:”<<160-strlen(Text)<<endl;}(c) Rewrite the following program after removing the syntactical errors (if any).Underline each correction. 2 #include <iostream.h> class Book

{long Bid,Qty; public:

void Purchase(){cin>>Bid>>Qty;}void Sale{cout<<setw(5)<<Bid<<”Old:”<<Qty<<endl; }};

void main(){ Book B;

B.Purchase();B.Sale()Sale.B();Sale();

}(d). Find the output of the following program: 3

#include<iostream.h>#include<conio.h>#include<ctype.h>class Metro{ int Mno,TripNo,PassengerCount; public: Metro(int Tmno=1) { Mno=Tmno; TripNo=0; PassengerCount=0; } void Trip(int PC=20) { TripNo++; PassengerCount+=PC;} void StatusShow() { cout<<Mno<<":"<<TripNo<<":"<<PassengerCount<<endl;} } ;void main(){ Metro M(5),T; M.Trip();

Page 11:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

T.Trip(50); M.StatusShow(); M.Trip(30); T.StatusShow(); M.StatusShow();}(e). Find the output of the following program: 2#include<iostream.h>#include<conio.h>#include<ctype.h>typedef char Str80[80];void main(){clrscr(); char *Notes; Str80 Str="vR2GooD"; int L=6; Notes=Str; while(L>=3) { Str[L]=(isupper(Str[L])?tolower(Str[L]):toupper(Str[L])) ; cout<<Notes<<endl; L--; cout<<L; Notes++; cout<<Notes; }}(f). Observe the following program and find out, which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Chance? 2#include<iostream.h>

#include<stdlib.h>void main( ) { randomize( ); int Arr[ ]={9,6},N;int Chance=random(2)+10; for(int I=0; I<2;I++) { N=random(2); cout<<Arr[N]+Chance<<”*”; }

}(i) 9*6*(ii) 19*17*(iii) 19*16*(iv) 20*16*

Page 12:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

BQ2

(a) What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable C++ code to illustrate both. (b) Answer the questions (i) and (ii) after going through the following class: 2

class Travel { int PlaceCode ; char Place[20];float Charges;

public: Travel( ) //Function 1{ PlaceCode=1; strcpy (Place,”DELHI”); Charges=1000;} void TravelPlan(float C) //Function 2{ cout<<PlaceCode<<”:”<<Place<<”:”<<Charges<<endl;}~Travel( ) //Function 3{ Cout<<”Travel Plan Cancelled”<<endl;}Travel (int PC,char P[ ],float C) //Function 4{ PlaceCode=PC; strcpy (Place,P);Charges=C;}

};i) In Object Oriented Programming, what are Function 1 and Function 4 combined together referred as?ii) In Object Oriented Programming, which concept is illustrated by Function 3? When is this function called/invoked? 2(c) Define a class SUPPLY in C++ with following description: 4Private Members:• Code of type integer• FoodName of type string• Sticker of type string• FoodType of type string• A member function GetType() to assign the following values for FoodType as per the given Sticker:

Sticker FoodTypeGREEN Vegetarian

YELLOW Contains Egg RED Non-Vegetarian

Public Members:• A function FoodIn ( ) to allow user to enter values for Code,FoodName,Sticker and call function GetType ( ) to assign respective FoodType.• A function FoodOut ( ) to allow user to view the content of all the data members..

CQ1.(a) Write the prototype of a function named Area, which take a float as value parameter and return a double type value. The parameter should have a default value 5.2. (2)(b)Write the names of the header files which are not necessary to execute the following C++ code (1)#include<iostream.h>#include<stdio.h>#include<string.h>

Page 13:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

#include<ctype.h>#include<math.h>void main(){ char c, String[ ] = " System Design ";for(int i=0; String[i]!='\0' ;i++)if(isdigit(String[i])cout<<endl;else{c=toupper(String[i]);cout<<c;}}(c) Hussain has just started working as programmer in the WORLD SOFTWARE company. In the company, he has got his first assignment to develop a small C++ module to find the smallest number out of a given set of numbers stored in a one dimensional array. Somehow he has committed a few logical mistakes while writing this code and so he is not getting the desired result from the code. Find out the mistakes and correct this C++ code so that it provides the desired result (do not add any new statement in the code). Underline each correction made: (2)

int SMALLFIND(int ARR,int Size) // Statement 1{int SMALL=ARR[1]; //Statement 2for (int C=2;C<Size;C++) //Statement 3if (ARR[C]>SMALL) //Statement 4ARR[C]=SMALL; //Statement 5return SMALL; //Statement 6

} (d) Find output of the following program segment: (2)

int A[][4] = {{11,21,32,43}, {20,30,40,50}};for (int i = 1; i<2; i++)for (int j = 0; j<4; j++)

cout<<A[i][j]<<"*\n"; (e) Find output of the following program segment: (3)

int a = 5;void demo(int x, int y, int &z){ a += x+y;

z = a+y;y += x;cout<<x<<'*'<<y<<'*'<<z<<endl;

}void main(){ int a = 3, b = 4;

demo(::a,a,b);demo(::a,a,b);

}(f) Write a function to accept three integers and return the smallest of three numbers(use conditional operator)

(2)CQ2. (a) What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable C++ code to illustrate both. (2)(b) What is constructor overloading? Give an example to illustrate the same. (2)(c) Define a class Train in C++ with following description: (4)Private Members

Page 14:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

src of type stringTnm of type stringdest of type stringcharges of float• A member function Getdata to assign the following values for Charges

dest charages Mumbai 1000,Chennai 2000 Kolkatta 2500.

Public members A parameterize constructor to initialize the data members. A function InputData() to allow the user to enter the values A function displaydata() to display all and call getdata function

d) Consider the following class counter: (4)class counter{ protected :

unsigned int count;public :counter()

{ count = 0; }void inc_count(){ count++; }int get_count(){ return count; }

};Write code in C++ to publically derive another class new_counter from class counter.Class new_counter should have the following additional function members in the public visibility mode:(i) A parameterized constructor to initialize the value of count to the value of parameter.(iii) Reset() to set the value of data member count to 0.(ii) dec_count() to decrease the value of data member count by 1.

DQ1. a. What is Inheritance? Give an example. 1b. Write the names of the header files to which the following belong: 2

i) sqrt() ii) isalpha iii) puts() iv)strcpy()c. Rewrite the corrected code for the following program .Underline each correction (if any) 2 # include<iostream.h>

Structure Swimmingclub{ int memnumber;

char memname[20];char memtype[ ] = “LIG”;

};void main( ){ Swimmingclub per1,per2;cin>>”Member number”;cin >>memnumber.per1:”;cout<< “ Member name:”;cin>>per1. Member name;per1.memtype=”HIG”;per2=per1;cin>> “Member number: “<<per2.memnumber:”;cin>>”Member name:”<<”per2.memname;

Page 15:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

cin>>” Member number :”<< per2.memtype:”;}d. What will be the output of the following program: 1

# include <iostream.h># include<ctype.h># include<conio.h># include< string.h>void Newtext(char String[ ], int &Position)

{ char *pointer = String;int Length =strlen(String);for(; Position<Length-2;Position+=2;{ *(Pointer Position)=toupper(*(Pointer Position));}

}e. What will be the output of the following program: 1

#include<iostream.h>void main( ){ clrscr( );

int v1=5, v2=10; for(int x =1; x<=2; x++) { cout<<” ++ v1<<”\t”<<v2 -- <<endl;

cout<< “ - - v2<<”\t” <<v1++<<endl;}

}

f. Write the definition for a function Sumseries ( ) in c++ with two 4 Arguments/parameters double x and int n .The function should return a value of type double and it should perform sum of the following series.

x- x2 /3!+ x3 /5!- x4/ 71+x5/9!-……..n.DQ2. a. Given the following C++ code answer the questions (i) to (ii). 2class TestMeOut{ Public:

~ TestMeOut( ) //Function 1{ cout<<” Leaving the examination hall:”<<endl;}TestMeOut () // Function2

cout<< appearing for the examination :”<<endl;}void MyWork( ) // Function3{ cout<,” Attempting the Question:”; }

};i. In object Oriented programming what is Function 1 referred as and when does it get invoked / called?ii. In OOP’s what is Function 2 referred as and when does it get invoked / called?b. Define a class TravelPlan in C++ with the following descriptions: 4Private Members:PlanCode of type longPlace of type character array (string)Number of travellers of type integerNumber_of_buses of type integer Public Members:A constructor to assign initial values of Plan Code as 1001, Place as “Agra”,Number_of_travellers as 5, Number_of_buses as 1A function NewPlan( ) which allows user to enter PlanCode, Place andNumber_of_travellers. Also, assign the value of Number_of_buses as per the

Page 16:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

Following conditions:Number_of_travellers Number_of_busesLess than 20 1Equal to or more than 20 and less than 40 2Equal to 40 or more than 40 3A function ShowPlan ( ) to display the content of all the data members on screen.c.Define the term Data Hiding in the context of Object Oriented Programming. Give a suitable example using a C++ code to illustrate the same. 2EQ1. a) Write short notes on typedef and #define. 2b) Give the Header files to run the following code. 1void main(){cout<<”Click 2 Win”;cout<<setw(9)<<”hello”;}c) Find the Errors in the following program code and rewrite the correct code. 2Include<iostream.h>class bank{int acno;char nm[20];float balamt;void bank(){ }void input(){cout<<”Enter the acno “;cin>>acno;}}void Main(){bank b;input.b();}d) Find the output of the following program: 3 #include<iostream.h> void main() { int X[]={30,35,50,66,110}; int *p=X; while(*p<110) { if(*p%3!=0) *p=*p+1; else *p=*p+2;p++;}for(int I=4;I>=1;i--){cout<<X[I]<<”*”;if(I%3==0) cout<<endl;

Page 17:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

}cout<<X[0]*3<<endl; }e) Find the output of the following program 2

#include<iostream.h> #include <ctype.h> void CangeIt (char Text[], char C) {for (int K=0;Text [K]!='\0' ;K++) { if (Text[K] >='F' && Text[K] <='L')

Text[K]=tolower(Text[K]); else if (Text[K]=='E' || Text[K]=='e')

Text[K]=C; else if (K%2==0)

Text[K]=toupper(Text[K]);else

Text[K]=Text[K-1];} }

void main( ) { char oldText[ ]= "Click@CAreeR2017" ;

ChangeIt (oldText,'%'); cout <<"New TEXT:"<<oldText<<endl; }

f) The following code is from a game .which generates a set of 4random numbers :identify the correct option(s)out of the four choices given below as the possible set of such numbers generated from the program code so that he wins the game. Justify your answer. 2

#include <iostream.h> #include <stdio.h> const int LOW = 15 ; void main( ) { randomize( ) ;

int POINT =5, Number ; for (int I = 1 ; I <= 4 ; I ++) { Number = LOW + random(POINT) ;

cout << Number << “:” ; POINT-- ;

} }

i) 19:16:15:18: (ii) 14:18: 15:16: (iii) 19:16:14:18: (iv) 19:16:15:16EQ2a) What is static Data member Explain with an eg. b) Answer the questions (i) and (ii) after going through the following class : 2

class TEST { int Regno, Max, Min, Score ; public :

TEST( ){ //Function 1 Regno = 101 ; Max=100; Min = 40 ; score = 75 ;

}TEST(int Pregno, int Pscore) //Function 2{Regno = Pregno ;

Max = 100 ; Min = 40 ; Score = Pscore ;

}~TEST( ) //Function 3

Page 18:  · Web viewWrite a driver program to test class SavingsAccount. Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of 2000.00 and 3000.00,

{cout << “TEST Over” << endl ;}void Display( ) //Function 4{

cout << Regno << “:” <<Max<< “:” << Min << endl ; cout << “[Score]” << Score << endl; } } ;

(i) What type of function 4 is and how it will be invoked(ii) What is Function 3 specifically referred as ? When do you think, Function 3 will be invoked/called?

Solve all these questions in Homework note book submit on the reopening day to get full mark.