C + + Exercises 310, 11 questions

Source: Internet
Author: User

Tag:c++    class and Object    

10.   the salary of a certain unit includes basic salary wage, post towel subsidy, rent rent, water fee waterfee, electricity tariff elecfee, design realizes wage management class salary, this kind of form is as follows:class  Salary{private:double wage,subsidy,rent,waterfee,elecfee;public:salary (-----) {Initialize payroll data for each sub-item}salary () { The data for the initial payroll is 0}void setxx  (double f) {xx=f;} Double getxx () {return xx;} Double realsalary ()           //calculates the actual wage-------}; The member function setxx () sets the individual data for the payroll, the member function getxx () is used to get the individual data for the payroll, and XX represents data members such as Wage,subsidy, such as wage corresponding member functions Setwage () and Getwage () .  The real wage =wage+subsidy-rent-waterfee-elecfee the design of this class, and write the main function of testing the class member function main.11.  human worker, it has the name name, age, Work Department Dept, Salary salary and other data members. Where salary uses the class defined on the title. Complete the worker class design and count the number of workers, write a test program to test// test.cpp :  define the entry point for the console application. #include <iostream> #include <string.h> #include <string>using namespace std;class  salary{private:double wage,subsidy,rent,waterfee,elecfee;double realsalary;public:salary (int  wag=0,int s=0,int r=0,int wat=0,int ele=0) {wage=wag; Subsidy=s; Rent=r; Waterfee=wat; Elecfee=ele; Realsalary=wage+subsidy-rent-waterfee-elecfee;} Void setwage (int xx) {wage=xx;} Void setsubsidy (int xx) {subsidy=xx;} Void setrent (int xx) {rent=xx;} Void setwaterfee (int xx) {waterfee=xx;} Void setelecfee (int xx) {elecfee=xx;} Double getwage () {return wage;} Double getsubsidy () {return subsidy;} Double getrent () {return rent;} Double getwaterfee () {return waterfee;} Double getelecfee () {return elecfee;} Double getrealsalary () {return realsalary;}}; class worker{private:static int numbers;char *name;int age;char *dept; Salary salary;public:worker (Const char* name,int age,const char* department,int  wag=0,int s=0,int r=0,int wat=0,int ele=0): Salary (Wag,s,r,wat,ele)  {name=new  char[strlen (Name) +1];D Ept=new char[strlen (Department)+1];strcpy (dept,department); strcpy (name,name); age=age;numbers++;} Void setname (const char *name) {Name=new char[strlen (Name) +1];strcpy (name,Name);} Void setage (int a) {age=a;} Void setdept (const char *department) {Dept=new char[strlen (Department) +1];strcpy (Dept, Department);} Void setsalary (int wag, int s, int r, int wat, int e) { Salary.setwage (WAG); Salary.setsubsidy (s); Salary.setrent (R); Salary.setwaterfee (wat); Salary.setelecfee (e);}; Static int getnumbers () {return numbers;} Char *getname () {return name;} Char *getdept () {return dept;} Int getage () {return age;} Double getsalary () {return salary.getrealsalary ();}}; Int worker::numbers=0;int main () {worker worker1 ("Jaychen", 19, "development department", 3000,1000,500,100,50); Worker worker2 ("JayChen1", 19, "development department", 3000,1000,500,100,50);cout<< "Worker1" <<endl;cout<< " name:       "<<worker1.getname () <<endl;cout<<" Department: "<<worker1.getdept () << endl;cout<< "age:       " <<worker1.getage () <<endl;cout< < "salary:    " <<worker1.getsalary () <<endl;return 0;}


C + + Exercises 310, 11 questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.