Question

In: Computer Science

WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items...

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

Solutions

Expert Solution

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:-


Related Solutions

C++ Classes & Objects Create a class named Student that has three private member: string firstName...
C++ Classes & Objects Create a class named Student that has three private member: string firstName string lastName int studentID Write the required mutator and accessor methods/functions (get/set methods) to display or modify the objects. In the 'main' function do the following (1) Create a student object "student1". (2) Use set methods to assign StudentID: 6337130 firstName: Sandy lastName: Santos (3) Display the students detail using get functions in standard output using cout: Sandy Santos 6337130
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
please write this in C # Create a Patient class which has private fields for patientid,...
please write this in C # Create a Patient class which has private fields for patientid, lastname, firstname, age, and email. Create public properties for each of these private fields with get and set methods. The entire lastname must be stored in uppercase. Create a main class which instantiates a patient object and sets values for each data item within the class. Display the data in the object to the console window.
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and...
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and height with setter and getter methods. A constructor that sets the values of base and height. A method named toString() that prints the values of base and height. A method named area() that calculates and prints the area of a triangle. Draw the UML diagram for the class. Implement the class. Q2: Write a Java program that creates a two-dimensional array of type integer...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an...
Part 1 Create a class named Room which has two private data members which are doubles...
Part 1 Create a class named Room which has two private data members which are doubles named length and width. The class has five functions: a constructor which sets the length and width, a default constructor which sets the length to 12 and the width to 14, an output function, a function to calculate the area of the room and a function to calculate the parameter. Also include a friend function which adds two objects of the room class. Part...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT