Top Banner
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. 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 Product Name List Price(Rs.) Washing Machine 12000 Colour Television 17000 Refrigerator 18000 OTG 8000 CD Player 4500
36

 · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

Apr 03, 2018

Download

Documents

dinhdien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

Assignment ClassXII 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.

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 stringb. PanNo of type stringc. Taxabincm (Taxable income) of type floatd. TotTax of type doublee. 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 15Public 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:

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

Page 2:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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 integerOvers of type integerExtra_time of type integerPenalty_runs of type integerCALPENALTY( ) a member function to calculate penalty runs as follows :If Extra_time<=10 then 5 runs should be added to Target_runsIf Extra_time>10 and <=20 then 10 runs should be added to Target_runsOtherwise 20 runs should be added to Target_runs

Public members :INT20( ) – to input data & call CALPENALTY( ) functionDISPT20( ) – to display the details of the T20 type

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

GCode of type stringGType of type stringGSize of type stringGFabric of type stringGPrice of type float

A function Assign ( ) which calculates and assigns the value of GPrice as follows:For the value of GFabric ‘COTTON”,

GType GPriceTROUSER 3000SHIRT 2000

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

Public MembersA 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.

Page 3:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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;

Page 4:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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;

Page 5:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

}

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 characterscls integer fees floatPublic members:A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0Function 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

Page 6:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

Private Members:

- Name of type character array(string) Account_noof 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.

Page 7:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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

Page 8:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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 name3. Display the information of any batsman on the basis of his first name4. 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.

Page 9:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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 cube2. 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)

Page 10:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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. QuitCscience_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 records3. 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.

Page 11:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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

No .of elements actually used by user (int n)

Member Functions-

1. To input n, and n number of elements2. Linear serch3. 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 Search3. Binary Search4. Array display 6. Quit

Cscience_12: 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 array5. To display n elements of the array

Make a menu in C++ with following options-

1. Array Input 2. Insertion3. Deletion4. Array display 6. Quit

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

Page 12:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

1. To input n, and n number of elements2. Selection sort3. Bubble sort4. Insertion sort5. 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

Cscience_14: 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 respectively3. merge2(), it merges array a and b to form c, if a and b are sorted in descending and

ascending order respectively4. merge3(), it merges array a and b to form c, if a and b are sorted in ascending order5. 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 respectively3. To merge array a and b to form c, if a and b are sorted in descending and

ascending order respectively4. To merge array a and b to form c, if a and b are sorted in ascending order

Page 13:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

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

Cscience_15: 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 list3. For traversal (Display info. of each node)4. To search a particular node, on the basis of information of nodes given.

Make a menu in C++ with following options-

1. To create a linked list.2. For linked list traversal.3. To search a particular node4. Quit.

Cscience_16: Write a program in C++ with the help of class array_stack with following members-

Member data :

An array of integer ar[MAX]

(Where MAX is a globally-declared symbolic-constant (integer) with size according to the requirement of user)

top (It keeps the index of top most array element)

Member Functions-

1. A constructor that initialize –1 in top (Makes array_stack ready to push)2. To push an item in stack.3. To pop an item from stack4. To display the content of stack without popping

Make a menu in C++ with following options-

Page 14:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

1. A initialize the stack( top must be -1)

2. To push an item in stack.

3. To pop an item from stack

4. To display the content of stack without popping

5. Quit

Cscience_17: Write a program in C++ with the help of class linked_stack with following members-

(Nodes of the linked stack are created by self-referential structure node-

struct node

{

int info;

node *next;

}; )

Member data :

A pointer top which keeps the address of top-most node.

Member Functions-

1.A constructor that initialize NULL in top (Makes array_stack ready to push)

2. To push an item on stack.

3. To pop an item from stack

4. To display the content of stack without popping

Make a menu in C++ with following options-

1. A initialize the stack( top must be NULL)

2. To push an item in stack.

3. To pop an item from stack

4. To display the content of stack without popping

5. Quit

Cscience_18: Write a program in C++ with the help of class array_queue with following members-

Member data :

An array of integer ar[MAX]

(Where MAX is a globally-declared symbolic-constant (integer) with size according to the requirement of user)

Page 15:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

front and rear ( They keep the index of front-most and rear-most array element)

Member Functions-

1. A constructor that initialize –1 in front and rear (Makes array_queue ready for insertion)

2. To insert an item in queue.

3. To delete an item from queue

4. To display the content of queue without deletion.

Make a menu in C++ with following options-

1. To initialize the queue( front and rear must be -1)

2. To insert an item in queue

3. To delete an item from queue

4. To display the contents of queue without deletion

2. QuitCscience_19: Write a program in C++ with the help of class linked_queue with following members-

(Nodes of the linked queue are created by self-referential structure node-

struct node

{

int info;

node *next;

}; )

member Data :

front and rear ( They keep the memory address of front-most and rear-most linked queue)

Member Functions-

1. A constructor that initialize NULL in front and rear (Makes linked__queue ready for insertion)

2. To insert an item in queue.

3. To delete an item from queue

4. To display the content of queue without deletion.

Make a menu in C++ with following options-

Page 16:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

1. To initialize the queue( front and rear must be NULL)

2. To insert an item in queue

3. To delete an item from queue

4. To display the contents of queue without deletion

5. Quit

Cscience_20: Write a program in C++ with the help of class circular_array_queue with following members-

Member data :

An array of integer ar[MAX]

(Where MAX is a globally-declared symbolic-constant (integer) with size according to the requirement of user)

front and rear ( They keep the index of front-most and rear-most array element)

Member Functions-

1. A constructor that initialize –1 in front and rear (Makes circular_array_queue ready for insertion)

2. To insert an item in circular queue.

3. To delete an item from circular queue

4. To display the content of circular queue without deletion.

Make a menu in C++ with following options-

1. To initialize the queue( front and rear must be -1)

2. To insert an item in queue

3. To delete an item from queue

4. To display the contents of queue without deletion

5. Quit

Page 17:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

Cscience_21: Write SQL commands .

1. Consider the following tables EMPLOYEE and DESIG. write SQL commands

for the statements (i) to (v).

EMPLOYEE

W_ID FIRSTNAME LASTNAME CITY

102 SAM TONES PARIS

105 SARAH ACKERMAN NEW YORK

144 MANILA SENGUPTA NEW DELHI

DESIG

W_ID SALARY BENEFITS DESIGNATION

102 75000 15000 MANAGER

105 85000 25000 DIRECTOR

144 70000 15000 MANAGER

(i) Display FirstName and City of Employee having salary between 50,000 and 90,000

(ii) Display details of Employees who are from “PARIS” city.

(iii) Increase the benefits of employee having W_ID = 102 by 500.

(iv) Count number of employees whose name starts from character ‘S’.

(v) Display max. salary for managers.

2. . Consider the following tables FACULTY and COURSES. Write SQL commands for the statements (i) to (v).

FACULTY

F_ID Fname Lname Hire_date Salary

102 Amit Mishra 12-10-1998 12000

103 Nitin Vyas 24-12-1994 8000

104 Rakshit Soni 18-5-2001 14000

Page 18:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

COURSES

C_ID F_ID Cname Fees

C21 102 Grid Computing 40000

C22 106 System Design 16000

C23 104 Computer Security 8000

(i) To display details of those Faculties whose date of joining is before 31-12-2001.

(ii) To display the details of courses whose fees is in the range of 15000 to 50000

(both values included).

(iii) To increase the fees of System Design course by 500.

(iv) To display F_ID, Fname, Cname of those faculties who charged more than15000 as fees.

(v) Display different coursesname from courses.

3. Consider the following tables Item and Customer. Write SQL commands for the

statements (i) to (v)

TABLE: ITEM

I_ID ItemName Manufacturer Price

PC06 Personal Computer ABC 35000

LC05 Laptop ABC 55000

PC03 Personal Computer XYZ 32000

TABLE : CUSTOMER

Page 19:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

C_ID CustomerName City I_Id

01 N Roy Delhi LC03

06 H Singh Mumbai PC03

12 R Pandey Delhi PC06

(i) To display the details of those Customers whose City is Delhi

(ii) To display the details of Items whose Price is in the range of 35000 to 55000 (Both

values included)

(iii) To display the CustomerNarne, City from table Customer and ItemName and Price from table Item, with their corresponding matching I_Id

(iv) To increase the Price of all Items by 1000 in the table Item

(vi) Display no. of cities from table customer.

4. Write SQL commands for and write the outputs of SQL commands with the help of above shown table.Table : SUPPLIER

Numbers Name City Itemno SuppliedQty Rate

S001 Puneet Delhi 1008 100 40

S002 Pradeep Bangalore 1009 200 30

S003 Tanmay Delhi 1008 150 40

S004 Rohini Bombay 1005 190 20

S005 Tanya Bombay 1003 20 50

S006 Aditi Madras 1008 180 40

S007 Kush Delhi 1009 300 30

a) Display names of suppliers whose names start with the letter ‘T’.b) Display details of suppliers residing in Delhi.c) Display supplier name, item numbers, and supplied quantity for quantity > 150.d) Create a view with one of the columns as rate * 10.e) List the suppliers name in the descending order of supplied quantity.f) List the different cities contained in supplier table.g) Give the output of the following SQL commands on the basis of table supplier.

Page 20:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

h) SELECT MIN(Rate) FROM SUPPLIERi) SELECT COUNT(DISTINCT City) FROM SUPPLIERj) SELECT (Rate*SuppliedQty) FROM SUPPLIER WHERE SuppliedQty>200

Page 21:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

File Handling - Added on 29 Aug. 2013

Assignment ClassClass XII – COMPUTER SCIENCE

FILE HANDLING

Q1. Find the error and show how to correct it in each of the following:

i) The file “Tools.dat” should be opened to add data to the file without discarding the current data.

ofstream outTools(“Tools.dat”, ios::out);

b) Write a function to count the number of one character words, 3 character words and 6 character words from

a text file named “Sentence.txt”. The output format is

CHARACTERS NO OF WORDS

ONE 4

TWO 2

THREE NIL

c) A binary file “class.dat” contains records of students of a class with name, and marks in three subjects. Write an UDF to display the student name and result (pass/fail). The passing criteria is the sum of three subject marks greater than or equal to 150.

Q2. (a) What is the difference between put() and write()?

(b) Distinguish between ios :: out and ios :: app.

(c) Name the stream classes supported by C++ for file input and output.

(d) Differential between getline() and get() function

(e) Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement2 using seekp( ) and seekg( ) functions for performing the required task.

#include <fstream.h>

class Item

{

int Imno; char Item[20];

public:

Page 22:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

//Function to search and display the content from a particular record number

void Search (int) ;

//Function to modify the content of a particular record number

void Modify(int);

};

void Item :: Search (int RecNo)

{

fstream File;

File.Open(“STOCK.DAT” , ios :: binary | ios :: in);

__________________________ //Statement 1

File.read((char*)this , sizeof(Item));

Cout <<Ino <<” = = >” << Item << endl;

File.close ( );

}

void Item :: Modify (int RecNo)

{

fstream File;

File.open (“STOCK.DAT”, ios ::binary | ios :: in | ios :: out);

cin>> Ino;

cin.getline(Itm,20 );

_________________________ //Statement 2

File.write ((char*) this sizeof(Item ));

File.close ( );

}

(b) Write a function in C++ to count the number of lines present in a text file “STORY.TXT”.

(c) Write a function in C++ to search for BookNo from a binary file “BOOK.DAT”, assuming the binary file is contained the objects of the following class:

class BOOK

{

Page 23:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

int Bno; char Title [20];

public :

int Rbno ( ) { return Bno; }

void Enter ( ) { cin >> Bno; gets (Title); }

void Display ( ) { cout << Bno <<Title <<endl; }

};

(d) Observe the program segment given below carefully and fill the blanks marked as

Statement 1 and Statement 2 using seekg() and write() for performing the required task.

#include<iostream.h>

#include<fstream.h>

class customer

{

char name[40];

long int phone;

public:

void search_phone(int recno); // Searching of telephone

// number for a given record number

void modify(int recno); // Function to modify the phone number

// of a given record number

};

void customer::search_phone(int recno)

{

fstream fin;

fin.open(“CUST.DAT”, ios::binary | ios:: in);

_____________________ //Statement 1

fin.read( ( char *) this, sizeof(customer));

cout<<name<< “\t” <<phone<<endl;

fin.close();

}

Page 24:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

void customer::modify(int recno)

{

fstream fout;

fout.open( “CUST.DAT”, ios::binary | ios::in | ios::out);

cout<< “Enter the new phone number”;

cin>>phone;

fout.seekp(recno * sizeof(customer));

_____________________ //Statement 2

fout.close();

}

Q3.(a ) Write a function in C++ to read one character at a time from an existing text file named

as OLD.TXT and store it into another text file named as NEW.TXT in uppercase.

(b)Differentiate between read() and write() functions.

(c ) Write a function in C++ to count and display the number of lines starting with alphabet ‘S’ present in a text file “STORY.TXT”.

Q4. (a)Consider the following declaration:

class TRAIN

{ int trainno;

char dest[20];

float distance;

public:

void get( ); //To read an object from the keyboard

void put( ); //To write an object into a file

void show( ); //To display the file contents on the monitor

};

Complete the member functions definitions

(b) Assuming the class COLLEGE,write a function in C++ to perform the following.

(i)Write the objects of COLLEGE to a binary file.

Page 25:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

(ii)Reads the objects of COLLEGE from binary file and display them on the screen.

class COLLEGE

{

char name[20];

char place[20];

public:

void getdata()

{

cin>>name;

cin>>place;

}

void display()

{

cout<<name;

cout<<place;

}

};

(c ) Write a user defined function in C++ to read the contents from a text file HAI.TXT, count and display the number of alphabets present in it.

(d) Observe the program segment given carefully, and answer the question that follows:class Joy

{

int Joy_id;

char Joy_name[20];

public :

// function to enter Joyians details

void enterdetails ( );

// function to display Joyians details

// function to return Joy_id

int AJoy_id( ) { return Joy_id; }

Page 26:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

};

void Modify ( JOY NEW)

{

fstream File;

File.open (“JOY.DAT”, ios :: binary | ios :: in | ios :: out);

JOY OB;

int Recordsread = 0, Found = 0;

while (!Found && File.read (( char*) & OB, sizeof(OB)))

{

Recordsread++;

if(NEW.AJoy_id( ) = = OB.AJoy_id( ))

{

________________ // Missing Statement

File.write ((char * )&NEW.sizeof(NEW));

Found = 1;

}

else

File.write((char *)&OB, sizeof(OB));

}

if (!Found)

cout << “Record for modification does not exist”;

File.close ( );

}

If the function Modify( ) is supposed to modify a record in file JOY.DAT with the values of JOY NEW passed to its argument, write the appropriate statement for Missing Statement using seekp( ) and seekg( ), whichever needed, in the above code that would write the modified record at its proper place.

(e) Write a function in C++ to search for a room-number (RoomNo) given by the user in an already existingbinary is called ‘Hospital.Dat”. Also display complete record of the room-no searched if found otherwise display a message ‘not found”.

class Hospital

Page 27:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

{

int Room_No;

char Patient_N [30];

public :

void Input( ) { gets (Patient_N); cin >> Room_No; }

void Output( )

{

cout << “Patient’s Name:” << Patient_N << endl;

cout << ‘Room Number:” << Room_No << endl;

}

int Getroom( ) { return Room_No; } };

(g) Write a program to create a text file “ TEXT.DOC “ . Tranfer the lines that start with a vowel ( not case sensitive ) to the file in reverse order . ( do not use strrev ) to a new file “EXAM.DOC” . Merge the content of both the files into a third file “ FINAL.DOC “ , contents of “TEXT.DOC” followed by “ EXAM.DOC “ . Also find the total number of bytes occupied by the file

(h) Define a class RECORD with the following specifications and complete the class definitions . ( Use BINARY FILE CONCEPT and write the function definitions )

private members :

Empno : integer

Ename : string of 30 characters

Salary : float

Input_record( ) : To accept records

Show_record( ) : To display records

Public members :

Ret_no( ) : returns eno

Create( ) : to create a file of records

Display( ) : to display the contents of the file

Modify( ) : to get a number and modify if record exist else display not found

Del( ) : to delete a record if present else say not found

Assignment Pointers - Added on 29 Aug. 2013

Page 28:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

Assignment ClassClass XII – COMPUTER SCIENCE

(h) Class XII A, Computer Science Assignment Pointers(i) Q1. Show output of the following code

1. void print (char *p) { p = “pass”; cout<<”value is :”<<p<<endl; }

void main( )

{ char *q = “best of luck”;

print (q); cout<<”new value is:”<<q;

}

2. void main( ){ int array[ ]= {1,2,3,4};

int *arptr = array;

int value = *arptr; cout<<value <<endl;

value = *arptr++; cout<<value <<endl;

value = *arptr; cout<<value <<endl;

value = *++arptr; cout<<value <<endl;

}

3. void strfunc(char **s){ char *n = “Dylan”;

*s = n; }

void main( )

{ char *str=”Lennon”;

strfunc (&str);

cout<<str <<endl;

}

4. void strfunc ( char *p){ p = “Dylan”; }

Page 29:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

void main( )

{ char *str = “Bob”;

strfunc (s);

cout<<s<<endl;

}

5. void main ( ){ float x = 5.999;

float *y, *z;

y=&x; z=y;

cout<<x<<*(&x)<<*y<<*z;

}

6. char str[ ] = ”sansum”;char *s=&str[5] – 5;

while (*s) cout<<*s++;

7. int *ptr, **ptr1;int a = 40; ptr = &a; ptr1=&ptr;

cout<<*ptr<<endl<<**ptr1<<endl<<ptr1<<*ptr1<<endl;

8. int tab [2][2] = {1, 2, 3, 4 };

cout<<*tab + 1<< endl <<*(*tab + 1) + 1<<endl <<*(*tab + 1) <<endl << *(*tab+1)+2 <<endl;

Q2. Find errors in the following code

1. const int *pc; *p=10; (*pc)++;

2. float num = 3.10, const *pc=&num;

Page 30:  · Web viewdeptname an array of char of size[20] ( represent department name) salary integer ( represent total salary of an employee) bonus float CalBonus() This function calculate

int num1 = 5.8;

pc = &num1;

Q3. Consider the following program segment:-

Int I, j = 10;

Int *p, *p1 = &j;

*p1 = j + 10;

I = *p1 – 5;

P = p1;

*p = I + j;

Suppose each integer occupies 1 byte of memory. If initial address of I is x01 and address of j is x11 then

1. What value is displayed by &j ?2. What value is displayed by &I ?3. What value is displayed by p1 ?4. What value is displayed by *p1 ?5. What value is assigned to I ?6. What value is displayed by p ?7. What value is displayed by *p ?8. What value is displayed by p+3 ?9. What value is displayed by (*p+3) ?10.What value displayed by *(p+3) ?

Q4. Consider the declaration int x[7] = { 1, 2, 3, 4, 5, 6, 7 }; and ans. the Ques. Given below

1. What is value of *x ?2. What is value of *x[5] ?3. What is value of (*x + 2) ?4. What is value of *(x + 2) ?

Q5. It tab is single dim array how you will display 1st element using * and if it is double dim array then how you will display 1st element ?