Question

In: Computer Science

C++ language Write a program that accepts as input the base price and the finished area...

C++ language

Write a program that accepts as input the base price and the finished area in square feet of the three models.

The program outputs the model(s) with the least price per square foot in the following format:

If the colonial model is the least price, output:

  • The price per square foot of the colonial model is the least.

If the split-entry model is the least price, output:

  • The price per square foot of the split-entry model is the least.

If the single-story model is the least price, output:

  • The price per square foot of the single-story model is the least.

If the colonial and split-entry models tie for the least price, output:

  • The price per square foot of the colonial and split-entry models tie for the least.

If the colonial and single-story models tie for the least price, output:

  • The price per square foot of the colonial and single-story models tie for the least.

If the single-story and split-entry models tie for the least price, output:

  • The price per square foot of the single-story and split-entry models tie for the least.

Finally, if all three tie for the least price, output:

  • The price per square foot all three models are the same.

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;

int main() {
   cout<<"Enter the square feet area of various models and their base prices:"<<endl;
   float f1,f2,f3;
   float bprice1,bprice2,bprice3;
   float fprice1,fprice2,fprice3;
   cout<<"Enter the base price for colonial model:";
   cin>>bprice1;
   cout<<"Enter the square feet area of colonial model:";
   cin>>f1;
   fprice1 = f1/bprice1;
   cout<<"Enter the base price for split-entry model:";
   cin>>bprice2;
   cout<<"Enter the square feet area of split-entry model:";
   cin>>f2;
   fprice2 = f2/bprice2;
cout<<"Enter the base price for single-story model:";
   cin>>bprice3;
   cout<<"Enter the square feet area of single-story model:";
   cin>>f3;
   fprice3 = f3/bprice3;
  
   if(fprice1==fprice2 && fprice1==fprice3)
   {
   cout<<"The price per square foot all the three models are same";
   }
   else if(fprice1==fprice2 && fprice1<fprice3)
   {
   cout<<"The price per square foot for colonial and split-entry models tie for the least";
   }
   else if(fprice1==fprice3 && fprice1<fprice2)
   {
   cout<<"The price per square foot for colonial and single-story models tie for the least";
   }
   else if(fprice2==fprice3 && fprice2<fprice1)
   {
   cout<<"The price per square foot for split-entry and single-story models tie for the least";
   }
   else if(fprice1<fprice2 && fprice1<fprice3)
   {
   cout<<"The price per square foot of the colonial model is the least";
   }
   else if(fprice2<fprice1 && fprice2<fprice3)
   {
   cout<<"The price per square foot of the split-entry model is the least";
   }
   else if(fprice3<fprice1 && fprice3<fprice2)
   {
   cout<<"The price per square foot of the single-story model is the least";
   }
  
   return 0;
}

Execution screenshot:


Related Solutions

2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT