In: Computer Science
This is a discussion question for my csc 252 computer programming c++ visual studio so post in c++ visual studio so that i can copy and paste thank you.
In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine a class already defined by a classmate. Use proper C++ syntax to present your class.
Code -
#include <iostream>
using namespace std;
class Employee{
//three data field /variable
public:
int id;
string name;
double salary;
//constructor
Employee(){
id = 1;
name = "xxx";
salary = 30000;
}
//parameterized constructor
Employee(int empid ,string empname,double empsalary){
id = empid;
name = empname;
salary = empsalary;
}
//three method to display Employee detials , Annual salary, and
incremenSalary
void display(){
cout<<"Employee ID "<<id<<" Name
"<<name<<" monthy salary
"<<salary<<endl;
}
void salaryAnnually(){
cout<<"Annual salary "<<salary*12<<endl;
}
void incremenSalary(int percentageIncrement){
salary = (percentageIncrement *salary/100)+salary;
cout<<"New salary "<<salary<<endl;
}
};
int main()
{
Employee e1 ;
e1.id = 40;
e1.name = "John Nuke";
e1.salary = 45000;
e1.display();
e1.salaryAnnually();
e1.incremenSalary(5);
Employee e2;
e2.display();
e1.incremenSalary(6);
Employee e3(25,"Bryan",50000);
e3.display();
return 0;
}
Screenshots -