Object oriented programming: Assignment 1
This assignment focus on:
• Composition
• Deep copying and dynamic memory allocation
o copy constructor
o assignment operator
o destructor
• Operator overloading
------------------------------------------------------------------------------------------------------------------------------------
Cellular phone stock
Your task is to write a program for handling cellular phones. The program will later on be developed further by other system developers, so remember to be clear about the naming and comments in the source code. Properties for cellular phones are name (for example “Samsung Galaxy 4”, “Iphone 6”), color, price and numbers in stock. Set- and get-functions shall be implemented for each attribute. A cellular phone shall be able to return all of its information as a string. Further it must be possible to change the number in stock for a cellular phone.
Finally, overload the ==operator in the class CellularPhone. In this case == shall be based on the properties name and color (that is two cellular phones are equal if they have the same name and the same color). Also overload the <operator which shall be based on the number in stock (that is a cellular phone is “less than” another cellular phone if the numbers in stock is less than the other cellular phones numbers in stock).
Your system shall be designed from this class sketch:
1
Menubased
handling
30
handles
CellularPhoneStock
CellularPhone
Object Oriented Programming, Blekinge Institute of Technology, Sweden
The class CellularPhoneStock shall have a statically allocated array of the type CellularPhone * with 30 positions (the capacity of the array is 30). Copy constructor, destructor and assignment operator shall be implemented – deep copying is required! Keyboard input and screen output in the member functions are not allowed. All cellular phones must always be placed consecutive in the array .
The class CellularPhoneStock must not contain any duplicates of cellular phone objects - use the == operator.
The cellular phones must always be sorted by the numbers in stock. When adding a cellular phone it must be placed in the correct order amongst the existing cellular phones. Use the <operator.
In the file containing the main function the menu must include the following alternatives:
1. Add a new cellular phone to the stock.
2. Present all cellular phones (with all information) in the stock.
3. Present all cellular phones in the stock (with all information) that has a price below a given value
4. Present all cellular phones in the stock (with all information) of a certain name.
5. Remove a cellular phone from the stock given the name and the color.
Technical requirements:
• No memory leaks are allowed! Use: _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
at the top of main and run in debug-mode to detect memory leaks.
• Only private member variables are allowed
• All classes shall be divided into header- and cpp-files
• The possibility to implement constant member functions shall be used
• Global variables are not allowed
• The menu based system shall handle separate problems in separate functions
This assignment focus on:
• Composition
• Deep copying and dynamic memory allocation
o copy constructor
o assignment operator
o destructor
• Operator overloading
------------------------------------------------------------------------------------------------------------------------------------
Cellular phone stock
Your task is to write a program for handling cellular phones. The program will later on be developed further by other system developers, so remember to be clear about the naming and comments in the source code. Properties for cellular phones are name (for example “Samsung Galaxy 4”, “Iphone 6”), color, price and numbers in stock. Set- and get-functions shall be implemented for each attribute. A cellular phone shall be able to return all of its information as a string. Further it must be possible to change the number in stock for a cellular phone.
Finally, overload the ==operator in the class CellularPhone. In this case == shall be based on the properties name and color (that is two cellular phones are equal if they have the same name and the same color). Also overload the <operator which shall be based on the number in stock (that is a cellular phone is “less than” another cellular phone if the numbers in stock is less than the other cellular phones numbers in stock).
Your system shall be designed from this class sketch:
1
Menubased
handling
30
handles
CellularPhoneStock
CellularPhone
Object Oriented Programming, Blekinge Institute of Technology, Sweden
The class CellularPhoneStock shall have a statically allocated array of the type CellularPhone * with 30 positions (the capacity of the array is 30). Copy constructor, destructor and assignment operator shall be implemented – deep copying is required! Keyboard input and screen output in the member functions are not allowed. All cellular phones must always be placed consecutive in the array .
The class CellularPhoneStock must not contain any duplicates of cellular phone objects - use the == operator.
The cellular phones must always be sorted by the numbers in stock. When adding a cellular phone it must be placed in the correct order amongst the existing cellular phones. Use the <operator.
In the file containing the main function the menu must include the following alternatives:
1. Add a new cellular phone to the stock.
2. Present all cellular phones (with all information) in the stock.
3. Present all cellular phones in the stock (with all information) that has a price below a given value
4. Present all cellular phones in the stock (with all information) of a certain name.
5. Remove a cellular phone from the stock given the name and the color.
Technical requirements:
• No memory leaks are allowed! Use: _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
at the top of main and run in debug-mode to detect memory leaks.
• Only private member variables are allowed
• All classes shall be divided into header- and cpp-files
• The possibility to implement constant member functions shall be used
• Global variables are not allowed
• The menu based system shall handle separate problems in separate functions