Question

In: Computer Science

In C++ Please Problem   1:   How   to   calculate   a   home's   value   Housing economists have long used...

In C++ Please

Problem   1:   How   to   calculate   a   home's   value  


Housing economists have long used a home price/rent ratio as one way to gauge whether or not home prices are inflated or undervalued.


A housing P/E


The use of a price/rent ratio is analogous to employing a price/earnings ratio for stocks. When a stock price is high, and its earnings per share relatively low, the P/E is high. A high P/E often indicates that the stock is too expensive, and the share price is headed for a drop.
What someone is willing to pay to rent a place is that home's "earnings." And, just as in the stock market, a high home price related to the rental earnings mean homes values will probably drop.
For a specific look at how a home's P/E is determined, let's consider a home that is listed for either rent or sale in suburban Chicago.
The home has been rented for the past three years for $1,600 per month; so that is $19,200 per year. It is currently listed for sale at $400,000. Dividing the price by the total annual rent of $19,200 gives a "housing P/E" of 20.83. According to Moody's Economy.com, the long-run average housing P/E is 16, so a P/E of 20.83 suggests that this home may be somewhat overpriced.


For this programming project you will read in a list of housing prices and how much each house is rented for that are found in the attached HousingPrices.txt file. The file looks like this:


713047 1246
1605787 1979
1174719 1879
1018239 1700


Where the first value on each line is the price of the home, and the second number on each line is the price that this home currently rents for per month.
Read these numbers in from the file into 2 separate arrays of size 100, since there are 100 home prices/rents in the file. Do this part in your main method.   
Then use a for-loop to loop through the arrays and for each pair of values send them into a method that you will write called "getHousingPE". Your method will have two parameters; the price of the home and the current monthly rental rate of the home. Your method will calculate and then return the homes “housing P/E”.   
Check each homes returned P/E value and if the P/E value is greater than 16 you should write to the output “House # is somewhat overpriced”; where # is the number of the house in the file (1100). If the P/E is greater than 19 then you should write to the output “House # is way overpriced”. If the P/E is less than 12 then you should write to the output "“House # might be a good deal”. And if the P/E is less than 9 then you should write “Buy House #, it is a deal”. If the P/E is between 12-16 then output "House # is average".

Problem   2:   Determining   Left   or   Right    

For   this   programming   project   you   are   to   read   in   a   list   of   street   addresses   and   determine   how   many   of   those   addresses   are   on   the   right   side   of   the   street,   and   how   many   are   on   the   left.   The   street   addresses   file   is   a   text   file   that   looks   like:  
  
6 S 33rd St

6 Greenleaf Ave

618 W Yakima Ave

74 S Westgate St

3273 State St
  

You   can   determine   if   an   address   is   either   on   the   left   or   right   side   of   the   street   by   looking   at   the   number   of   the   address;   all   even   numbers   are   on   the   right   side   of   the   street,   and   all   odd   numbers   are   on   the   left   side   of   the   street.  
  
You   will   read   your   data   into   2   arrays;   an   integer   array   to   hold   the   street   number,   and   a   String   array   to   hold   the   rest   of   the   address.       These   will   be   parallel   arrays,   meaning   the   street   number   and   street   address   of   each   index   are   related   to   each   other.  
  
Remember   to   draw   a   picture   so   that   you   can   visualize   this.  
  
You   will   need   to   write   a   method   that   will   determine   if   each   house   is   on   the   left   or   right   side   of   the   street.  
  
You   will   call   this   method   for   every   street   address,   and   then   keep   a   count   of   how   many   houses   are   on   the   left   and   right   sides   of   the   street.  
  
The   output   should   be   the   street   number   and   address   and   then   whether   the   house   is   on   the   left   or   right   side   of   the   street:  
  
Address Left/Right

6649 N Blue Gum St left

4 B Blue Ridge Blvd right

8 W Cerritos Ave #54 right

639 Main St left


  

The   number   of   houses   on   the   left   and   right   sides   of   the   street   should   also   be   output.  

Solutions

Expert Solution

Code: For Program 1:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
    string rd_file;
    cin>>rd_file;
    ifstream read (rd_file);
  
    if (read.is_open()){
        ofstream out ("output");
        int h_price[100], m_rent[100];
        int i = 0;
      
        while( read >> h_price[i] >> m_rent[i] ) {
            i++;
        }
      
        string str;
        for(i=0; i<100; i++){
            float val = h_price[i] / (m_rent[i]*12);
            if(val < 9)
                str = "Buy House " + to_string(i+1) + " ,It is the deal.\n";
            else if(val < 12)
                str = "House " + to_string(i+1) + " might be a good deal.\n";
            else if(val < 16)
                str = "House " + to_string(i+1) + " is average.\n";
            else if(val < 19)
                str = "House " + to_string(i+1) + " is somewhat overpriced.\n";
            else
                str = "House " + to_string(i+1) + " is way overpriced.\n";
            out << str;
        }
    }
    return 0;
}

Screenshot:

Code: For Program 2:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string check(int n){
    if(n%2 == 0)
        return "Right";
    return "Left";
}

int main(){
    string f_name;
    cin>>f_name; //use x.txt
    ifstream read(f_name);
  
    if (read.is_open()){
        ofstream out ("output");
        int num[100];
        string address[100];
        int i = 0;
      
        while( read >> num[i]>> address[i] ) {
            i++;
        }
      
        string str; int left = 0, right = 0;
        for(i=0; i<100; i++){
            string side = check(num[i]);
            if(side == "Left")
                left++;
            right++;
            str = to_string(num[i]) + " " + address[i] +" " + side + "\n";
            out << str;
        }
      
        str = "\nThere are " + to_string(left) + " houses to the Left.";
        out << str;
        str = "\nThere are " + to_string(right) + " houses to the Right.";
        out << str;
        read.close();
        out.close();
    }
    return 0;
}

Output:

Hope you like the answer.

Please give it a like and your valuable feedback or any doubt.


Related Solutions

Long essay question: Question 2) Explain how economists calculate the rate of return that individuals get...
Long essay question: Question 2) Explain how economists calculate the rate of return that individuals get from investments in their human capital and basic empirical results of these calculations. A perfect answer will explain the types of costs/benefits included in these calculations, how the actual calculation is done (You are not expected to do this calculation) and empirical results. Use only material provided in this course to answer this question. (18 pts)
Please calculate the Big-O cost and explain how: 1) void recurX(long x) {           ...
Please calculate the Big-O cost and explain how: 1) void recurX(long x) {            if(x==0) System.out.print("*");   else { recurX(x/2); recurX(x/2); } } 2) void recurY(long y) {            if(n==0) return;            for(long i=0;i<y;i++) System.out.print("*"); recurY(n/2);        }
Please note that this problem have to use sstream library in c++ (1) Prompt the user...
Please note that this problem have to use sstream library in c++ (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number...
Please solve this problem, in c++ (algoritms) write code and explaination how to solve it! 1)...
Please solve this problem, in c++ (algoritms) write code and explaination how to solve it! 1) N numbers are given. The first K of them are sorted in ascending order, the remaining NK are also sorted in ascending order. Sort numbers in ascending order in O (N). Input data format N - number of numbers, K - number of numbers in the first half (sorted). Example input 10 6 1 2 5 6 8 9 3 4 7 12 Sample...
When using time value of money to calculate how long it will take to pay off...
When using time value of money to calculate how long it will take to pay off a debt, what do you solve for? A) Number of Periods B) Present Value C) Interest Rate D) Future Value
Problem 4: Coins Used java please You are given a target value in cents and some...
Problem 4: Coins Used java please You are given a target value in cents and some coins: quarters, dimes, nickels, and pennies (in that order). Your program should tell which coins add up to that target. input: 63 3 2 5 3 output: 63 cents = 2 quarters, 1 dimes, 0 nickels, 3 pennies Hints: Your recursive function can have ten int parameters: targetValue, valueSoFar, quartersLeft, dimesLeft, nickelsLeft, penniesLeft, quartersSpent, dimesSpent, nickelsSpent, penniesSpent. Base cases: 1. you hit the target...
Could you please explain this step by step? I do not understand how to calculate long...
Could you please explain this step by step? I do not understand how to calculate long end duration with the different prices? What is long end duration? Calculate the long end duration for a bond with a current price of £109.5, if its price drops to £108.5 when the yield curve steepens at the long end by 50bps; and if its price increases to £112.2 when the yield curve flattens at the long end by 50bps. Interpret the value of...
Problem 1: Recursive anagram finder please used Java please Write a program that will take a...
Problem 1: Recursive anagram finder please used Java please Write a program that will take a word and print out every combination of letters in that word. For example, "sam" would print out sam, sma, asm, ams, mas, msa (the ordering doesn't matter) input: cram output: cram crma carm camr cmra cmar rcam rcma racm ramc rmca rmac acrm acmr arcm armc amcr amrc mcra mcar mrca mrac macr marc Hints: Your recursive function should have no return value and...
If possible, please explain how to calculate with a Ti-84 Plus calculator. In the following problem,...
If possible, please explain how to calculate with a Ti-84 Plus calculator. In the following problem, check that it is appropriate to use the normal approximation to the binomial. Then use the normal distribution to estimate the requested probabilities. Do you try to pad an insurance claim to cover your deductible? About 44% of all U.S. adults will try to pad their insurance claims! Suppose that you are the director of an insurance adjustment office. Your office has just received...
Please explain in full how to work this problem below. I need a method to calculate...
Please explain in full how to work this problem below. I need a method to calculate this type of problems. Please help. Question The trial balance on 28 February 2013, the end of the financial year, reflected a total of R6 850 for rates expense. This total includes rates for March 2013. If there was a 10% increase in rates with effect from 01 September 2012, the amount that should be reflected as rates in the Profit and loss account...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT