好的,这是程序
#include<iostream>
#include<iomanip>
using namespace std;
class My_Date{
private:
int year;
int month;
int day;
public:
My_Date(){}
~My_Date(){}
void setDate(int recieve_year,int recieve_month,int recieve_day)
{
year = recieve_year;
month = recieve_month;
day = recieve_day;
}
int getYear()
{
return year;
}
int getMonth()
{
return month;
}
int getday()
{
return day;
}
};
class ROrder{
private:
unsigned int order_ID;
My_Date Order_Date;
double amount;
double tip;
double totalamount();
public:
void setorder_ID(unsigned int recieve_order_ID)
{
order_ID = recieve_order_ID;
}
void setamount(double recieve_amount)
{
amount = recieve_amount;
}
void settip(double recieve_tip)
{
tip = recieve_tip;
}
double getorder_ID()
{
return order_ID;
}
double getamount()
{
return amount;
}
double gettip()
{
return tip;
}
void setDate(int y, int m, int d)
{
Order_Date.setDate(y,m,d);
}
};
int main()
{
int ID,send_Year,send_Month,send_Day,send_amount;
class ROrder Rice;
cout << "Enter Order ID: ";
cin >> ID;
cout << "Enter Date (YYYY/MM/DD): ";
cin >> send_Year >> send_Month >> send_Day;
Rice.setorder_ID(ID);
Rice.setDate(send_Year,send_Month,send_Day);
cout << "Your Order ID is: " << Rice.getorder_ID()<<endl;
return 0;
}
从程序中我认为我已经能够访问My_Date类以将值放入年月和日变量中 现在我唯一不知道的是如何将值返回给主类,因为my_date类是ROrder类的私有类。 认为代码不完整我只需要帮助处理来自my_date类的返回值
答案 0 :(得分:1)
在课程<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="progressQs">
<span class="progressBarQs"><span class="reportPrecentage"></span></span>
</div>
<div class="form">
<div class="slider">
<div class="part part1">part1
Name: <input type="text">
Address: <input type="text">
location: <input type="text">
Gender: <input type="text">
How Long: <input type="text">
date: <input type="text">
</div>
<div class="part part2">part2</div>
<div class="part part3">part3</div>
</div>
</div>
<div class="buttonWrapper">
<button id="left">Left</button>
<button id="right">Right</button>
</div>
中,添加:
ROrder
在public:
int getYear(){
return Order_Date.getYear();
}
功能中,添加:
main
我不确定它是否解决了你的问题。
答案 1 :(得分:1)
答案 2 :(得分:1)
如果我理解正确,您希望返回内部类中的值。如果是这种情况,则需要在外部类中创建一个getter方法,这需要您在外部类中实例化该对象。