Download as pdf
Download as pdf
You are on page 1of 5
(QUESTION 5 brary issues @ a ‘of the library. fine will al ‘Number of excess days 1105 61010 above 10 days Design a cas Library and another class Compute to perform the task. The classes details are as given: Class name Data members/instance variables name, author | P ‘Member functions/methods Library( String n, String a, double np) void show( ) Class name Data members/instance variables a r ‘Member functions/methods Compute (en) void fine ) void display( ) book on rental basis at a 2% charge on the epst price of the book per day. As per the 1 book can be retained for 7 days without any fine. Ifthe book is retumed after 7 days, Iso be charged for the excess days as per the chart given below : fine per day (Rs.) 2.00 3.00 5.00 Library string variables to store name of book and authors name. price of the book in decimals. parameterized constructor to assign the parameters n to name, ‘a to author and np to p. displays the book details. Compute ‘number of days taken in returning the book. to store the fine. parameterized constructor to assign values to data members of both the classes. calculates the fine for the excess days. displays the book details along with the number of days, as fine. The amount is fine and total amount to be pai calculated as : (2% of price of book * total no. of days ) + fine Specify the class Library giving the details of the constructor and Inheritance, specify the class Compute giving the details function. You do not need to write the main( ) function. void show( ). Using the concept of | of constructor, void fine( ) and void display( ) | — A lass Salesman defines the personal data of a salesman while another class Sales defines the bit umber, mame ofthe tem, numer ftom sold and pce of teem. Te Gets of HS es Class name i Salesman Data membersiinstance variables: name: string variable to store name salesman. address: string variable to store address. ‘Member functions/methods : Salesman( ) : constructor to assign blank to name and address, void readDetails(Suing n, String ad): to assign ‘n’ to mame and ‘ad" to address. . id Show) : to print values of name and address using suitable headings. ‘Class name : Sales Data membersinstance variables Dillno, qty: integer to store bill number and quantity. Price, psales : double type to store price and previous sales amount. ‘Phame : string variable to store name of product. Member functions/methods Void readDetails(int b, int q, double p) : to assign ‘b’ to billno, ‘q’ to qty and ‘p’ to price. void readDetails(double s, String pr): to assign ‘s' to psales (previous sales) and ‘pr’ to pname. double caleulate() : to calculate and return the total sales using the formula : [ price (p) * quantity (qty) }+ previous sales (psales) void Show( ) : to display values of pname, billno, qty, price, sales and total sales made by invoking suitable function. (@) Specify the class Salesman giving details of constructor, functions void readDetails(String n, ‘String ad) and void Show( ) (b) Using the concept of inheritance specify the class Sales by giving details of the functions void readDetails(int b, int q, double p), vold readDetails(double s, String pr), double calculate( ) and ‘oid Show( ). You do not need to write the main function, QUESTION 7 ‘The distance between two points (x1, y1) and (x2, y2) is calculated as: fx wl-y2" ‘An abstract class Point represents a point on a 2D plane while another class distance is declared to help ‘in finding distance between two points and mid point. The details of both the classes are as: Class name : Point Data members/instance variables x1, yl, x2, y2 double type variable to store coordinates. dis : double type variable to strore distance. Member functions/methods + Point() : constructor to assign 0 to x1, yl, x2 and y2. abstract void readPoint( ) : to declare abstract type function. abstract void FindDistance( ) : to declare abstract type function. void Show() : to print values of x1, yl, x2 and y2 using suitable headings. Class name : distance ‘Data members/instance variables midx, midy : double type variables to store midx and midy coordinates. ‘Member functions/methods abstract void readPoint( ) : to input values of x1, y1, x2 and y2 for this abstract function declared in the class Point. abstract void FindDistance( ) : to find the distance between the two points (x1, y2) and (32, y2) for this abstract function declared in the class Point. void FindMidPoint() : to calculate the mid point using the coordinates (x1, y2) and (x2, y2). The mid point is calculated as midx=(x1+x2\/2 and midy=(y1+y2)2 void Show() : to display the values of dist, midx and midy. (a) Specify the class Point giving details of constructor, function void Show( ) and declare abstract functions abstract void readPoint( ) and abstract void FindDistance( ). (b) Using the concept of inheritance specify the class distance by giving details of the abstract functions abstract void readPoint( ), abstract void FindDistance( ), void FindMidPoint( ) & void Show( ). ‘The class distance is derived from class Point. You need to write the main function. ‘Queue is an entity which can hold elements. The queve restriction is that an integer can only Be se from the rear and removed from the front. This is like a line of voters made at the eas ‘at the casting votes for the candidates contesting in a general election, where the first person who st ‘caste thei front and next person stds on the rear of first person and 50 on and as soon as the First Person i vote, the voter exits from front only a soon Define a class queue with the following details ‘queue | ~ int quel]: array to hold the integer elements int capacity: the maximum storage capacity ea ee array is 100. int F to point to the index of front of the queue. | R: to point to the index of rear of the queue. | Member funetions/methods + ueveC) constructor to initialize 0 in each memory cell of quel | ueueGint fit, int nf int ne) constructor to initialize the limit to capacity. nf to F and mr to R (af and nr gets a value -1 only). . _| void dataPush(int num) adds the integer num to the rear of queue using FIFO. if possible, otherwise ourpots a message “queue fs full. | int dataPop() + removes the integer from the front of queue using FIFO and retums it if queue is not empty, output a message “queue is empty” and returns -9999, | void QueueDisplay) : to display the elements of current queue, if queue is not | empty. display a message “queue underflow’. (@) Specify the class queue giving the details of the constructors and all functions. Write a menu driven program with options push - 1, pop - 2, show - 3, quit - 4 and using switch-case invoke the functions depending upon the option Selected. Your program should keep on continue dll user does a want to gui Te program should eee any hole oer than 1.2.3.4 and asks o ener de | choice again. () What care should you take while defining function int dataPop( ) and void QueueDisplay()? | Stack is a kindof data structure which can hold elements, The sy . The stack restr be added from the top or removed from the top only i, applies LIFO (aon hata element can only process a class stack is declared with following details mat. To implement the above Class name : stack Data members / instance variables: int stk]: the array to hold the i int capacity the maximum capacity of the integer array. int top + to point (o the index of the topmost element ofthe stack. ‘Member functions / methods: stack() + constructor to initialize O to array stk} stack(int cap) constructor to ii iaize the cap to capacity and —1 to top. (0 push val into the stack stkf ] on the top, if possible, otherwise outputs a message “stack overflow, the element cannot be pushed". int popltem () : removes the integer from the top of stack and returns it, if stack is not empty, otherwise outputs a message “stack underflow” and returns -9999, void print_stack() : to display the elements of stack if possible ie. if stack is not empty, otherwise display a message “stack underflow". (a) , Specify the class stack giving the details of the constructors and the functions void pushItem(int val), int popltem( ) and void print_stack( ). Write a menu driven program with options push - 1, pop - 2, show_stack - 3, quit - 4 and using switch-case invoke the functions depending ‘upon the option selected. Your program should keep on continue till user does not want to quit. The program should reject any choice other than 1, 2, 3,4 and asks to re-enter the choice again. (b) What care do you take while defining function int popltem() ? void pushltem(int val)

You might also like