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,...

  • 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...

  • [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...

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

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
ADVERTISEMENT