0

私は C++ プログラミングが初めてで、プロジェクトの名前と期間を表示する単純なクラス プログラムを作成しました。

#include<iostream>
class project
{

public: 
std::string name;
int duration; 
};

int main ()
{
project thesis;  // object creation of type class
thesis.name = "smart camera"; //object accessing the data members of its class
thesis.duration= 6;

std::cout << " the name of the thesis is" << thesis.name << ;
std::cout << " the duration of thesis in months is" << thesis.duration;
return 0;

しかし今、クラスの get および set メンバー関数を使用して同じパラダイムをプログラムする必要があります。私は多少のようにプログラムする必要があります

#include<iostream.h>

class project
{

std::string name;
int duration; 

void setName ( int name1 ); // member functions set 
void setDuration( string duration1); 

};

void project::setName( int name1)

{

name = name1;

}


void project::setDuration( string duration1);

duration=duration1;

}

// main function

int main()
{
project thesis;  // object creation of type class

thesis.setName ( "smart camera" );
theis.setDuration(6.0);


//print the name and duration


return 0;

}

上記のコード ロジックが正しいかどうかはわかりません。誰かがそれを進める方法を教えてください。どうもありがとう

4

1 に答える 1