C++ 程序ClockType.h、testClockType.cpp和ClockTypeImp.cpp中存在错误
仍然有7个错误:C++ 程序ClockType.h、testClockType.cpp和ClockTypeImp.cpp中存在错误,c++,C++,仍然有7个错误: clockTypeImp.cpp:48:错误:“void ClockType::getTime(int&,int&,int&)const”的原型与类“ClockType”中的任何原型都不匹配 clockType.h:35:错误:候选项为:void clockType::getTime(int&,int&,int&) clockTypeImp.cpp:98:错误:在“(”标记之前需要构造函数、析构函数或类型转换 > CyType IMP.CPP:109:错误:ISO C+
#include <iostream>
#include "clockType.h"
using namespace std;
int main()
{
int cellHours;
int cellMinutes;
int cellSeconds;
int computerHours;
int computerMinutes;
int computerSeconds;
cout << "Please tell me the hour on your cell phone: ";
cin >> cellHours;
cout << endl;
cout << "Please tell me the minute on your cell phone: ";
cin >> cellMinutes;
cout << endl;
cout << "Please tell me the second on your cell phone: ";
cin >> cellSeconds;
cout << endl;
cout << endl;
cout << "Please tell me the hour on your computer: ";
cin >> computerHours;
cout << endl;
cout << "Please tell me the minute on your computer: ";
cin >> computerMinutes;
cout << endl;
cout << "Please tell me the second on your computer: ";
cin >> computerSeconds;
cout << endl;
cout << endl;
cout << "=================================================" << endl;
cout << endl;
cout << "Your cell phone time is: " << endl;
ClockType cellPhoneClock;
cellPhoneClock.setTime(cellHours, cellMinutes, cellSeconds);
cellPhoneClock.printTime();
cout << endl;
cout << "Your computer time is: " << endl;
ClockType myComputerClock;
myComputerClock.setTime(computerHours, computerMinutes, computerSeconds);
myComputerClock.printTime();
cout << endl;
if(!cellPhoneClock.equalTime(myComputerClock))
{
cout << "Both clocks do not have equal times" << endl;
cout << "Setting Computer clock to the cell Phone Clock time" << endl;
int hours, minutes, seconds;
cellPhoneClock.getTime(hours, minutes, seconds);
myComputerClock.getTime(hours, minutes, seconds);
}
else
{
cout << "Both clocks have equal times" << endl;
}
cout << endl << "Final cell phone time is: ";
cellPhoneClock.printTime();
cout << endl << "Final computer time is: ";
cellPhoneClock.printTime();
cout << endl;
//cout << "===================================================" << endl;
//cout << endl;
//cout << "Computer needs to be set 1 Hour, 5 minutes, and 23 seconds ahead of cell phone:" <<endl;
return 0;
}
包括
包括“clockType.h”
使用名称空间std
int main()
{
int cellHours;
int cellMinutes;
int cellSeconds;
int computerHours;
int computerMinutes;
int computerSeconds;
cout << "Please tell me the hour on your cell phone: ";
cin >> cellHours;
cout << endl;
cout << "Please tell me the minute on your cell phone: ";
cin >> cellMinutes;
cout << endl;
cout << "Please tell me the second on your cell phone: ";
cin >> cellSeconds;
cout << endl;
cout << endl;
cout << "Please tell me the hour on your computer: ";
cin >> computerHours;
cout << endl;
cout << "Please tell me the minute on your computer: ";
cin >> computerMinutes;
cout << endl;
cout << "Please tell me the second on your computer: ";
cin >> computerSeconds;
cout << endl;
cout << endl;
cout << "=================================================" << endl;
cout << endl;
cout << "Your cell phone time is: " << endl;
ClockType cellPhoneClock;
cellPhoneClock.setTime(cellHours, cellMinutes, cellSeconds);
cellPhoneClock.printTime();
cout << endl;
cout << "Your computer time is: " << endl;
ClockType myComputerClock;
myComputerClock.setTime(computerHours, computerMinutes, computerSeconds);
myComputerClock.printTime();
cout << endl;
if(!cellPhoneClock.equalTime(myComputerClock))
{
cout << "Both clocks do not have equal times" << endl;
cout << "Setting myComputerClock to the cellPhoneClock time" << endl;
int hours, minutes, seconds;
cellPhoneClock.getTime(hours, minutes, seconds);
myComputerClock.getTime(hours, minutes, seconds);
}
else
{
cout << "Both clocks have equal times" << endl;
}
cout << endl << "Final cell phone time is: ";
cellPhoneClock.printTime();
cout << endl << "Final computer time is: ";
cellPhoneClock.printTime();
cout << endl;
return 0;
}
下面是我正确的代码,它确实有效 testClockType.cpp
#include <iostream>
#include "clockType.h"
using namespace std;
int main()
{
int cellHours;
int cellMinutes;
int cellSeconds;
int computerHours;
int computerMinutes;
int computerSeconds;
cout << "Please tell me the hour on your cell phone: ";
cin >> cellHours;
cout << endl;
cout << "Please tell me the minute on your cell phone: ";
cin >> cellMinutes;
cout << endl;
cout << "Please tell me the second on your cell phone: ";
cin >> cellSeconds;
cout << endl;
cout << endl;
cout << "Please tell me the hour on your computer: ";
cin >> computerHours;
cout << endl;
cout << "Please tell me the minute on your computer: ";
cin >> computerMinutes;
cout << endl;
cout << "Please tell me the second on your computer: ";
cin >> computerSeconds;
cout << endl;
cout << endl;
cout << "=================================================" << endl;
cout << endl;
cout << "Your cell phone time is: " << endl;
ClockType cellPhoneClock;
cellPhoneClock.setTime(cellHours, cellMinutes, cellSeconds);
cellPhoneClock.printTime();
cout << endl;
cout << "Your computer time is: " << endl;
ClockType myComputerClock;
myComputerClock.setTime(computerHours, computerMinutes, computerSeconds);
myComputerClock.printTime();
cout << endl;
if(!cellPhoneClock.equalTime(myComputerClock))
{
cout << "Both clocks do not have equal times" << endl;
cout << "Setting Computer clock to the cell Phone Clock time" << endl;
int hours, minutes, seconds;
cellPhoneClock.getTime(hours, minutes, seconds);
myComputerClock.getTime(hours, minutes, seconds);
}
else
{
cout << "Both clocks have equal times" << endl;
}
cout << endl << "Final cell phone time is: ";
cellPhoneClock.printTime();
cout << endl << "Final computer time is: ";
cellPhoneClock.printTime();
cout << endl;
//cout << "===================================================" << endl;
//cout << endl;
//cout << "Computer needs to be set 1 Hour, 5 minutes, and 23 seconds ahead of cell phone:" <<endl;
return 0;
}
这比您正在查看的错误多得多。请重新添加生成错误消息的代码的最小上下文量,并包括错误消息的实际文本。我已添加了所有代码,所有错误都是行旁边的注释。总共有25个错误请不要随机编程语法猜测。减少到20个错误,我不是在猜测我只是没有做这个设置很长时间,我仍然learning@JessicaDuncan专业提示:提供有助于获得更多用户的关注:)
#include <iostream>
#include "clockType.h"
using namespace std;
int main()
{
int cellHours;
int cellMinutes;
int cellSeconds;
int computerHours;
int computerMinutes;
int computerSeconds;
cout << "Please tell me the hour on your cell phone: ";
cin >> cellHours;
cout << endl;
cout << "Please tell me the minute on your cell phone: ";
cin >> cellMinutes;
cout << endl;
cout << "Please tell me the second on your cell phone: ";
cin >> cellSeconds;
cout << endl;
cout << endl;
cout << "Please tell me the hour on your computer: ";
cin >> computerHours;
cout << endl;
cout << "Please tell me the minute on your computer: ";
cin >> computerMinutes;
cout << endl;
cout << "Please tell me the second on your computer: ";
cin >> computerSeconds;
cout << endl;
cout << endl;
cout << "=================================================" << endl;
cout << endl;
cout << "Your cell phone time is: " << endl;
ClockType cellPhoneClock;
cellPhoneClock.setTime(cellHours, cellMinutes, cellSeconds);
cellPhoneClock.printTime();
cout << endl;
cout << "Your computer time is: " << endl;
ClockType myComputerClock;
myComputerClock.setTime(computerHours, computerMinutes, computerSeconds);
myComputerClock.printTime();
cout << endl;
if(!cellPhoneClock.equalTime(myComputerClock))
{
cout << "Both clocks do not have equal times" << endl;
cout << "Setting Computer clock to the cell Phone Clock time" << endl;
int hours, minutes, seconds;
cellPhoneClock.getTime(hours, minutes, seconds);
myComputerClock.getTime(hours, minutes, seconds);
}
else
{
cout << "Both clocks have equal times" << endl;
}
cout << endl << "Final cell phone time is: ";
cellPhoneClock.printTime();
cout << endl << "Final computer time is: ";
cellPhoneClock.printTime();
cout << endl;
//cout << "===================================================" << endl;
//cout << endl;
//cout << "Computer needs to be set 1 Hour, 5 minutes, and 23 seconds ahead of cell phone:" <<endl;
return 0;
}
#include <iostream>
#include "clockType.h"
class ClockType;
void ClockType::setTime (int hours, int minutes, int seconds)
{
if ( 0 <= hours && hours < 24 )
hr = hours; //added int to initialize
else
hr = 0;
if ( 0 <= minutes && minutes < 60 )
min = minutes; //added int to initialize
else
min = 0;
if ( 0 <= seconds && seconds < 60 )
sec = seconds; //added int to initialize
else
sec = 0;
}
void ClockType::getTime (int& hours, int& minutes, int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
void ClockType::printTime() const
{
if (hr < 10)
cout << "0";
cout << hr << ":";
if (min < 10)
cout << "0";
cout << min << ":";
if (sec < 10)
cout << "0";
cout << sec << ":";
}
void ClockType::incrementHours()
{
hr++;
if (hr > 23)
hr = 0;
}
void ClockType::incrementMinutes()
{
min++;
if (min > 59)
{
min = 0;
incrementHours(); //increment hours
}
}
void ClockType::incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes(); //increment minutes
}
}
bool ClockType::equalTime (ClockType& myComputerClock)const
{
return (hr == myComputerClock.hr
&& min == myComputerClock.min
&& sec == myComputerClock.sec);
}
//ClockType::clockType()
//error: ISO C++ forbids declaration of ‘clockType’ with no type
//error: no ‘int ClockType::clockType()’ member function declared in class ‘ClockType'
//{
// hr = 0;
// min = 0;
// sec = 0;
//}
void ClockType::clockType(int hours, int minutes, int seconds)
//error: ISO C++ forbids declaration of ‘clockType’ with no type
//error: no ‘int ClockType::clockType(int, int, int)’ member function declared in class ‘ClockType’
{
setTime(hours, minutes, seconds);
}
#ifndef CLOCKTYPE_H
#define CLOCKTYPE_H
using namespace std;
class ClockType
{
public:
void setTime (int hours, int minutes, int seconds);
void getTime (int& hours, int& minutes, int& seconds) const;
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(ClockType& myComputerClock) const;
void clockType(int hours, int minutes, int seconds);
void clockType();
//void newTime (
private:
int hr;
int min;
int sec;
};
#endif