Assignment Class

XII Computer Science

Q1. 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.

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

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.

Q2. 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.

Q3. Define a class RESORT with the following specifications.

Private members:

Data members : roomno- int, name- string, charges- float, days- int, amount- float.

Member function: compute( ) - To calculate and return amount as days * charges

and if the value of days * charges is more than 2100 then as 1.5 * days * charges.

Public members:

Member Functions: enterdetails ( )– to input data and invoke compute( ) function.

display ( ) – to display the details of the customer

Q4. Define a class T20 in C++ with the following specifications

Private members :

Target_runs of type integer

Overs of type integer

Extra_time of type integer

Penalty_runs of type integer

CALPENALTY( ) a member function to calculate penalty runs as follows :

If Extra_time<=10 then 5 runs should be added to Target_runs

If Extra_time>10 and <=20 then 10 runs should be added to Target_runs

Otherwise 20 runs should be added to Target_runs

Public members :

INT20( ) – to input data & call CALPENALTY( ) function

DISPT20( ) – to display the details of the T20 type

Q5.Define a class Garments in C++ with the following descriptions:

Private Members

GCode of type string

GType of type string

GSize of type string

GFabric of type string

GPrice of type float

A function Assign ( ) which calculates and assigns the value of GPrice as follows:

For the value of GFabric ‘COTTON”,

GType GPrice

TROUSER 3000

SHIRT 2000

For the value of GFabric other than “COTTON” the above mentioned GPrice gets reduced by 25%

Public Members

A constructor to assign initial values of GCode,GType and GFabric with the word “NOT ALLOTED” and GSize and GPrice with 0.

A function Input ( ) to input the values of the data members GCode,GType, GSize and GFabric and invoke the Assign ( ) function.

A function Display ( ) which displays the content of all the data members for a Garment.

CONSTRUCTORS AND DESTRUCTORS

Q1.(a) Answer the questions(i) and (ii) after going through the following program:

class Match

{ int Time;

public:

Match( ) //Function 1

{ Time = 0;

cout < “Match commences” <endl;

}

void Details( ) //Function 2

{

cout < “Inter Section Baketball Match”< endl;

}

Match (int Duration ) //Function 3

{

Time = Duration;

cout <”Another Match begins now”< endl;

}

Match (Match &M) //Function 4

{

Time = M.Duration;

cout <”Like Previous Match” <endl;

} };

(i)  Which category of constructor – Function 4 belongs to what is the purpose of using it?

(ii)  Write statements that would call the member Function1 and 2? Also write diff. between them.

Q2. (a) Answer the questions (i) and (ii) after going through the following class:

class Travel

{ int days;

public:

Travel ( ) // Function 1

{

Days = 50; cout < “ Journey starts now” < endl;

}

void sightseeing( ) // Function 2

{

cout < “ Sightseeing in the journey starts” < endl;

}

Travel (int Duration) // Function 3

{

Days = Duration; cout < “ Journey starts now” < endl;

}

~ Travel ( ) // Function 4

{

cout < “ Happy journey” < endl;

} };

(1)  In Object Oriented Programming, what is Function 4 referred as and when does it get invoked/ called?

(2) In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3 together? Write an example illustrating the calls for these functions.

Q3. Distinguish between the following two statements:

time T1(13, 10, 25); time T1=time(13, 10, 25)

Q4.Consider the following class:

class Interview

{ int month;

public:

Interview(int y) // function 1

{

month=y;

}

interview (interview &m); // function 2

};

(i)  Write the difference between function 1 and function 2.

(ii)  Complete the definition of function 2.

Q5. Answer the questions (i) and (ii) after going through the following class :

class ATTENDANCE

{ private:

char CL[20];

int absent,present;

public:

ATTENDANCE( ) //function 1

{ strcpy(CL,”Blank”);

present=0;

absent=0; }

void SHOW( ) //function 2

{ cout<CL<endl<present<absent<endl; }

ATTENDANCE(ATTENDANCE &a); // function 3

~ATTENDANCE( ){ } // function 4

};

i)  In OOP, when will function 1 & function 4 be called?

ii) Write the definition of function 3.

Q6. Define a class named Admission in C++ with following description?

Private members:

admno integer (Ranges 10-1500) name string of 20 characters

cls integer fees float

Public members:

A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0

Function getdata() to read the object of Admission type.

Function putdata() to print the details of object of admission type.

Function draw_nos() to generate the admission no. randomly to match with admno and display the detail of object.

Define a class Bank to represent the bank account of a customer with the following specification

Private Members:

-  Name of type character array(string) Account_no of type long

-  Type_of_account ( S for Saving Account, C for current Account) of type char

-  Balance of type float

Public Members:

A constructor to initialize data members as follows

-  Name NULL Account_no 100001

-  Type_of_account ‘S’ Balance 1000

A function NewAccount() to input the values of the data members Name, Account_no,

Type_of_account and Balance with following two conditions

·  Minimum Balance for Current account is Rs.3000

·  Minimum Balance for Saving account is Rs.1000

A function Deposit() to deposit money and update the Balance amount.

A function Withdrawal() to withdraw money. Money can be withdrawn if minimum

balance is as >=1000 for Saving account and >=3000 for Current account.

A function Display() which displays the contents of all the data members for a account.

Cscience_1 : Write a Program in C++ to add two distance type objects into third one. Class distance contains following components-

1.  feet (integer type)

2.  inches (integer type)

(Program must have following general functions-

1.  To input a distance type object.

2.  To add two distance type objects (Pass two distance type arguments and return a distance type object).

3.  To display distance type object.)

Cscience_2 : Define a class Employee in C++ with the following specification:

Private members

Id long

title 40 char

author 40 char

price , stockqty double

stockvalue double

valcal() A function to find stockvalue as 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 id , 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

Cscience_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

4.  Quit

Cscience_4 : Write a program in C++ with the help of following class student –

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.

Cscience_5 : 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.

Cscience_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.

Cscience_7 : 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.

Cscience_8 : 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

Cscience_9 : 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

Cscience_10 : 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 5 objects of employee. Input and calculate detail of every employee .

Finally display the detail of that employee who draws the highest salary.

Cscience_11: 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