15-01-2014, 04:10 PM
Object Oriented Programming Labtask#3
Object Oriented Programming .doc (Size: 32.5 KB / Downloads: 13)
Q1:Modify the class Student that you have already written in previous lab.
Create a class named Student. It contains two private data members name, marks. Create a constructor that initializes the data members; name to an empty String and marks as zero. Create two functions input() and display(). Input() takes value from user and display() displays the values of name and marks entered. Input values using input() function and display the values using display() function
1. Add parameterized constructor that is called from main().
2. Change the access of the constructor from public to private and see what happens.
3. Remove the default constructor and see what happens.
4. Define all the functions outside the class.
Q2Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four data members—a part number (type string), a part description (type String), a quantity of the item being purchased (type int) and a price per item (type int).
Your class should have a default constructor that initializes the four data members (space for strings data types and 0 for int) and a parameterized structure that initializes the four data members (values which are given by user).
Provide a public set and a get member functions for each data member.
Set member functions will receive values from main by user. Get member functions will return values instead of printing them.
In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value.
Also implement the following checks in set methods, if the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.
Write a main method that demonstrates class Invoice’s capabilities.