上課的時候老師提到了個這個東西,然后給了代碼實例,可是無論如何執行main.cpp都會有些錯誤Example DATE class – Using METHOD Three?File 1 - Date.h? ?Header file?#pragma once? ? ? ? // needed to work class Date { public:? ? ?void get();? ? ? // function header for inputting the date? ? ?void write();? ? // function header for outputting the date private:? ? ?int month;? ? ? ?// month (between 1 and 12)? ? ?int day;? ? ? ? ?// day (between 1 and 31)? ? ?int year;? ? ? ? // year (between 0 and 99) }? ????File 2 – Date.cpp? Implementation file?#include <iostream> #include <iomanip> using namespace std; #include "Date.h"? // Include the library/file name of the class in quotes??void Date::get() {? ? ?char slash;? ? // Allows for inputting in the format MM/DD/YY? ? ?cin >> month >> slash >> day >> slash >> year; }??void Date::write() {? ? ?cout << "The date you entered was: " << setw(2) << month << "/" << setw(2) << day << "/" << setw(2) << year << endl; }???File 3 – Driver/Test fileImp.Date.cpp??#include <iostream> #include <iomanip> using namespace std; #include "Date.h"? ? ? // include DATE class header file name??int main () {? ? ?Date aDate;? ? ? ? // declaring A as a type Date??? ? cout << "Enter a date in the form MM/DD/YY:? \n";? ? ?aDate.get();? ? ? ?// Function which will input our date? ? ?aDate.write();? ? ?// Function which will output our date? ? ?return 0;?
- 0 回答
- 0 關注
- 907 瀏覽
添加回答
舉報
0/150
提交
取消