
请高手帮忙解决一下这个C++问题。
#include<iostream>#include<iomanip>#include<fstream>#include<cstring>#include<cctype>...
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cctype>
using namespace std;
class WorkerPay
{
private:
char lname[10];
char fname[10];
float payrate;
char time[5];
float hour;
float totalhours;
float min;
float totalmins;
public:
WorkerPay ()
{ hour = 0; min = 0; payrate = 0; totalhours = 0; totalmins = 0; }
WorkerPay (float, float, float, float, float);
void setlname(char lastname[10]);
void setfname(char firstname[10]);
void settime(char worktime[5]);
void getlname();
void getfname();
void gettime();
float caltime();
WorkerPay operator + (const WorkerPay &);
};
void WorkerPay::setlname(char lastname[10])
{
strcpy(lname, lastname);
}
void WorkerPay::setfname(char firstname[10])
{
strcpy(fname, firstname);
}
void WorkerPay::getlname ()
{
cout << lname;
}
void WorkerPay::getfname ()
{
cout << fname;
}
void WorkerPay::settime (char worktime[5])
{
hour = (atof(worktime[0]) * 10) + atof(worktime[1]);
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
}
float caltime()
{
return ( totalhours + totalmins / 60 );
}
struct w_Time
{
char w_hour[5];
};
struct Week
{
w_Time day[5];
};
int main ()
{
const int MAXNUM = 200;
WorkerPay worker[MAXNUM];
char ln[10];
char fn[10];
float rate;
int num = 0;
Week t;
cout << "Please input the worker’s last name, first name, pay rate, " << endl;
cout << "start time, and end time from Monday through Friday separated " << endl;
cout << "by space. (Enter -1 to end the input)" << endl;
cin >> ln >> fn >> rate >> t.day[0].w_hour >> t.day[1].w_hour >> t.day[2].w_hour >> t.day[3].w_hour >> t.day[4].w_hour;
worker[0].setlname (ln);
worker[0].setfname (fn);
for (int i = 0; i < 5; i++)
worker[0].settime (t.day[i].w_hour);
while (!(ln[0] == '-' && ln[1] == '1'))
{
cin >> ln >> fn >> rate >> t.day[0].w_hour >> t.day[1].w_hour >> t.day[2].w_hour >> t.day[3].w_hour >> t.day[4].w_hour;
num++;
worker[num].setlname (ln);
worker[num].setfname (fn);
for (int i = 0; i < 5; i++)
worker[num].settime (t.day[i].w_hour);
}
return 0;
}
代码还没有写完。这是一部分而已。我编译这部分的时候遇到了如下问题:
error C2664: 'atof' : cannot convert parameter 1 from 'char' to 'const char *'
我想问题应该出在如下地方。。。
解释一下我之所以这么写的原因是:需要输入一个工人5天的工作时间。而输入时间的格式必须为 hh:mm(输入的时候要带冒号,小时和分钟十位数不足的时候要用0补齐)。
void WorkerPay::settime (char worktime[5])
{
hour = (atof(worktime[0]) * 10) + atof(worktime[1]);
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
}
struct w_Time
{
char w_hour[5];
};
struct Week
{
w_Time day[5];
};
worker[0].settime (t.day[i].w_hour);
请高手帮我看一下,我的问题该怎么解决,麻烦解释一下发生问题的原因。 展开
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cctype>
using namespace std;
class WorkerPay
{
private:
char lname[10];
char fname[10];
float payrate;
char time[5];
float hour;
float totalhours;
float min;
float totalmins;
public:
WorkerPay ()
{ hour = 0; min = 0; payrate = 0; totalhours = 0; totalmins = 0; }
WorkerPay (float, float, float, float, float);
void setlname(char lastname[10]);
void setfname(char firstname[10]);
void settime(char worktime[5]);
void getlname();
void getfname();
void gettime();
float caltime();
WorkerPay operator + (const WorkerPay &);
};
void WorkerPay::setlname(char lastname[10])
{
strcpy(lname, lastname);
}
void WorkerPay::setfname(char firstname[10])
{
strcpy(fname, firstname);
}
void WorkerPay::getlname ()
{
cout << lname;
}
void WorkerPay::getfname ()
{
cout << fname;
}
void WorkerPay::settime (char worktime[5])
{
hour = (atof(worktime[0]) * 10) + atof(worktime[1]);
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
}
float caltime()
{
return ( totalhours + totalmins / 60 );
}
struct w_Time
{
char w_hour[5];
};
struct Week
{
w_Time day[5];
};
int main ()
{
const int MAXNUM = 200;
WorkerPay worker[MAXNUM];
char ln[10];
char fn[10];
float rate;
int num = 0;
Week t;
cout << "Please input the worker’s last name, first name, pay rate, " << endl;
cout << "start time, and end time from Monday through Friday separated " << endl;
cout << "by space. (Enter -1 to end the input)" << endl;
cin >> ln >> fn >> rate >> t.day[0].w_hour >> t.day[1].w_hour >> t.day[2].w_hour >> t.day[3].w_hour >> t.day[4].w_hour;
worker[0].setlname (ln);
worker[0].setfname (fn);
for (int i = 0; i < 5; i++)
worker[0].settime (t.day[i].w_hour);
while (!(ln[0] == '-' && ln[1] == '1'))
{
cin >> ln >> fn >> rate >> t.day[0].w_hour >> t.day[1].w_hour >> t.day[2].w_hour >> t.day[3].w_hour >> t.day[4].w_hour;
num++;
worker[num].setlname (ln);
worker[num].setfname (fn);
for (int i = 0; i < 5; i++)
worker[num].settime (t.day[i].w_hour);
}
return 0;
}
代码还没有写完。这是一部分而已。我编译这部分的时候遇到了如下问题:
error C2664: 'atof' : cannot convert parameter 1 from 'char' to 'const char *'
我想问题应该出在如下地方。。。
解释一下我之所以这么写的原因是:需要输入一个工人5天的工作时间。而输入时间的格式必须为 hh:mm(输入的时候要带冒号,小时和分钟十位数不足的时候要用0补齐)。
void WorkerPay::settime (char worktime[5])
{
hour = (atof(worktime[0]) * 10) + atof(worktime[1]);
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
}
struct w_Time
{
char w_hour[5];
};
struct Week
{
w_Time day[5];
};
worker[0].settime (t.day[i].w_hour);
请高手帮我看一下,我的问题该怎么解决,麻烦解释一下发生问题的原因。 展开
2个回答
展开全部
hour = (atof(worktime[0]) * 10) + atof(worktime[1]);
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
==>
hour = (worktime[0]-'0') * 10 + (worktime[1]-'0');
min = (worktime[3]-'0') * 10 + (worktime[4]-'0');
atof是把数字串转为实型数返回,你现在只是要把字符型数字换成整数 如'9'-'0' 就得到整数9了
min = (atof(worktime[3]) * 10) + atof(worktime[4]);
==>
hour = (worktime[0]-'0') * 10 + (worktime[1]-'0');
min = (worktime[3]-'0') * 10 + (worktime[4]-'0');
atof是把数字串转为实型数返回,你现在只是要把字符型数字换成整数 如'9'-'0' 就得到整数9了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询