(TCO 8) If you were a manager and wanted to address best practices in choosing a
ID: 3773287 • Letter: #
Question
(TCO 8) If you were a manager and wanted to address best practices in choosing appropriate names for attributes and their associated accessor/mutator properties, what would you say? (Points : 18)
Question 2. 2. (TCO 2) Provide an example that shows how we can have Encapsulation without Data/Information Hiding in object-oriented programming. (Points : 18)
Question 3. 3. (TCO 2) Given the following program description, • identify the required classes/objects necessary to achieve the program requirements; • briefly describe any relationships that might exist between your classes; and • briefly describe the overall hierarchy of your proposed classes. Program Description - You have been asked to create a program designed to take coffee orders in a coffee shop. The program must be able to take an order, assign a unique ID to the order, add any number of drinks to the order, and calculate the total bill. (Points : 18)
Question 4. 4. (TCO 7) What is an abstract class? How do you use pure virtual functions defined inside an abstract class? What are the differences between a pure virtual function and an interface? (Points : 18)
Question 5. 5. (TCO 4) Consider the class Bicycle. Given your knowledge of some common components of bicycles • show a class hierarchy in which the class Bicycle inherits from other classes, which, in turn, can also be inherited from yet other classes; • discuss inheritance from class Bicycle for other closely related derived classes; and • discuss the common components of class Bicycle. (Points : 18)
Question 6. 6. (TCO 3) How does the "has-a" relationship relate to composition? Give an example of such a relationship. (Points : 18)
Question 7. 7. (TCO 2) Define and implement the overloaded constructors that support the following test function for a Date class. The data members for the Date class are: • year - integer number • month - integer number • day - integer number
int main()
{
Date d1(); //d1 will take all default values
Date d2(2011, 8, 2); //d2 will take all supplied values
Date d3(2011); //d3 will take supplied year, month and day will take default values
Date d4(2011, 9); //d4 will take supplied year and month, day will take default value
Date d5 = d2; //d5 will take the same value as d2
//the rest of the code
} (Points : 22)
Explanation / Answer
1) If I am a developer then all methods names are understood by me. But, If any one
try to modify the code then they will confuse and it will take more time to understand
the code. So it is manditory to follow intendation of code and also must use general
speaking names and also they must meaningfull. It should opt for that purpose.
Dont use any short cut names.
----------------------------------------------------------------------------------
2)
Simple we can say, Encapsulation is nothing but hiding implementation details from
user.
small eg:
public class myEncapsulationExample{
String name;
//constructor
public myEncapsulationExample(String name){
this.name = name;
}
public myEncapsulationExample(){
}
//getter setter methods
public String setName(String name){
this.name = name;
}
public void getName(){
return name;
}
}
//using this class...as follows
myEncapsulationExample obj = new myEncapsulationExample();
obj.setName("abc");
--------------------------------------------------------------------------------------------------
3)
Required class:
Coffee class (id, name,cost)
Orders class (id,cost,quantity,total)
main driver class ---> it will have relationship with both coffee and Orders.
---------------------------------------------------------------------------------------
4)
For abstract classes we will declare with abstract keyword. Main thing is that
they are not instanitiated , they are subclassed.
we can use pure virtual functions like: virtual void fun() = 0;
Interface construct doesnt provide any actual implementation, where virtual functions
will provide.
---------------------------------------------------------------------------------------------
5)
we will have common base class vehicle(name,wheels) . Then another class Specifications (wheels,color,height,speed,fuelcharge). Then program driver class.
Vehicle.java Specificatoins.java
/
/
/
main driver class
----------------------------------------------------------------------------------
6)
The class representing details that are there in other class methods too.. I mean it includes.
Take example:
Class MaruthiCar
Class Engine
So MaruthiCar has a relationship with Class Engine.
Since MaruthiCar has Engine.
-----------------------------------------------------------------------------------------
7) Overloaded method is method having same name but with different signatures.
Date d1(){
this.year = 2015;
this.month = 12;
this.day = 30;
}
Date d2(int year, int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
Date d3(int year){
this.year = year;
this.month = 9;
this.day = 30;
}
Date d4(int year, int month){
this.year = year;
this.month = month;
this.day = 30;
}
Date d5(Date d2){
this.year = d2.year;
this.month = d2.month;
this.day = d2.day;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.