我正在尝试提示用户输入数据,然后调用该函数以从“类”函数中打印出数据……下面是我的代码,它返回奇怪的数字。
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
class planet
{
public:
int id_planet;
float x,y,z;
};
void report_planet_properties(planet P)
{
cout<<"Planet's ID: "<<P.id_planet<<endl;
cout<<"Planet's coordinates (x,y,z): ("<<P.x<<","<<P.y<<","<<P.z<<")"<<endl;
}
void set_planet_properties(planet Q)
{
cout<<"Enter planet's ID: ";
cin>>Q.id_planet;
cout<<"Enter planet's coordinates (x,y,z): ";
cin>>Q.x>>Q.y>>Q.z;
}
int main()
{
planet G;
set_planet_properties(G);
report_planet_properties(G);
}