Question

C++ Program: getter & setter methods

Author the C++ class (both a .h file and a .cpp fi

0 0
Add a comment Improve this question Transcribed image text
Answer #1

HI, Please find my implementation:

Please let me know in case of any issue.

########## RadioStation.h ###############

#include <string>
using namespace std;

class RadioStation{
public:
   RadioStation(string name, string mysicStyle, double broadcastedValue);
   string getName();
   double getBroadcastValue();
   string getStyle();

   void setName(string name);
   void setStyle(string style);
   void setBroadcastValue(double value);

private:
   string my_Name;
   double my_BroadcastValue;
   string my_MusicStyle;
};

############## RadioStation.cpp ##############

#include <string>
#include "RadioStation.h"
using namespace std;

RadioStation::RadioStation(string name, string musicStyle, double broadcastedValue){
   my_Name = name;
   my_BroadcastValue = broadcastedValue;
   my_MusicStyle = musicStyle;
}

string RadioStation::getName(){
   return my_Name;
}

double RadioStation::getBroadcastValue(){
   return my_BroadcastValue;
}

string RadioStation::getStyle(){
   return my_MusicStyle;
}

void RadioStation::setName(string name){
   my_Name = name;
}

void RadioStation::setStyle(string style){
   my_MusicStyle = style;
}

void RadioStation::setBroadcastValue(double value){
   my_BroadcastValue = value;
}

############## RadioStationTest.cpp ###############

#include <iostream>
#include "RadioStation.h"
using namespace std;

int main(){

   // creating Object of RadioStation
   RadioStation r1("Daltonganj_FM_Radio", "Classical", 45.6);

   cout<<"Name: "<<r1.getName()<<endl;
   cout<<"Music Style: "<<r1.getStyle()<<endl;
   cout<<"Broadcasted Value: "<<r1.getBroadcastValue()<<endl;

   r1.setBroadcastValue(56.4);

   cout<<"Broadcasted Value: "<<r1.getBroadcastValue()<<endl;

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ Program: getter & setter methods Author the C++ class (both a .h file and a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Program in C++ We need commentaries in the program setter and getter we need...

    Create a Program in C++ We need commentaries in the program setter and getter we need the Output of the program and the code compiling and use a file. You will design a program that plays hangman. The rules are explained here. The program must at least include one class and client code. It does not require graphical representation but to keep track of the player misses. The host is the computer. The user has eight chances for error (otherwise,...

  • Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create...

    Exercise: (2) Create a class called Dog containing two Strings: name and says. In main(), create two dog objects with names “spot” (who says, “Ruff!”) and “scruffy” (who says, “Wurf!”). Then display their names and what they say. Be sure to use setter and getter methods to assign(set) and retrieve(get) values for both Strings name and says. Your Task: Create the program using Netbeans and easyUML (i.e: Open a project in NetBeans then create the classes, attributes, and methods in...

  • [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...

    [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is read-only; 2)a getter and setter for the lecturer attribute, so that it is readable and writable; 3)a constructor that creates the associations shown in the UML diagram; 4)an enrolStudent method that adds a given Student object into the 'enrolled' set; 5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed,...

  • Create a C++ console program that defines a class named EvenNumber that represents an even number....

    Create a C++ console program that defines a class named EvenNumber that represents an even number. Create the class inside a separate header file (.h) and then include this header in your main source code file. The class should have one private integer data field to store the even number. The default constructor should initialize the data field to 0. Also define a 1-arg constructor that initializes the object with the specified value. Define a public getter method named getValue...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • On Dev C++ Using the header file provided below "myClock.h", implement a C++ program that present...

    On Dev C++ Using the header file provided below "myClock.h", implement a C++ program that present the user with the following menu: "Press 1 to read the time." "Press 2 to enter a new time." "Press 3 to exit." -------------------------------------------------------------- Submit both file, myClock.h and your implementation .cpp myClock.h class myClock { public: myClock(); ~myClock(){}; void setTime(int, int, int); // Add the getter function prototype here . private: int hour; int minute; int second; };

  • How can you change this function from the main program “struct point” to a “class point”...

    How can you change this function from the main program “struct point” to a “class point” into new .h and .cpp projects. Make all the member variables private. Add getter and setter methods for each member variable. ///////////////////////////////////////////////// struct point { int x,y;}; int main() { point plat[20]; for (int i=0;i<10;i++) {   plat[i].x=rand()%400; plat[i].y=rand()%533; } /////////////////////////////////////////////////////////////

  • [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...

    [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is read-only; 2)a getter and setter for the lecturer attribute, so that it is readable and writable; 3)a constructor that creates the associations shown in the UML diagram; 4)an enrolStudent method that adds a given Student object into the 'enrolled' set; 5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed,...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • PLEASE DO IN JAVA 1) Create interface named “Person” which exposes getter/setter methods for the person’s...

    PLEASE DO IN JAVA 1) Create interface named “Person” which exposes getter/setter methods for the person’s name and college ID: 1. getName 2. setName 3. getID 4. setID. The college ID is represented as “int”. Define two classes, Student and Faculty, which implement Person. Add field GPA to Student and department to faculty. Make them private and create corresponding getters (getGPA, getDepartment) and setters (setGPA, setDepartment). Use appropriate types. 2) Write a class College, which contains the name of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT