Question

I need help making this in C++ Asap! If you feel information is missing, or provided...

I need help making this in C++ Asap!

If you feel information is missing, or provided information is incorrect, make assumptions but clearly state your assumptions.

You should NEVER use global variables. Other than the main() function, there should be no global functions in your code. Other than the test() function not other function needs to be a static function in this problem.

Let us say you find a consulting opportunity for a regional real-estate company that wants you to write a class to do statistical analysis that also keeps track of all the houses sold in your area. There are currently 100 houses in the region of their operation and they are never are expected to store more than 200 sales.

They want you to store the sales price in a local array of this class as soon as the house is sold. Only sale price is stored, the address or the date of sale or any other data is not stored by this class.

They also want to be able to determine the maximum price of all the houses sold based on the current entries in this array.

You have to write a class that provided following functions:

void addHouseSale(double salePrice); //Adds the house sale to the sold[] array.

double calculateMaximumPrice();

The class must implement an array called "sold". You will determine the capacity of the array need in your program and what you need to maintain how many houses have been sold so far.

(You have to make the decision on how many data members you need in addition array. No! this problem does not need dynamic memory allocation).

Your program will assume that the history is started fresh, every time you execute the program. That is: the first call to addHouseSale(double salePrice) will make the first entry into the array.

Please implement a print() function that prints all of the data members of the class in a friendly manner.

Please implement a static test() function that tests all other functions, and at least 5 new entries into the array.

Please make sure that you use "Preformatted" style rather than "Paragraph" for the entire code and ensure it is readable and properly indented.

You have to provide

You are not required to show code separated by files. You can paste all of your code in the following edit box (using "Preformatted" style).

complete contents of the .h file: [18]

all system includes [1]

all #define's you need [1]

class declaration that includes:

Constructor [2]

all function declarations (including test, and print functions) [8]

the array declaration [4]

any other variables you need to make this work [2]

complete contents of the .cpp file that includes complete definitions (implementation) of: [57]

Constructor  

addHouseSale(double salePrice) function [5 points]

calculateMaximumPrice() function [20 points]

print() function [10 points]

test() function [20 points]

main function that simply calls the test() function. [2 points]

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

// houseSale.h file containing the system includes, # defines and class declaration

#ifndef HOUSESALE_H_

#define HOUSESALE_H_

// system includes

# include<iostream>

# define MAX_SALE 200 // define maximum number of sales

using namespace std;

// class defining the sales

class HouseSale{

               private :

                              double sold[MAX_SALE]; // array storing the sale prices. Maximum size :00

                              int sales; // variable to hold the number of sales

               public:

                              // constructor

                              HouseSale();

                              void addHouseSale(double salePrice); //Adds the house sale to the sold[] array.

                              double calculateMaximumPrice(); // calculate and return the maximum sale price

                              void print(); // print the variables of the class

                              static void test();// test the functions of the class

};

// end of HouseSale class

#endif /* HOUSESALE_H_ */

// end of houseSale.h

// houseSale.cpp implementing the class HouseSale and the main function

# include "houseSale.h"

// implementation of class HouseSale

HouseSale::HouseSale()

{

               sales=0;

}

void HouseSale::addHouseSale(double salePrice)

{

               if(sales < MAX_SALE)

               {

                              sold[sales] = salePrice;

                              sales++;

               }

}

double HouseSale::calculateMaximumPrice()

{

               double max =0;

               if(sales > 0)

                              max = sold[0];

               for(int i=1;i<sales;i++)

               {

                              if(sold[i] > max)

                                             max = sold[i];

               }

               return max;

}

void HouseSale::print()

{

               cout<<"\n Number of sales : "<<sales;

               if(sales > 0){

                              cout<<"\n Sales details : ";

                              for(int i=0;i<sales;i++)

                                             cout<<"\n Sale price "<<(i+1)<<" : "<<sold[i];

               }

}

void HouseSale::test()

{

               HouseSale hSale;

               hSale.addHouseSale(200.25);

               hSale.addHouseSale(450.5);

               hSale.addHouseSale(600);

               hSale.addHouseSale(500.85);

               hSale.addHouseSale(760);

               hSale.print();

               cout<<"\n Maximum sale price :"<<hSale.calculateMaximumPrice();

}

int main()

{

               HouseSale::test(); // call the test function of HouseSale class

               return 0;

}

// end of houseSale.cpp

Output:

Number of sales5 Sales details: Sale price 1 200.25 Sale price 2 : 450.5 Sale price 3 : 600 Sale price 4 : 500.85 Sale price

Add a comment
Know the answer?
Add Answer to:
I need help making this in C++ Asap! If you feel information is missing, or provided...
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
  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • Hi I need help doing this problem *The program must re-prompt as long as invalid input...

    Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • Hey everyone, I need help making a function with this directions with C++ Language. Can you...

    Hey everyone, I need help making a function with this directions with C++ Language. Can you guys use code like printf and fscanf without iostream or fstream because i havent study that yet. Thanks. Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the...

  • I need help making my array into a function that can called by the main function...

    I need help making my array into a function that can called by the main function using my program. This is C programming int prime (int x) { int i; i = 2; while (i < x) { if (x % i == 0) return 0; i++; } return 1; } int main (void){ int n; scanf ("%d", &n); if (n < 1) { printf ("Error: at least one data value must be provided.\n"); return 1; } int a[n]; int...

  • i need help making this C++ code. Lab #2 Assignments: Numbers Class that translate whole dollar...

    i need help making this C++ code. Lab #2 Assignments: Numbers Class that translate whole dollar amounts in the range 0 through 9999 into an English description of the number. Numbers Class Design a class numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand...

  • You should implement several functions that the Phone Contacts program will need Each function with take...

    You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...

  • I need help with the following code... Instructions: This lab builds on the skills from Lab...

    I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...

  • This homework involves ADDING MEMBER FUNCTIONS to ArrayBag.h. This homework is important because ...

    This homework involves ADDING MEMBER FUNCTIONS to ArrayBag.h. This homework is important because we do some thing like this on exams. All you will need to submit is your member function code BUT your code should compile and run if I were to add it to ArrayBag.h. That means you should put your code in ArrayBag.h and make sure it compiles before submitting. You should test with a simple main. DO NOT submit main or your ArrayBag.h file just submit...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solu...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...

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