#C++ OOP Classes Question Help

1 messages · Page 1 of 1 (latest)

sacred sedge
#

I've been frustrated with this tutorial lately, I've tried my hardest to figure out how to do it but I can only type in the few basic ones (declare the classes, public and private members)
It might be caused by the question's wording that confuses me or the output that is also weird to me.

I think I've overload my construrctor wrongly and I would like to change it. Also, is should the default arguments be the two examples that I wanted to print out? I might need to get help with that.

Any help is appreciated! <@&1170904818810880060>

#

this is all i had came up with

#include <iostream>
#include <string>
#include <cstring>

using namespace std;

class Software {
private:
string data1, data2;

public:
Software(string x = "Dev C++", string y="RStudio");

Software(string x, string y) : data1(x), data2(y) {}

void getdata(string, string);

~Software() {}

};

class Hardware {
private:
char type1[20], type2[20];

public:
Hardware(const char* x = "Laptop", const char* y="Mouse");

Hardware(const char* x, const char* y) {
    strcpy(type1, x);
    strcpy(type2, y);
}

void gettype(char[20],char[20]);

~Hardware() {}

};

Software::Software(string x,string y) {
data1 = x;
data2 = y;
}

Hardware::Hardware(const char* x, const char* y) {
strcpy(type1, x);
strcpy(type2, y);
}

void Software :: getdata(string x, string y)
{
cout<<"Enter 2 softwares: "<<endl;
cin>>x>>y;
data1=x;
data2=y;
}

void Hardware :: gettype(char x[20], char y[20])
{
cout<<"Enter 2 hardwares: "<<endl;
cin>>x>>y;
strcpy(type1, x);
strcpy(type2, y);
}

int main() {
Software* sPtr;
Hardware hw[2];

cout<<"Two example softwares: "<<endl;
return 0;

}

lapis arrow
sacred sedge
#

thanks for your help! i've solved this question a while ago and i've figured it out