Fancy Oriental Objects (FOO), Incorporated, is a mail-order company specializing
ID: 3669208 • Letter: F
Question
Fancy Oriental Objects (FOO), Incorporated, is a mail-order company specializing in overpriced knick-knacks and kitsch imported from Eastern Asia. FOO processes orders via a number of regional warehouses. Each warehouse has responsibility for inventory management and order processing. Because demand of some products varies by region, the inventory at the warehouses may vary considerably. Also, the products offered tend to vary considerably from year to year.
Customer orders are received at the central mail-order facility (MOF). The MOF staff check the list of products ordered against the available stock in the various warehouses and divides the order among the warehouses, sending a packing slip to each warehouse. The packing slip tells the warehouse which products from the total order that warehouse should ship to the customer.
The MOF prepares a single invoice for each customer order, indicating the items to be shipped to fulfill the order,their expected shipping date, and various charges to the customer including the price of the items, shipping and handling costs, and sales taxes. This invoice is mailed separately to the customer.
FOO would like to have a common inventory- and order-tracking system across all of its warehouses, to replace the current amalgamation of manual processing and low-level computer tools (spreadsheets, word processors) used to support this process.
Explanation / Answer
List of Candidate Classes in C++.
1) Aggregate Classes
2) Global and Local Class
3) Member Functions
4) Inheritance
5) Constructors
6) Destructors
1) Aggregate classes
An aggregate class is a class with no user-declared constructors, no private or protected non-static data members, no base classes, and no virtual functions.
Such a class can be initialized with a brace-enclosed comma-separated list of initializer-clauses.
An aggregation is a specific type of composition where no ownership between the complex object and the subobjects is implied. When an aggregate is destroyed, the subobjects are not destroyed.
Example:
#include <string>
using namespace std;
class Teacher
{
private:
string m_strName;
public:
Teacher(string strName)
: m_strName(strName)
{
}
string GetName() { return m_strName; }
};
class Department
{
private:
Teacher *m_pcTeacher; // This dept holds only one teacher
public:
Department(Teacher *pcTeacher=NULL)
: m_pcTeacher(pcTeacher)
{
}
};
int main()
{
// Create a teacher outside the scope of the Department
Teacher *pTeacher = new Teacher("Bob"); // create a teacher
{
// Create a department and use the constructor parameter to pass
// the teacher to it.
Department cDept(pTeacher);
} // cDept goes out of scope here and is destroyed
// pTeacher still exists here because cDept did not destroy it
delete pTeacher;
}
2) Global and Local Class
A class defined outside all methods is a global class because its objects can be created from anywhere in the program. If it is defined within a function body then it's a local class because objects of such a class are local to the function scope.
Example for Global Variables:
3) Member Functions
The C++ classes and structures are Member Functions
A member function of a class is a function that has its definition or its prototype within the class definition like any other variable. It operates on any object of the class of which it is a member, and has access to all the members of a class for that object.
Example:
When the above code is compiled and executed, it produces the following result:
4) Inheritance
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
5) Constructors
When programmers declare their variables as default or specific value.
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.
Following example explains the concept of constructor:
When the above code is compiled and executed, it produces the following result:
6) Destructors
A destructor is the reverse of a constructor. It is called when an instance of a class is destroyed.
A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.
A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
Example:
When the above code is compiled and executed, it produces the following result:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.