I took a class about class this time, but I don't understand, so I'm asking you a question. The language is c++.
You must create a class with a name and coordinates (x,y) and a program that generates two objects.
Header file
class Point { public: Point(std::string pname, int px, int py) {
}
std::string getName() { return name; }
int getX() { return x; }
int getY() { return y; }
void setName(std::string pname) { name = pname; }
void setX(int px) { x = px; }
void setY(int py) { y = py; }
private: std::string name; int x; int y; };
Source File include
using namespace std;
int main() {
c++
#include <iostream>
using namespace std;
class Point {
private:
string name;
int x;
int y;
public:
Point(string pname, int px, int py) {
setX(px);
setY(py);
setName(pname);
}
string getName() { return name; }
int getX() { return x; }
int getY() { return y; }
void setName(string pname) { name = pname; }
void setX(int px) { x = px; }
void setY(int py) { y = py; }
};
int main() {
Point test = Point("test", 2, 35);
cout << test.getName() << endl;
cout << test.getX() << endl;
cout << test.getY();
return 0;
};
© 2024 OneMinuteCode. All rights reserved.