lab5
lab5
Section 06
Lab Objectives:
The basic purpose of this laboratory is revision of some preliminary concepts of ++ that has been
covered in the course of Introduction to Computing and Programming Fundamentals. Its objective is
to:
Instructions:
public:
Student();
Student(int id, char*name, float om, float cm, float dm);
Student(const Student &obj);
void setname(char* n);
char* getname();
void setid(int id);
int getid();
void display();
void set_oopmarks(float om);
void set_calmarks(float cm);
void set_dsmarks(float dm);
float get_oopmarks();
float get_calmarks();
float get_dsmarks();
float findtotal();
};
Student::Student(){
id = 0;
name = nullptr;
OOP_marks = 0.0;
Cal_marks = 0.0;
Ds_marks = 0.0;
cout << "its a default constructor" << endl;
}
Student::Student(int id, char*name, float om, float cm, float dm){
this->id = id;
int size = 0;
for (int i = 0; name[i] != '\0'; i++){
size++;
}
this->name = new char[size + 1];
for (int i = 0; i < size + 1; i++)
{
this->name[i] = name[i];
}
this->name[size] = '\0';
OOP_marks = om;
Cal_marks = cm;
Ds_marks = dm;
cout << "its a parameterized constructor" << endl;
}
Student::Student(const Student &obj){
cout << "its a copy constructor" << endl;
id = obj.id;
int size = 0;
for (int i = 0; obj.name[i] != '\0'; i++){
size++;
}
name = new char[size + 1];
for (int i = 0; i < size + 1; i++)
{
name[i] = obj.name[i];
}
name[size] = '\0';
OOP_marks = obj.OOP_marks;
Cal_marks = obj.Cal_marks;
Ds_marks = obj.Ds_marks;
void Student::setname(char*name){
int size = 0;
for (int i = 0; name[i] != '\0'; i++){
size++;
}
this->name = new char[size + 1];
for (int i = 0; i < size + 1; i++)
{
this->name[i] = name[i];
}
this->name[size] = '\0';
}
char* Student::getname(){
return name;
}
void Student::setid(int id){
this->id = id;
}
int Student::getid(){
return id;
}
void Student::set_calmarks(float cm){
Cal_marks = cm;
}
void Student::set_oopmarks(float om){
OOP_marks = om;
}
void Student::set_dsmarks(float dm){
Ds_marks = dm;
}
float Student::get_calmarks(){
return Cal_marks;
}
float Student::get_oopmarks(){
return OOP_marks;
}
float Student::get_dsmarks(){
return Ds_marks;
}
float Student::findtotal(){
float total;
total = Ds_marks + OOP_marks + Cal_marks;
return total;
void Student::display(){
int main(){
s1.setid(9087);
s1.setname("hira");
s1.set_calmarks(90.7);
s1.set_dsmarks(96.12);
s1.set_oopmarks(99.2);
cout << "student " << s9.getname() << " total marks are " << s9.findtotal() <<
" out of 300" << endl;
system("pause");
return 0;
}
Sample task output
LAB TASKS:
Task 1
Write a code for a class ‘BankAccount’. A basic idea of the class is shown below:
copy constructor, deep copy shallow copy
- means private
+ means public
BankAccount
- Name: char *
- Address: char *
- PhoneNumber: char *
- Account_Type: char *
- Account_Balance: float
- Account_Number: int
+ BankAccount()
+ BankAccount(char *, char *, char *, char *, float, int)
+ BankAccount(BankAccount&obj)
+ void setname(char* n)(for all private member except const
attribute)
+ char* getName() (for all attributes)
When an object of this class is instantiated, it is always done by default constructor, parameterized
constructor using having 5 parameters or by creating a copy of an already existing object.
A bank account number can have 4 or more digits. This number will be unique for every account.
Use this pointer in overloading constructor and setters and also do deep copy in setter and overloaded
constructor
Task 2
Next Bridge software house Lahore requires an application that calculates employee’s increment
based on the given criteria. For the purpose software house wants his software engineer to design the
application using object-oriented approach. The class “NextBridge” is required to create with
attributes and functions as mentioned below.
- name: char*
- address: char*
- phoneNumber: char*
- level: char* //fresh,Junior,sensior
- experience:int //in years
- currentSalary: double
- increment: double
Methods:
// Constructors( parameterize constructor, copy
constructor )
// Destructor
// Calculate increment
Increment criteria
Experience Increment
0 0%
01- 02 10 %
02- 06 20%
06 to onward 40%
When an object of the class is instantiated, it is always done by either using an overloaded constructor
having 7 parameters or by creating a copy of an already existing object. Examples of such instantiations
are given below:
Use this pointer in overloading constructor and setters and also do deep copy in setter and overloaded
constructor