Bee13d Lab 06
Bee13d Lab 06
Bee13d Lab 06
Class: BEE-13D
Fall 2022
Lab06: Constructors
Instructor: Mehreen
Tahir
Objective
After performing this lab, the student should be able to learn how to overload a constructor, use
copy constructors and what are the scenarios where overloaded constructors can be used.
Example
#include<iostream>
using namespace std;
class Point
{
private:
int x, y;
public:
Point(int x1, int y1) { x = x1; y = y1; }
// Copy constructor
Point(const Point &p2) {x = p2.x; y = p2.y; }
int getX() { return x; }
int getY() { return y; }
};
int main()
{
Point p1(10, 15); // Normal constructor is called here
Point p2 = p1; // Copy constructor is called here
class Sandwich{
string filling;
double price;
bool is_ready;
……
public:
Sandwich();
Sandwich(string filling, double price);
void setFilling(string);
void setPrice(double);
bool check_status();
void printData();
};
Task # 2
Write a Student class in C++
A student object should hold information about a student in your grade book and should have the
following details:
string name
int age
int *p
Print the values of s1 and s2 along with address of pointer p (calling the same print function
again)
IMPORTANT
Apply Object Oriented Programming concepts to ensure that data is private and accessed
properly through public interface comprising of set and get functions.
Split implementation across multiple files (Header Files and Source Code Files) to ensure
that application design is modular.
You are encouraged to use good programming conventions by entering appropriate
comments, using indentations, and using descriptive variable names in your programs.
Deliverables: Complete lab manual by performing all tasks. Copy paste your code and screen
shot of console window as a solution of each task. You are required to upload the lab tasks on
LMS and the name of the task must be in this format YourFullName_reg#.