10.22 Lab 9: Classes and Objects In this lab, we will be writing classes and see how they work with data members and mem

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

10.22 Lab 9: Classes and Objects In this lab, we will be writing classes and see how they work with data members and mem

Post by answerhappygod »

10 22 Lab 9 Classes And Objects In This Lab We Will Be Writing Classes And See How They Work With Data Members And Mem 1
10 22 Lab 9 Classes And Objects In This Lab We Will Be Writing Classes And See How They Work With Data Members And Mem 1 (88.76 KiB) Viewed 69 times
c++ code
starter code:
// Lab 9: Defining a class
#include <iostream>using namespace std;
//a class Vacation hereclass Vacation{ private: string destination; int cost;
public: //write you getters setter here ?? setDestination(???){ //write your code here } ?? setCost(??){ //write your code here } ?? getDestination(???){ } ?? getCost(??){ } // write your constructor here Vacation(){ // write your code here.... } ??? compare (???){ //write your compare function here... }};
//-----------------------------------------------------------------------------------------------// *** DO NOT CHANGE ANYTHING BELOW THIS LINE ***int main(){
// Declarations Vacation holiday1; string destination; int cost; // ---- Stage 1 ---- Basic classdefinition, private data members, get() and set() functions cout << "Enter the Destination and amountrequested: (e.g. MachuPicchu 5): "; cin >> destination >> cost ;
// Test set() member functions holiday1.setDestination( destination); holiday1.setCost( cost); // Test get() member functions cout <<" You have requested for " << holiday1.getCost() << "000$ for" <<holiday1.getDestination() << endl; // ---- Stage 2 ---- Default constructor cout << "2. Using default constructor gives: "; // Invoke the default constructor and display the newShape Vacation holiday2; cout <<" You have requested for "<< holiday2.getCost() << "000$ for" <<holiday2.getDestination() << endl; //---- Stage 2 ---- compare two objects bool check = holiday1.compare(holiday2); if (check == true){ cout <<" You have requested for " << holiday2.getCost() << "000$ for " <<holiday2.getDestination() <<" before. " << endl; } else{ cout <<" You have notrequested for " << holiday2.getCost() << "000$for " <<holiday2.getDestination() <<" yet. " << endl; }
return 0;}//end main()
10.22 Lab 9: Classes and Objects In this lab, we will be writing classes and see how they work with data members and member functions. Imagine we lived in a world where everyone would be given money to travel anywhere in the world for a vacation. Where would you go, how much money would you request? Refer to the main to know what parameters the functions take and what they return. You are given a class Vacation with two data members a • destination (String) which represents either name of the country or city you wish to visit • cost (Integer) which represents the hypothetical amount in thousands of dollars you would request for Stage 1: Get, Set (1 Point) a) Write the set function for each data member: setDestination and setCost the main() accepts the user input for the respective field and passes it to the function. The set functions should take the user input and assign that value to the respective data member of the object. b) Write the get function for each data member: getDestination and getCost The function returns the values of the respective fields and which are displayed from main. Running the program should like: (input indicated in bold) Enter the Destination and amount requested: (e.g. MachuPicchu 5): MachuPicchu 5 You have requested for 5000$ for MachuPicchu Stage 2: Constructors (1 Point) a) Write a default constructor for the class to accept Alaska for destination name, 3 for cost as default values. Running the program should look like: You have requested 3000$ for Alaska. Stage 3: Compare Function (1 Point) a) Write a compare function which can compare the place and cost of your request and tell you if you have requested for that place or not yet. The compare function should **compare two objects and return true or false ** one with values Montana 3 and other with values Antartica 10. Your do not have print any messages it has been handled in the main. Running the program should look like: Enter the Destination and amount to compare: (e.g. Machu Picchu 5): Alaska 3 You have requested 3000$ for Alaska before. Running again should look like: Enter the Destination and amount to compare: (e.g. MachuPicchu 5): Antartica 10 You have not requested 10000$ for Antartica yet.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply