Question

Using basic c++ write a separate code for each of the following: 1. Area Rectangle •...

Using basic c++ write a separate code for each of the following:

1. Area Rectangle

• Write a program that asks the user to enter length and width of a rectangle and then display the rectangles area.

• Write the following functions

• getLength – prompt the user to enter length and return that value as a double

• getWidth – prompt the user to enter width and return that value as a double

• getArea – This method should take both the length and width as arguments and return the rectangles area.

• displayData – This method should accept length, width and area as arguments and display them in appropriate message.

• Output

Enter the rectangle's length: 21

Enter the rectangle's Width: 13.4

Length = 21.0

Width = 13.4

Area = 281.40000000000003

2. Financial Application

Write a function that computes future investment value at a given interest rate for a specified number of years.

FutureInvestmentValue = invAmount * ( 1 + monthlyInterestRate) **(numberOfYears*12)

Use the following function prototype double futureInvestmentValue(double invAmount, double monthlyInterestRate, int years). Write a test program that prompts the use to enter the investment amount and interest rate and prints a table that displays the future value for the years from 1 to 30 as shown below

Enter investment amount: 10000

Enter yearly interest rate: 6.25

Enter the year: 30

Years Future Value

1 10643.22

2 11327.81

---- -----

29   60969.97

30 64891.66

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

If you like the answer, please give a Thumps Up

Program 1

#include <iostream>
#include<iomanip>

using namespace std;
double getLength();
double getWidth();
double getArea(double length,double width);
void displayData(double length,double width,double area);

int main()
{
    double l,w,a;
    l=getLength();
    w=getWidth();
    a=getArea(l,w);
    displayData(l,w,a);

}
double getLength()
{
    double length;
    cout<<"Enter the rectangle's length: ";
    cin>>length;
    return length;
}


double getWidth()
{
    double width;
    cout<<"Enter the rectangle's width: ";
    cin>>width;
    return width;
}
double getArea(double length,double width)
{
    return(length*width);
}

void displayData(double length,double width,double area)
{
    cout<<"Length = "<<length<<endl;
    cout<<"Width = "<<width<<endl;
    cout<<"Area = "<<std::fixed << std::setprecision(14)<<area<<endl;
}

Output

Enter the rectangle's length: 21
Enter the rectangle's width: 13.4
Length = 21
Width = 13.4
Area = 281.40000000000003

Program 2


#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

double futureInvestmentValue(double invAmount, double monthlyInterestRate, int years);
int main()
{
    double invAmount, yearlyInterestRate, monthlyInterestRate,f;
    int years,y;
    cout << "Enter investment amount: ";
cin >> invAmount;

cout << "Enter yearly interest rate: ";
cin >> yearlyInterestRate;
monthlyInterestRate=yearlyInterestRate/1200;

cout << "Enter the year: ";
cin >> years;

cout<<"\nYears\tFuture Value\n";
    for(y=1;y<=years;y++)
    {
        f=futureInvestmentValue(invAmount,monthlyInterestRate,y);
        cout<<y<<"\t"<<std::fixed << std::setprecision(2) <<f<<endl;

    }


   return 0;
}
double futureInvestmentValue(double invAmount, double monthlyInterestRate, int years)
{
    double FutureInvestmentValue;
    FutureInvestmentValue = invAmount*(pow((1 + monthlyInterestRate), years*12));
    return FutureInvestmentValue;
}


Output

Enter investment amount: 10000
Enter yearly interest rate: 6.25
Enter the year: 30

Years   Future Value
1       10643.22
2       11327.81
3       12056.43
4       12831.93
5       13657.30
6       14535.76
7       15470.73
8       16465.83
9       17524.95
10      18652.18
11      19851.92
12      21128.84
13      22487.88
14      23934.34
15      25473.84
16      27112.37
17      28856.28
18      30712.37
19      32687.85
20      34790.39
21      37028.17
22      39409.89
23      41944.80
24      44642.77
25      47514.27
26      50570.48
27      53823.26
28      57285.27
29      60969.97
30      64891.66

Add a comment
Know the answer?
Add Answer to:
Using basic c++ write a separate code for each of the following: 1. Area Rectangle •...
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
  • In the code (C++) below, if you input 2 as length and 4 as width, the...

    In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...

  • Write a program to display the area of a rectangle after accepting its length and width...

    Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00...

    share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...

  • Hello I have a question. I would like to check if the code follows this requirement....

    Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...

  • C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class...

    C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class    double rectWidth; // Local variable for width    double rectLength; // Local variable for length    string rectColor;    // Get the rectangle's width and length from the user.    cout << "This program will calculate the area of a\n";    cout << "rectangle. What is the width? ";    cin >> rectWidth;    cout << "What is the length? ";    cin >>...

  • Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override...

    Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle {       private double length;    private double width;       public Rectangle(double l, double w)    {        length = l;        width = w;    }       public double getLength()    {   ...

  • I need help with the C++ for the following problem: Write a program uses objected oriented...

    I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...

  • Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are...

    Modify the C++ program you created in assignment 1 by using 'user defined' functions. You are to create 3 functions: 1. A function to return the perimeter of a rectangle. This function shall be passed 2 parameters as doubles; the width and the length of the rectangle. Name this function and all parameters appropriately. This function shall return a value of type double, which is the perimeter. 2. A function to return the area of a rectangle. This function shall...

  • The program must be in C# syntax. Write the definition for a generic class called Rectangle...

    The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that...

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