In: Computer Science
WRITE IN C++
Create a class named Coord in C++
Class has 3 private data items
int xCoord;
int yCoord;
int zCoord;
write the setters and getters. They should be inline functions
void setXCoord(int) void setYCoord(int) void setZCoord(int)
int getXCoord() int getYCoord() int getZCoord()
write a member function named void display() that displays the data items in the following format
blank line
xCoord is ????????
yCoord is ????????
zCoord is ????????
Blank line
Example
blank line
xCoord is 101
yCoord is -234
zCoord is 10
Blank line
Complete code in C++:-
#include <bits/stdc++.h>
using namespace std;
class Coord {
// Private instance variables
private:
int xCoord;
int yCoord;
int zCoord;
// Public methods.
public:
// Constructor.
Coord(int xCoord, int yCoord, int zCoord) {
this->xCoord = xCoord;
this->yCoord = yCoord;
this->zCoord = zCoord;
}
// Setter methods
inline void setXCoord(int xCoord) {
this->xCoord = xCoord;
}
inline void setYCoord(int yCoord) {
this->yCoord = yCoord;
}
inline void setZCoord(int zCoord) {
this->zCoord = zCoord;
}
// Getter methods.
inline int getXCoord() {
return this->xCoord;
}
inline int getYCoord() {
return this->yCoord;
}
inline int getZCoord() {
return this->zCoord;
}
// Display method.
void display() {
cout << '\n';
cout << "xCoord is " <<
this->xCoord << '\n';
cout << "yCoord is " <<
this->yCoord << '\n';
cout << "zCoord is " <<
this->zCoord << '\n';
cout << '\n';
}
};
// Main function
int main(void)
{
// Creating object of 'Coord' class.
Coord point(101, -234, 10);
// Displaying value of instance variables.
point.display();
return 0;
}
Screenshot of output:-