CLASS XII ASSIGNMENT

REV. TOUR OF CLASS XI

Q1. (a) What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to illustrate both

(b) Write the names of the header files to which the following belong:

(i) frexp() (ii) isalnum()

(c) Rewrite the following program after removing the syntactical errors (if any). Underline each correction #include <iostream.h>

struct Pixels

{ int Color,Style;}

void ShowPoint(Pixels P)

{ cout<P.Color,P.Style<endl;}

void main()

{

Pixels Point1=(5,3);

ShowPoint(Point1);

Pixels Point2=Point1;

Color.Point1+=2;

ShowPoint(Point2);

}

(d) Find the output of the following program:

#include <iostream.h>

void Changethecontent(int Arr[ ], int Count)

{

for (int C=1;C<Count;C++)

Arr[C-1]+=Arr[C];

}

void main()

{

int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};

Changethecontent(A,3);

Changethecontent(B,4);

Changethecontent(C,2);

for (int L=0;L<3;L++) cout<A[L]<'#';

cout<endl;

for (L=0;L<4;L++) cout<B[L] <'#';

cout<endl;

for (L=0;L<2;L++) cout<C[L] <'#';

}

(e) Find the output of the following program:

#include <iostream.h>

struct Game

{

char Magic[20];int Score;

};

void main()

{

Game M={"Tiger",500};

char Choice[20];

strcpy(Choice,M.Magic);

Choice[4]='P';

Choice[2]='L';

M.Score+=50;

cout<M.Magic<M.Score<endl;

Game N=M;

N.Magic[0]='A'; N.Magic[3]='J';

N.Score-=120;

cout<N.Magic<N.Score<endl;

}

(f) In the following program, if the value of N given by the user is 20, what maximum

and minimum values the program could possibly display?

#include <iostream.h>

#include <stdlib.h>

void main()

{

int N,Guessnum;

randomize();

cin>N;

Guessnum=random(N-10)+10;

cout<Guessnum<endl;

}

Q2. (a) Rewrite the following program after removing all the syntactical errors (if any), underlining each
correction. :

include<iostream.h>
typedef char[40] string;
void main( )
{ string S=”Australia”;
L=strlen(S);
cout<”String “<S<’ has ’<L<”Characters”<endl;

}

(b) Go through the following c++ code, find out the correct possible output(s) from the suggested output options i) to iv). Also write the highest value which can be assigned to variable G :
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int G,H=5;
G=random(H)+30;
for(int i=35;i>G;i--)
cout<i<’$’;
cout<i;
}

1.  35$34$33$32$31$30$

2.  35$34$33$32$31

3.  30$31$32$33$34$35$36

4.  35$34$33$32$31$30

( c) Name the header file(s) that shall be needed for successful compilation of the following C++ code.

void main()

{

int a[10];

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

{

cin>a[i];

if(a[i]%2==0)

a[i]=pow(a[i],3);

else

a[i]=sqrt(a[i]);

if(a[i]>32767)

exit(0);

}

getch();

}

(d) Write the output of the following code:

# include<iostream.h>

# include<ctype.h>

void manipulate( char string[], int&len)

{

for(int i=0; string[i]!=’\0’;i++)

{

if (isupper(string[i]))

string[i]= string[i]-2; len++;

else

if (isupper(string[i]))

string[i]=string[i+2]; −−len;

else

string[i]=’@’;

}

}

void main( )

{ char word[]= “FuNUnliMiTEd!! “;

int length=strlen(word);

manipulate (word, length );

cout<”Word “<word<”@”<”Length”<length;

}

(e) Find the output

#include<iostream.h>

void in( int x, int y, int&z)

{ x+=y;

y--;

z*=(x-y);

}

void out( int z, int y, int&x)

{ x−= y;

y++;

z/=(x+y);

}

void main( )

{

int a= 20, b=30, c=10;

in (a, c, b);

cout<a<”#”<b<”#”<c<”#”<endl;

out (b, c, a);

cout<a<”@”<b<”@”<c<”@”<endl;

in (a, b, c);

cout<a<”$”<b<”$”<c<”$”<endl;

}

(f) Chose the correct alternative from the options (i)- (iv). Justify your answer.

#include<iostream.h>

#include<stdlib.h>

#define Getval (N) ((N%2 = =0)? N+1:N+2)

void main( )

{ randomize( );

intnum= random(3)+3;

for(int I= num ; I<=num+2 ;I++)

cout<Getval(I)<’@’;

}

Options:

a) 3@5@7@

b) 7@7@9@

c) 7@9@9@

d) 7@9@11@

(g) In the following program, find the correct possible output(s) from the options: #include<iostream.h>

#include<stdlib.h>

void main( )

{

randomize( );

int p=99,q=999;

int x=random(3)+4;

int y=random(2)+2;

for(int i=0;i<x;i++)

cout<’#’;

cout<p<’-’;

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

cout<’@’;

cout<q<endl;

}

1.  ##99-@999

2.  ##99-@@999

3.  ######99-@@999

4.  ####99-@@@999

LESSON BREAKUP

S.no. / Program / Submission
1. / Write a menu-driven program in C++ to calculate the volume of following shapes-
1.  Volume of a cube
2.  Volume of a box
3.  Volume of a sphere.
4.  Quit
Make this program with the help of a class shape with following-
Member data:
p1 (type float)
p2 (type float)
p3 (type float)
volume (type float)
Member Functions :
To input data members (Input as many as required)
To calculate volume of various shapes (must be overloaded)
To display the volume. / 3rd week of April
2. / Define a class TAXPAYER in C++ with following description :
Private members :
a.  Name of type string
b.  PanNo of type string
c.  Taxabincm (Taxable income) of type float
d.  TotTax of type double
e.  A 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 15
Public members :
Ø  A function to input data 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. / I week of May
3. / Define a class to represent batsmen in a cricket team. Include the following members:
Data members :
First name
Last name
Runs made
Number of fours
Number of sixes
Member Functions :
To assign the initial values
To update runs made
(It should simultaneously update fours and sixes, if required)
To display the batsman’s information.
Test this class in main() function. Make 11 objects to represent a team.
Make a menu with following options.
1.  Assign the basic values to all of the team members.
2.  Update the information of any batsman on the basis of his first name
3.  Display the information of any batsman on the basis of his first name
Quit / Last week of June
4. / Define a class named Publisher in C++ with the following descriptions :
Private members
Id long
title 40 char
author 40 char
price , stockqty double
stockvalue double
valcal() A function to find price*stockqty with double as return type
Public members
·  a constructor function to initialize price , stockqty and stockvalue as 0
·  Enter() function to input the idnumber , title and author
·  Takestock() function to increment stockqty by N(where N is passed as argument to this function) and call the function valcal() to update the stockvalue().
·  sale() function to decrease the stockqty by N (where N is sale
quantity to this function as argument) and also call the function
valcal() to update the stockvalue
·  outdata() function to display all the data members on the screen.
Test this class in main() function. / I week of july
5. / Define a class Employee in C++ with the following specification:
Private Members:
·  ename an array of char of size[50] ( represent employee name)
·  deptname an array of char of size[20] ( represent department name)
·  salary integer ( represent total salary of an employee)
·  bonus float
·  CalBonus() This function calculate the total bonus given to an employee according to following conditions
Deptname Bonus
Accounts 4 % of salary
HR 5% of salary
IT 2% of salary
Sales 3% of salary
Marketing 4% of salary
Public Members:
·  Constructor to initialise ename and deptname to NULL and salary and bonus to 0.
·  A function read_info to allow user to enter values for ename, deptname,salary & Call function CalBonus() to calculate the bonus of an employee.
·  A Function disp_info() to allow user to view the content of all the data members.
Test above-mentioned class in main() function. / 2nd week of july
6. / Imagine a publishing company that markets both books and audio cassette versions of its works. Create a class Publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes : book, which adds a page count (type int); and tape, which adds a playing time in minutes (type float). Each of these three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display its data.
Write a main() program to test the book and tape classes by creating instances of them asking the user to fill in their data with getdata(), and then displaying the data with putdata().
Test classes book and tape from main function. Implement the concept of member function over-riding. / 3rd week of july
Write a menu-driven program in C++ with following options-
1.  Creation of a text file (file must be created, character by character until a particular character is typed , like as you type ‘#’ the file creation task gets stopped)
2.  Reading of a created text file. (To display the contents of a text file)
3.  Quit. / I week of August
Write a menu-driven program in C++ with following options-
1.  Creation of a text file (say file is mixed.txt, it contains alphabets, digits or special characters)
2.  Make separate files (This option creates three files- alpha.txt (contains alphabets only), digit.txt (contains digits only) and special.txt (contains special characters only) taking data from mixed.txt)
3.  Display a file (This option displays the contents of a particular file out of above-mentioned four files, by asking its name, if not found reports “file not found”)
4.  Quit / II week of August
Write a menu-driven program in C++ with following options-
1.  To add records (Name, Rollno, Marks ) of students (Add records till the user wants ‘yes’)
2.  Display all the records
3.  Display a particular record on the basis of Roll No.
4. Quit / III week of August
Write a menu-driven program in C++ with following options-
1.  To add records (Name, Rollno, Marks ) of students (Add records till the user wants ‘yes’)
2.  Display all the records
3.  Display a particular record on the basis of Roll No.
4. Quit
Write a program in C++ with the help of following class employee –
Member Data :
Employee name
Employee code
Basic Salary
Da
Hra
Total salary
Member Functions:
1. To input employee detail (name, code and basic)
2. To calculate following
Code / Da / Hra
1 / 50% of basic / 30% of basic
2 / 40% of basic / 25% of basic
Any other / 30% of basic / 20% of basic
Total Salary=Basic + Da + Hra
This function must be a private function and must be called from input detail function
3. A function which returns the address of that object which has got higher basic salary
(This function compares calling object and passing object)
4. To display the detail of the student
In main() function make 10 objects of employee. Input and calculate detail of every employee .
Finally display the detail of that employee who draws the highest salary. / IV week of august
Write a program in C++ with the help of class array_search with following members-
Member data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions-
1.  To input n, and n number of elements
2.  Linear serch
3.  Binary search (If array is in ascending order)
4.  To display n elements of the array
Make a menu in C++ with following options-
1.  Array Input
2.  Linear Search
3.  Binary Search
4.  Array display
6. Quit / I week of Sept.
Write a program in C++ with the help of class array_update with following members-
Member data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions-
1. To input n, and n number of elements
2. To insert an item in the array if array is in ascending order
4.  To delete an item from the array
5.  To display n elements of the array
Make a menu in C++ with following options-
1.  Array Input
2.  Insertion
3.  Deletion
4.  Array display
6. Quit / 2nd week of September
Write a program in C++ with the help of class array_sort with following members-
Member data :
An array ar of integer with 100 elements
No .of elements actually used by user (int n)
Member Functions-
1.  To input n, and n number of elements
2.  Selection sort
3.  Bubble sort
4.  Insertion sort
5.  To display n elements of the array
Make a menu in C++ with following options-
1. Array Input
2. Selection sort
3. Bubble sort
4. Insertion sort
5. Array display
6. Quit / 3rd week of September
Write a program in C++ with the help of class array_merge with following members-
Member data :
An array a of integer with 100 elements
No .of elements actually used by user in array a (int l)
An array b of integer with 100 elements
No .of elements actually used by user in array b (int m)
An array c of integer with 200 elements
No .of elements actually used by user in array c (int n)
Member Functions-
1.  To input array a and b with size l, m respectively
2.  merge1(), it merges array a and b to form c, if a and b are sorted in ascending and descending order respectively
3.  merge2(), it merges array a and b to form c, if a and b are sorted in descending and ascending order respectively
4. merge3(), it merges array a and b to form c, if a and b are sorted in ascending order
5. merge4(), it merges array a and b to form c, if a and b are sorted in descending order
(Note :Array c is required in ascending order.)
6.  display(), To display all the arrays a, b and c.
Make a menu in C++ with following options-
1.  To input array a, b
2.  To merge array a and b to form c, if a and b are sorted in ascending and descending order respectively
3.  To merge array a and b to form c, if a and b are sorted in descending and ascending order respectively
4.  To merge array a and b to form c, if a and b are sorted in ascending order
5.  To merge array a and b to form c, if a and b are sorted in descending order
6.  To display all the arrays.
7. Quit / 4th week of September
Write a program in C++ with the help of class linked_list with following members-
(Nodes of the linked list are created by self-referential structure node-
struct node
{
int info;
node *next;
}; )
Member data :
A pointer start which keeps the address of first node.
Member Functions-
1.  A constructor which keeps NULL in start.
2.  To add a node in a linked list
3.  For traversal (Display info. of each node)
4.  To search a particular node, on the basis of information of nodes given.