Question

Develop a complete C++ program that will calculate draw an empty cube rectangle using a function...

Develop a complete C++ program that will calculate draw an empty cube rectangle using a function call. A rectangle is identified by length of its edges, 2 <= L <= 20. Implement a function to perform user request, which requires two parameter. The functions you define should not return a value. In main() function, design a loop to ask user to enter length of edges until user enters 0 for one of the edges. A length of 0 exits the program. An example run is given below:

Enter length of the edges: 5 4

* * * * *
*       * 
*       *
* * * * *

Enter length of the edges: 6 3

* * * * * *
*         *
* * * * * * 

Enter length of the edges: 2 3

* *
* *
* *

Enter length of the edges: 0 9

Bye...

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

I think the output you provided in the example is wrong as in first case the second and third row stars end one column earlier , same in the second example the middle row ends one column earlier.

It should have been like this:

Though I have implemented both the cases, In the code below drawRectangle(int ,int) is for drawing as I mentioned in the image above and drawRectangle1(int,int) is as you have given the screenshot. Uncomment drawRectangle1(int,int) function call in main() function to check it .

Code Screenshot

Output:

This is if you use the drawRectangle(int ,int) method

This is if you use the drawRectangle1(int ,int) method

Code:

#include<iostream>

using namespace std;

//output is as I mentioned in the answer

//drawrectangle(int,int) method

//takes two integer parameters which are length of the edges

void drawRectangle(int l,int b){

    //the first outer loop keeps track of the breadth of the rectnagle

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

    {

        //this inner loop is for length of the rectangle

        for(int j=1;j<=l;j++)

        {

            //this is for the first and last row case of the rectangle

            //in this case stars are entered continously till teh entire length

            if(i==1 || i==b){

                cout<<"*";

            }

            //this is for all the middle rows of teh rectangle(except the first and last)

            //in this case star is printed only at the first and last column

            else{

                //if it is the first or last column then only print the star

                //else print a blacnk space

                if(j==1 || j==l)

                    cout<<"*";

                else

                    cout<<" ";

            }

        }

        //after row is done move to next line

        cout<<"\n";

    }

}

//output is asper your question , which I think is incorrect

//drawrectangle(int,int) method

//takes two integer parameters which are length of the edges

void drawRectangle1(int l,int b){

    //the first outer loop keeps track of the breadth of the rectnagle

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

    {

        //this inner loop is for length of the rectangle

        for(int j=1;j<=l;j++)

        {

            //this is for the first and last row case of the rectangle

            //in this case stars are entered continously till teh entire length

            if(i==1 || i==b){

                cout<<"*";

            }

            //this is for all the middle rows of the rectangle(except the first and last)

            //in this case star is printed only at the first and second last column

            else{

                //if it is the first or second last column then only print the star

                //else print a blacnk space

                if(j==1 || j==l-1)

                    cout<<"*";

                else

                    cout<<" ";

            }

        }

        //after row is done move to next line

        cout<<"\n";

    }

}



int main(){

    //local varibales for storing the length of the edges

    int l,b;

    //this loops runs continuosly

    while(true)

    {

        //ask user to enter the lengths of the edges

        cout<<"\nEnter length of the edges : ",

        cin>>l>>b;

        //if any one of the edge length =0 show Bye msg and break the loop

        if(l==0 || b==0)

        {

            cout<<"Bye...";

            break;

        }

        else    //else make function call to drawrectangle(int,int) method

        {

            //function which draws the rectangle as I mentioned in the answer

            drawRectangle(l,b);    

            //function which draws the rectangle as you mentioned in the question

            //uncomment the below function and comment the fucntion call above to check it

            

            //drawRectangle1(l,b);    

        }

        

    }

}

Add a comment
Know the answer?
Add Answer to:
Develop a complete C++ program that will calculate draw an empty cube rectangle using a function...
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
  • Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called...

    Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called in the main function to complete the program. You must not change any of the existing code in the file. You can only add functions and comments to the code. Here’s a sample run of how the program should behave: Enter rectangle length: -1 ← invalid value, ask user to re-enter Enter rectangle length: -2 ← invalid value Enter rectangle length: 0 ← invalid...

  • Use C++ to implement a program uses objected oriented programming to calculate the area of a...

    Use C++ to implement 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(), and getArea() member function should get the...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • 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 DevC++ to implement a program uses objected oriented programming to calculate the area of a...

    Use DevC++ to implement 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(), and getArea() member function should get the...

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1...

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • 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...

  • C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu...

    C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu to test the functions from 2 - 4. You must call the functions from 2 - 4 and cannot reimplement their functionality in this function. The menu is displayed as follows: 1) Enter a 4-bit message to encode into a 7-bit Hamming message. 2) Enter a 7-bit Hamming message to transmit through a noisy channel. 3) Enter a 7-bit Hamming message to receive and...

  • 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 >>...

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