1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yuradex [85]
3 years ago
15

2) ( 60p) Write a C program that reads a number n from the user and allows to print a house with a roof using ‘*’ characters. Th

e house should be a n x n square and the roof two diagonal lines of 45 degrees forming a roof (if n is odd the roof closes in the top perfectly).
Computers and Technology
1 answer:
Charra [1.4K]3 years ago
5 0

Answer:

Explanation:

#include <iostream>

using namespace std;

int printroofln(int, int);

int printbodyln(int, int);

int main()

{

   int hgt=0,odd=0,rhgt=0;

   cout<<"Enter the height:";

   cin>>hgt;

   if ((hgt%2)==1) rhgt=(hgt/2)+1;

   else rhgt=hgt/2;

       

   for (int i=0;i<rhgt;i++)

   {

       printroofln(i,hgt);

   }

   for (int j=0;j<hgt;j++)

   {

       printbodyln(j,hgt);

   }

   return 0;

}

int printroofln(int rfln, int hgt)

{

   int id1,id2,hlf=0;

   hlf=hgt/2;

   if ((hgt%2)==1)

   {

       id1=hlf-rfln;

       id2=hlf+rfln;

   }

   else

   {

       id1=hlf-rfln-1;

       id2=hlf+rfln;

   }

   

   for (int i=0;i<=hgt;i++)

   {

       if ((id1==i)||(id2==i))

           cout<<"*";

       else

           cout<<" ";

   }

   cout<<endl;

   return 0;

}

int printbodyln(int bln, int hgt)

{

   for (int i=0;i<hgt;i++)

   {

       if ((bln==0)||(bln==(hgt-1))||(i==0)||(i==(hgt-1)))

       {

           cout<<"*";

       }

       else

       {

           cout<<" ";

       }

   }

   cout<<endl;

   return 0;

}

You might be interested in
Why doesn't the ad load ?
baherus [9]
Try refreshing the page, if not restart your device check your internet etc.
3 0
2 years ago
Read 2 more answers
I hate these homework it's very hard and I need help
liubo4ka [24]
Ethics is the answer I believe
8 0
3 years ago
Harrison works in a manufacturing unit and oversees the logistics, including the daily shipping of a large number of packages. W
Nookie1986 [14]

E. Transaction processing system

Explanation:

He will need a transaction processing system to know the amount of logistics available daily and how many to ship and how many to order.

Transaction processing system will make him keep track of what transactions take place during the various days to help him give a good report.

8 0
3 years ago
Read 2 more answers
Consider the following class declarations.
kow [346]
Override only
Reason because the same method speak is in the parent and child class
5 0
3 years ago
Which programming language uses objects?<br> a. C++<br> b. ALGOL<br> c. Pascal<br> d. BASIC
yanalaym [24]
So this is your answer hope this helps you
C++
7 0
3 years ago
Other questions:
  • Assume you have a byte-addressable machine that uses 32-bit word (integers are 32-bit) and you are storing the following informa
    5·1 answer
  • Codio Challenge Question (Python)
    6·1 answer
  • 14. What is the simplest way to permanently get rid of an unwanted file?
    9·1 answer
  • Suppose your name was George Gershwin. Write a complete program that would print your last name, followed by a comma, followed b
    11·2 answers
  • An internal control system is used to do all of the following: (You may select more than one answer. Single click the box with t
    11·1 answer
  • The CPU converts into information. The CPU is the mastermind of the computer, controlling everything that goes on through a seri
    12·2 answers
  • Moving Images are called________.
    15·1 answer
  • How do I send the face to the back? Seriously, I can't find out how...
    13·1 answer
  • is a security design principle to direct the selection of control layers for an organization's computing enclave to ensure its r
    6·1 answer
  • Select the correct term to complete the sentence.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!