Member's visit
Box.h
#pragma once
int main();
class Box
{
public:
double length;
void setWidth(double wid);
double getWidth();
private:
double width;
};
double Box::getWidth()
{
return width;
}
void Box::setWidth(double wid)
{
width = wid;
}
Chapter 2 The textbook tests the access of 6 types of members.cpp
#include <iostream>
#include <string>
using namespace std;
#include "Box.h"
int main()
{
Box box;
box.length = 10.0;
cout << "Length of box:" << box.length << endl;
box.setWidth(10.0);
cout << "Width of box:" << box.getWidth() << endl;
return 0;
}
CEmplyee.h
#pragma once
#include <string>
using namespace std;
class CEmployee
{
private:
string szName;
int salary;
public:
void setName(string);
string getName();
void setSalary(int);
int getSalary();
int averageSalary(CEmployee);
};
void CEmployee::setName(string name)
{
szName = name;
}
string CEmployee::getName()
{
return szName;
}
void CEmployee::setSalary(int mon)
{
salary = mon;
}
int CEmployee::getSalary()
{
return salary;
}
int CEmployee::averageSalary(CEmployee e1)
{
return (salary + e1.getSalary()) / 2;
}
The second chapter textbook test 7 types of member access examples.cpp
#include <iostream>
using namespace std;
#include "CEmplyee.h"
int main()
{
CEmployee eT, eY;
eT.setName("Tom1234567");
eT.setSalary(5000);
cout << eT.getName() << endl;
eY.setName("Yong7654321");
eY.setSalary(3500);
cout << eY.getName() << endl;
cout << "aver=" << eT.averageSalary(eY) << endl;
return 0;
}