Lab 1
Lab 1
Lab Preparation
First Program: Write the following program in your IDE and inspect the output.
#include<iostream>
using namespace std;
#include <iostream>
using namespace std;
class Student
{
public:
string level;
int age;
1. Consider the following UML representation of a base class. Write a class called MobilePhone
and save as mobilephone.h. Note that function ‘getModel()’ will return model, ‘getPrice()’
will return price, and print() will print information of the phone.
MobilePhone
-id:int
-make: string
-model: string
-type: string = “smartphone”
-ram: string
-price: double
-stock: int
+getModel(): string
+getPrice():double
+setStock(): void
+print() const: void
+Mobilephone()
+Mobilephone(int,string, string, string, string, double): void
2. The following UML representation is a derived class IPhone of a MobilePhone. Create a class
called IPhone and save as iphone.h
IPhone
-os: string
-version: string
+set_specs(string, string)
AndroidPhone
-os: string
-version:string
+set_specs(string, string)
Implement the definition of the member functions of all of the classes in (1). Then write a basic
program (main) that creates instances of IPhone and AndroidPhone using the details shown in
Table 1. Print the basic information of the mobile phone.
Table 1: Details of mobile phone data.
id Make Model RAM Price OS Version
1 IPhone IPhone 6S 2GB 1688.00 iOS 9.0
2 Samsung Galaxy S8 4GB 2756.00 Android 7.0
3 Motorola Moto Z2 4GB 1799.00 Android 7.1.1
1. Modify the definition of class IPhone and AndroidPhone to override the function print() in
MobilePhone and print their local variables.
2. Modify the overriding function print() to include phone information from MobilePhone.
Exercise 4: Overloading concept (Specifying more than one definition for a function name
or an operator in the same scope).
1. Function overloading:
a. Create setStock(int) function definition in MobilePhone with parameter (int) to accept
the current total stock number of a phone.
b. Implement the function by calling it from your program in Exercise 2.