addDropdown
也
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee(string f ,string l ,int m ){
setFName(f) ;
setLName(l) ;
setMSalary(m) ;
}
void setFName(string f){
fName = f ;
}
string getFName(){
return fName ;
}
void setLName(string l){
lName = l ;
}
string getLName(){
return lName ;
}
void setMSalary(int m){
if ( m <0 ){
mSalary = 0 ;
}
else {
mSalary = m ;
}
}
intgetMSalary(){
returnmSalary ;
}
intySalary(){
return12 * mSalary ;
}
intraise(){
return (0.10 * ySalary()) + ySalary() ;
}
private :
string fName ;
string lName ;
int mSalary ;
};
int main(){
Employeeem1("SARA" , "SALEH" , 5000);
Employeeem2("Bayan" , "Khaled" , 8000 ) ;
cout<<"The yearly salary of first employee is "<< em1.ySalary() <<endl ;
cout<<"The yearly salary of second employee is "<< em2.ySalary()<<endl ;
cout<<"\nThe yearly salary of first employee is after raising "<<em1.raise()<<endl ;
cout<<"The yearly salary of second employee is after raising "<<em2.raise() <<endl ;
}
我收到这些错误
#include <iostream>
#include <string>
using namespace std ;
class Employee {
public:
Employee(string f ,string l ,int m ){
setFName(f) ;
setLName(l) ;
setMSalary(m) ;
}
void setFName(string f){
fName = f ;
}
string getFName(){
return fName ;
}
void setLName(string l){
lName = l ;
}
string getLName(){
return lName ;
}
void setMSalary(int m){
if ( m <0 ){
mSalary = 0 ;
}
else {
mSalary = m ;
}
}
int getMSalary(){
return mSalary ;
}
private :
string fName ;
string lName ;
intmSalary ;
};
int main(){
Employeeem1("SARA" , "SALEH" , 5000);
Employeeem2("Bayan" , "Khaled" , 8000 ) ;
int raise1 , raise2 ;
cout<<"The yearly salary of first employee is "<< em1.getMSalary()*12<<endl ;
cout<<"The yearly salary of second employee is "<< em2.getMSalary() *12<<endl ;
raise1 = (0.20 * em1.getMSalary()) + em1.getMSalary() ;
raise2 = (0.20 * em2.getMSalary()) + em2.getMSalary() ;
cout<<"\nThe yearly salary of first employee is after raising "<< raise1 * 12<<endl ;
cout<<"The yearly salary of second employee is after raising "<< raise*12<<endl ;
}
答案 0 :(得分:2)
以下是第二个版本的语法更正。您只有与空间相关的小问题...请参阅内联评论
#include <iostream>
#include <string>
using namespace std ;
class Employee
{
public:
Employee(string f , string l , int m )
{
setFName(f) ;
setLName(l) ;
setMSalary(m) ;
}
void setFName(string f)
{
fName = f ;
}
string getFName()
{
return fName ;
}
void setLName(string l)
{
lName = l ;
}
string getLName()
{
return lName ;
}
void setMSalary(int m)
{
if ( m < 0 )
{
mSalary = 0 ;
}
else
{
mSalary = m ;
}
}
int getMSalary()
{
return mSalary ;
}
private :
string fName ;
string lName ;
//you forgot space after int
int mSalary ;
};
int main()
{
//you forgot space after Employee
Employee em1("SARA" , "SALEH" , 5000);
Employee em2("Bayan" , "Khaled" , 8000 ) ;
int raise1 , raise2 ;
cout << "The yearly salary of first employee is " << em1.getMSalary() * 12 << endl ;
cout << "The yearly salary of second employee is " << em2.getMSalary() * 12 << endl ;
raise1 = (0.20 * em1.getMSalary()) + em1.getMSalary() ;
raise2 = (0.20 * em2.getMSalary()) + em2.getMSalary() ;
cout << "\nThe yearly salary of first employee is after raising " << raise1 * 12 << endl ;
// I think you meant raise2 instead of raise
cout << "The yearly salary of second employee is after raising " << raise2 * 12 << endl ;
}