eTrustBux

CLICK HERE TO JOIN AND MAKE EARNING


Prgram



#include<iostream>
using namespace std;
class student{
float inch;
float feet;
float add;
public:
float dist(float a,float b){
inch=a;
feet=b;
add=inch+feet;
return add;
}
void display(){
cout<<add;
}
};
int main(){
student d1;
d1.dist(12.3,23.3);
d1.display();
return 0;
}

PROgramming TAsk

#include<iostream>
#include<string>
using namespace std;
class Employee{
string fname,lname;
public:
Employee(){
}
Employee(string n,string n1){
fname=n;
lname=n1;
}
void Display(){
cout<<" *<< Employee Detaile >>* "<<endl;
cout<<" Full Name: "<<fname<<" "<<lname<<endl;
}
};
class Hourlyworker:public Employee{
double wage,hour,salary;
public:
Hourlyworker():Employee("ZAIN","SHAHID"){
wage=25500.0;
hour=12.0;
}
float getpay(){
salary=wage*hour;
return salary;
}
void show(){
cout<<" Salary of Employee is: "<<salary;
}
};
int main(){
Hourlyworker hw;
hw.Display();
hw.getpay();
hw.show();
}

C++ Programming

#include<iostream>
#include<string>
using namespace std;
class Date{
int day;
string month;
int year;
public:
Date(){
day=1;
month="January";
year=2000;
}
Date(int d,string m,int y){
day=d;
month=m;
year=y;
}
void show(){
cout<<"\n Date is : "<<day<<"-"<<month<<"-"<<year<<endl;
}
};
int main(){
Date d;
Date d1(26,"March",2019);
d1.show();
return 0;
}

Programming Task

Programming task:


Task_A
Create a class Employee with following constraints in mind;
_ Declare two data members named firstName and lastName of string type.
_ Implement a parameterized constructor, which will take firstName and lastName of an employee and initialized the respective data members.
_ Implement a print function that displays the complete name (firstName lastName) of an Employee.
Task_B
Test the working of your created Employee class with the help of a main program.
Task_C
Create a class HourlyWorker which inherits from Employee class publically with following constraints in mind;
_ Declare two data members named wage and hours of double type with private access.
_ Implement a parameterized constructor, which initializes all the data members of HourlyWorker class.
_ Implement a getPay function that calculate and return the salary (hours * wage) of particular
HourlyWorker employee.
_ Implement a print function that displays the complete name and salary of a particular employee.
Task_D
Test the working of your created HourlyWorker class with the help of a main program.
Programming Task 02
Implement the following class hierarchy, the inheritance access level should be protected for Reptile, Bird and
Mammal on the other hand it should be private for Snake, Parrot and Horse classes.




Task _A
Add a protected data member named id of integer type to Animal class.
Task_B
Add get/set methods for id data member in Animal class with public access.
Task_C
Add a default constructor to each of the above created class. The constructor should initialize the id data member of Animal, Reptile, Bird and Mammal, to 0, 1, 2 and 3 respectively also it display a message “(class Name)’s default constructor”.
Task_D
Add a parameterized constructor to each of the above created class. The constructor should initialize the id data member of Animal, Reptile, Bird and Mammal, to the specified id passed to the constructor also it display a message “(class Name)’s default constructor”. The parameterized constructor should call its base class parameterized constructor to initialize any data member inherited from the base class.
Task_E
Add a destructor to each of the above created class. The destructor should display a message “(class Name)’s default destructor”.
Task_F
Add a getFamily method to Snake, Parrot and Horse classes, this method must return the id of a particular animal’s family where it belongs to.
Task_G
Add a tellAboutSelf method to Animal class with public access. The method displays the name of each objects class where it belongs to.
Task_H
Override the tellAboutSelf in all the sub-leaving classes of Animal with the same functionality as in Animal class.
Task_I
Add a speak method to Animal class and override it in each of the sub-leaving classes. The Animal, Reptile, Bird, Mammal, Snake, Parrot and Horse can speak by printing a message “I am Animal, I cant speak…”, “Family of Reptiles…” “Family of Birds…”, “Family of Mammals…”, “Shhh….”, “Trrrr….” and “Hurrrrr…” respectively.
Task_J

Write down your main method and instantiate object of each class created above, call tellAboutSelf, speak and getFamily methods for each of the created object.            Note the mechanism in which constructors and destructors are called.


Programming Task

Programming Task: 


Ø C++ Program to Store Information of a Student in a Class
Ø C++ Program to Add Two Distances (in inch-feet) System Using Class
Ø C++ Program to Add Complex Numbers by Passing Object of a class to a     Function
Ø C++ Program to Calculate Difference Between Two Time Period
Ø  Store and Display Information of a car using Class and Member functions



 Programming task 2:
  
Part 1
Create a class Date with following data members:
·        Day, Month, Year
·        Overload two constructors to set the initial date.
·        Create multiple objects in main according to the need of programme.
  1. Overloaded == operator to check if the date is same. This will be a member function as demonstrated in the notes. Remember that you will want to compare the month, day, and year.
  2. Add an overloaded ++ operator (as a member function, to increment date, and month and year according to requirements of the calendar)
  3. Just for fun, create an overloaded << operator as a non-member to print the date.
ostream& operator<<(ostream&, const Date&);
  1. Explain why operator<< must be overloaded as a non-member.

Part 2:
Overload the + operator so that the following lines of code run in main:
        Date date3, date4;
        date3=date1+82;
        date4=6+date2;
More Details:
  • Define two functions. The prototypes will look like this:
·         Date operator+ (const Date&, int);
Date operator+ (int, const Date&);
Are they member or non-member functions? (Notice how many arguments they have)
  • Both functions will create a temporary date and return it.
  • Think about reusing as much code as possible.
    1. For one implementation of operator+, can you call the operator++ function?
    2. For the second implementation of operator+, can you call the first operator+ function?
    3. Together these two functions should be no more that 10 lines of code in the bodies. If you make it longer, you are working too hard.




C++ Program with inheritence

#include<iostream>
using namespace std;
class A{
public:
A(){
cout<<"Class A"<<endl;
}
A(int x){

cout<<x<<endl;
}
};
class B:public A{
public:
B(){
cout<<"Class B"<<endl;
}
B(int x):A(){

cout<<x<<endl;
}
};
class C:public B{
public:
C(){
cout<<"Class C"<<endl;
}
C(int x){
cout<<x<<endl;
}
};
int main(){
B obj(12);
return 0;
}