Question

In: Computer Science

Define a class called Goals that has the following requirements in c++: a function called set...

Define a class called Goals that has the following requirements in c++:
  • a function called set that takes 3 int parameters that are goals for "fame", "happiness" and "money". The function returns true and saves the values if they add up to exactly 60, and returns false otherwise (you may assume the parameters are not negative)
  • a functions satisfies that takes 3 int parameters and returns true if each parameter is at least as large as the saved goal, false otherwise

Solutions

Expert Solution

CODE

#include<iostream>
using namespace std;
class Goals {        // The class
public:              // Access specifier
    bool set(int fame,int happiness,int money) { // Method/function defined inside the class
        if(fame>=10 && happiness>=15 && money >=12) //returns true only if fame>=10,happiness>=15 and money=12; else false
        {
            if((fame+happiness+money)>=60) //returns true only if fame+happiness+money >= 60 otherwise false
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
};

int main() {
    Goals obj;
    int fame,happiness,money;
    cout<<"enter fame happiness money respectively"<<endl;
    cin>>fame>>happiness>>money;    // Create an object of MyClass
    if(obj.set(fame,happiness,money))
        cout <<"result of your goal is true"<< endl;
    else
        cout <<"result of your goal is false"<< endl;
return 0;
}

OUTPUT


Related Solutions

in C++ Requirements: Write a program that creates a new class called Customer. The Customer class...
in C++ Requirements: Write a program that creates a new class called Customer. The Customer class should include the following private data: name - the customer's name, a string. phone - the customer's phone number, a string. email - the customer's email address, a string. In addition, the class should include appropriate accessor and mutator functions to set and get each of these values. Have your program create one Customer objects and assign a name, phone number, and email address...
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main...
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main function, instantiate the SinglyLinkedList class. Your program should provide a user loop and a menu so that the user can access all the operators provided by the SinglyLinkedList class. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
In C++, implement a class called setOper that provides several simple set operations. The class only...
In C++, implement a class called setOper that provides several simple set operations. The class only needs to deal with sets that are closed intervals specified by two real numbers; for example, the pair (2.5, 4.5) represent the interval [2.5, 4.5]. The following operations should be supported: - Check if the value x belongs to the given interval. - Check if the value x belongs to the intersection of two intervals. - Check if the value x belongs to the...
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
Create a class that generates permutations of a set of symbols. Requirements The class must be...
Create a class that generates permutations of a set of symbols. Requirements The class must be named PermutationGenerator. The PermutationGenerator class has two methods as follows. hasNext This method has no parameters.  It returns true if at least one permutation remains to be generated. next This method has no parameters.  It returns an array of the symbols (char[]) in a permutation (if any remain) or null otherwise. The following main method MUST be used, with NO CHANGES to test your class. public static void main(String[] args) { int count = 0; PermutationGenerator pg...
In C++, create a class to hold a set of strings called setTree. setTrees contain copies...
In C++, create a class to hold a set of strings called setTree. setTrees contain copies of the strings inserted so that the strings cannot be changed due to the fact that changing the strings inside the set could break the binary search tree. The strings are case sensitive. TreeSet implements the following: bool add(const string& s) -- add s to the set, if it's not already there. Return true if the set changed, false otherwise. void clear() -- remove...
Have to use C language Pseudocode A #define called BITS should be set at the top...
Have to use C language Pseudocode A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This define should be used throughout the entire program when setting/using array sizes/max element. This define will also be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16. Part of the grading process will be...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y),...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of your new point and retrieve their values. Write an Objective-C program to implement your new class and test it (main section of the file). Your test program needs to create two instances of your class. Make sure your program test prints out the values that you have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT