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

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 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...
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and...
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and price of items in a grocery store. Encapsulate the fields and provide getters and setters. Create an application for a grocery store to calculate the total bill for each customer. Such program will read a list of products purchased and the quantity of each item. Each line in the bill consists of: ProductName ProductPrice Quantity/Weight The list of items will be terminated by “end”...
In C++ please. 3. Define templates and explain their purpose. Differentiate standalone function and class templates....
In C++ please. 3. Define templates and explain their purpose. Differentiate standalone function and class templates. Give an example of a class template and a function template.
***Define a class called Pizza that has member variables to track the type of pizza (either...
***Define a class called Pizza that has member variables to track the type of pizza (either deep dish, hand tossed, or pan) along with the size (either small, medium, or large) and the number of pepperoni or cheese toppings. You can use constants to represent the type and size. Include mutator and accessor functions for your class. Create a void function, outputDescription( ) , that outputs a textual description of the pizza object. Also include a function, computePrice( ) ,...
Consider a Class C network 200.100.100.0. and divide it into 10 subnets, according the following requirements...
Consider a Class C network 200.100.100.0. and divide it into 10 subnets, according the following requirements of number of hosts on each subnet. Draw a diagram clearing labelling each subnet with its name (i.e. A, B, C etc.) and subnet ID. (Use variable length subnet mask) 30 Hosts 12 Hosts 28 Hosts 10 Hosts 25 Hosts 25 Hosts 30 Hosts 5 Hosts 15 Hosts 10 Hosts
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT