can not build an object of type person unless you give your name, surname and age when built .
Last edited on
obiect[3] does not exist.
Persoana obiect[3]; // creates an array of 3 instances of Persoana numbered
obiect[0], obiect[1],obiect[2]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
class Persoana
{
private:
string name;
string prenume;
int varsta;
public:
void setData(string x,string y,int v)
{
name = x;
prenume = y;
varsta = v;
}
void getData()
{
cout << "\nname:" << name << "\nprenume:" << prenume << "\nvarsta:" << varsta << endl;
}
};
int main()
{
Persoana obiect[3];
obiect[0].setData("xyz","pqr",0);
obiect[0].getData();
obiect[1].setData("abc","efg",0);
obiect[1].getData();
obiect[2].setData("dada","dsadad",0);
obiect[2].getData();
// system("pause");
return 0;
}
|
Last edited on