Question

I have asked this question two times and I got wrong answers in both of them....

I have asked this question two times and I got wrong answers in both of them. Unfortunately, experts are no allowed to edit their answers.

Kindly read the following instructions carefully and don’t paste the same answer that I got before, please.


in C++, Create a project titled Lab5_Figures. This project contain multiple files. Write a program that repeatedly asks the user to select either a square, slash (diagonal line), backlash(reverse diagonal line) or a cross, then inputs the figure size and prints the appropriate figure in stars. For square, the program should ask whether the user wants a filled or a hollow square. The program should quit if the user inputs an invalid option. See an example dialog below:
1. square
2. slash
3. backslash
4. cross
select figure: 1
select size: 4
filled or hollow [f/h]: h
****
* *
* *
****

1. square
2. slash
3. backslash
4. cross
...
You can reuse your code from the Looping lab. Place star-printing code in four separate functions: filledSquare(), hollowSquare(), shash(), backslash() and cross(). Each function should accept a single integer parameter - the size of the figure and return no value (be a void-function). Create three separate files figures.cpp, figures.h, and figuresInput.cpp. Place the triangle and square function definitions in figures.cpp and their prototypes in figures.h. Make sure that the header file is protected against multiple inclusion. Place the main function in figuresInput.cpp

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

figures.h:

#include<iostream>
using namespace std;

void filledsquare(int n);
void hollowsquare(int n);
void slash(int n);
void backslash(int n);
void cross(int n);

figures.cpp

#include<iostream>
#include "figures.h"
using namespace std;

void filledsquare(int n)
{
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=n;j++)
       {
           cout<<"*";
       }
       cout<<endl;
   }
}
void hollowsquare(int n)
{
   for(int i=1;i<=n;i++)
   {
       if(i==1 ||i==n)
       {
           for(int j=1;j<=n;j++)
           {
               cout<<"*";
           }
           cout<<endl;  
       }
       else
       {
           for(int j=1;j<=n;j++)
           {
               if(j==1||j==n)
                   cout<<"*";
               else
                   cout<<" ";
           }
           cout<<endl;  
       }
      
   }
}
void slash(int n)
{
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=n-i;j++)
       {
           cout<<" ";
       }
       cout<<"*"<<endl;
   }
}
void backslash(int n)
{
   for(int i=1;i<=n;i++)
   {
      
       for(int j=1;j<=i-1;j++)
       {
           cout<<" ";
       }
       cout<<"*"<<endl;
   }
}
void cross(int n)
{
   n=n/2;
   int s=2*n-1;
   for(int i=1;i<=n;i++)
   {
      
       for(int j=1;j<=i-1;j++)
       {
           cout<<" ";
       }
       cout<<"*";
       for(int k=1;k<=s;k++)
       {
           cout<<" ";
       }
      
       cout<<"*"<<endl;
       s-=2;
   }
   for(int j=1;j<=n;j++)
       {
           cout<<" ";
       }
       cout<<"*"<<endl;
  
   s=1;
   for(int i=1;i<=n;i++)
   {
      
       for(int j=1;j<=n-i;j++)
       {
           cout<<" ";
       }
       cout<<"*";
       for(int k=1;k<=s;k++)
       {
           cout<<" ";
       }
       cout<<"*"<<endl;
       s+=2;
   }
  
}

figuresInput.cpp:

#include<iostream>
#include "figures.cpp"
using namespace std;
int main()
{
      
   int flag=1;
   while(flag)
   {
       cout<<"Enter   1:to draw filled square"<<"   2:to draw empty square"<<endl;
       cout<<"   3:to draw slash"<<endl<<"   4:to draw backslash"<<endl;
       cout<<"   5:to draw cross"<<endl<<"   0:to exit";
       int n;
       cin>>n;
       if(n!=0)
       {
           int sz;
           cout<<"Enter size:";
           cin>>sz;
           switch(n)
           {
          
               case 1:
                   {
                       filledsquare(sz);  
                       break;
                   }
               case 2:
                   {
                       hollowsquare(sz);  
                       break;
                   }
               case 3:
                       {
                           slash(sz);              
                           break;
                       }
               case 4:
                   {
                       backslash(sz);
                       break;
                   }  
               case 5:
                   {
                       cross(sz);                  
                       break;
                   }
           }
          
       }
       else
       {
           flag=0;
       }
   }
}

output:

DAchglc++figuresinput.exe Enter 1:to draw filled square 2:to draw empty square 3:to draw slash 4:to draw backslash 5:to draw

Add a comment
Know the answer?
Add Answer to:
I have asked this question two times and I got wrong answers in both of them....
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
  • Please help! i asked this question earlier & got wrong answers and wrong formulas. i included...

    Please help! i asked this question earlier & got wrong answers and wrong formulas. i included a pic of what the formulas are supposed to look like! also there are three parts to this question but only one is shown... please help with all 3 parts Homework: Topic 4 Homework (Chapter 23) Save Score: 0 of 10 pts 20, 4 (4 complete) ▼ Hw Score: 29.52%, 17.71 of 60 pts E23-19 (similar to) Question Help * 0) Quality Fender, which...

  • How do I correct this error in my code? When it got to the file type...

    How do I correct this error in my code? When it got to the file type I can only go "null" from a certain point and I'm wondering how to correct this error. Also can I get a word document on this coding strategy for this problem? How much of this am I doing correctly? The original problem description: Create a program that provides a listing of all the files in a directory. The program should be a Java application...

  • Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can...

    Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE...   MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • This assignment requires you to write a program to implement an odd-order Magic Square. Prompt the...

    This assignment requires you to write a program to implement an odd-order Magic Square. Prompt the user to enter the “order” of the square and then produce for the user a magic square of that order. Run your code for at least four different inputs – all odd. ODD ORDER MAGIC SQUARES 1. Start by placing 1 in the middle column of the top row. 2. Continue by always placing the next number (say k+1) in the square diagonally up...

  • What am I doing wrong here...…. Question is this : In this exercise, you will create...

    What am I doing wrong here...…. Question is this : In this exercise, you will create a program that displays a table consisting of four rows and three columns. The first column should contain the numbers 10 through 13. The second and third columns should contain the results of squaring and cubing, respec- tively, the numbers 10 through 13. The table will look similar to the one shown in Figure 9-38. If necessary, create a new project named Introductoryl6 Project,...

  • Please follow the instructions below to create a code. The instructions are broken down into a...

    Please follow the instructions below to create a code. The instructions are broken down into a few steps. Create the following functions along with a driver for each one confirming it works. The driver needs to test the function with at least 5 different inputs, although more is always better. Be sure to use the function display_startup_banner( ) in all of your drivers. Please create separate files for each code. That is, if you're creating a function called learning_online_is_a_trip( )...

  • I am required to use the try - catch block to validate the input as the...

    I am required to use the try - catch block to validate the input as the test data uses a word "Thirty" and not numbers. The program needs to validate that input, throw an exception and then display the error message. If I don't use the try - catch method I end up with program crashing. My issue is that I can't get the try - catch portion to work. Can you please help? I have attached what I have...

  • Instructions This assignment has to be completed by each student individually. NO COLLABORATION I...

    I need help creating a class diagram for this please: I am not sure what more you want? it has 2 classes at least Connect4 and Connect4TextConsole. Instructions This assignment has to be completed by each student individually. NO COLLABORATION IS ALLOWED Submit YourASURitelD ProjectDeliverable2.zip compressed folder should contain the following files following This the 1. 2. Connect4.java 〔Game Logic Module) Connect4TextConsole.java (Console-based Ul to test the gamel 3. JavaDoc documentation files index.html and all other supporting files such as.cs5...

  • Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have...

    Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have set up a program in Visual Studio that will use operation between fractions. I have written a basic code example that does all the resources that you need to follow. Your job is to complete the exercises presented below in quest2.cpp. For this assignment you will learn and demonstrate how to: Work with functions use Past-by-Value and Past-by-Reference. use structs. use cin to get...

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