Question

Name: PART II: USE THE COMPUTER Problem (40 points) A A tree cat = = A) Write a C++ program to reproduce the drawing below ca

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

Hey!

Answer for the first part is below. I am giving the code as well as a screenshot of the output.

Code for A)

// Program begins from here

#include <iostream>
using namespace std;

// user defined function to print tree
void tree(){
   cout << "   *   " << endl;
   cout << " *** " << endl;
   cout << " ***** " << endl;
   cout << "*******" << endl;
   cout << " *** " << endl;
}
// user defined function to print cat
void cat(){
   cout << "/\\   /\\ " << endl;
   cout << " o o   " << endl;
   cout << " =   = " << endl;
   cout << " ---   " << endl;
}

int main(){
   cat();
   tree();
   return 0;
}

// Program ends here

Here's the screenshot of the code.

i #include <iostream> using namespace std; // user defined function to print tree void tree() { cout << * << endl; cout <

Output of above code:

оо V V

Now, the answer for the second part of the problem. I am adding the code screenshot and the code as well.

Code for B)

// Program begins from here

#include <iostream>
using namespace std;

// a userdefined function to print tree n times
void tree(int n){
   for(int i = 0; i < n; i++)
       cout << "   *    ";
   cout << endl;

   for(int i = 0; i < n; i++)
       cout << " ***   ";
   cout << endl;
  
   for(int i = 0; i < n; i++)
       cout << " ***** ";
   cout << endl;
  
   for(int i = 0; i < n; i++)
       cout << "******* ";
   cout << endl;
  
   for(int i = 0; i < n; i++)
       cout << " ***   ";
   cout << endl;
}

// a userdefined function to print cat n times
void cat(int n){
   for(int i = 0; i < n; i++)
       cout << "/\\   /\\ ";
   cout << endl;

   for(int i = 0; i < n; i++)
       cout << " o o   ";
   cout << endl;
  
   for(int i = 0; i < n; i++)
       cout << " =   = ";
   cout << endl;
  
   for(int i = 0; i < n; i++)
       cout << " ---   ";
   cout << endl;
}

int main(){
   // input variable
   int input;

   // taking input from the user
   cout << "Enter input: ";
   cin >> input;

   // checking if input is even or odd
   if(input % 2 == 0) {
       // if input is even, call tree and cat function 10 times in same line
       cat(10);
       tree(10);
   }
   else {
       // if input is odd, call tree and cat function 20 times in the same column
       for(int i = 1; i <= 20; i++){
           cat(1);
           tree(1);
       }
   }

   return 0;
}

// Program ends here

Here's the screenshot(s) of the code

2 #include <iostream> using namespace std; // a userdefined function to print tree n times void tree(int n) { for(int i = 0;

27 28 // a userdefined function to print cat n times void cat(int n){ for(int i = 0; i <n; i++) cout << A A ; cout << endl

46 int main() { // input variable int input; // taking input from the user cout << Enter input: ; cin >> input; // checking

And output is here: (for even input, because for odd input, the oupt was quite large)

半 半 学学 半 「 半半 半 半 翠翠翠 ¥¥¥¥¥¥ ¥¥¥¥¥¥¥¥¥¥¥¥ ¥¥¥ ¥¥¥ 翠翠翠 羊羊羊 ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥弟弟弟弟弟弟 ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥串串 ¥¥ ¥

I hope this answers your problem.

Add a comment
Know the answer?
Add Answer to:
Name: PART II: USE THE COMPUTER Problem (40 points) A A tree cat = = A)...
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
  • One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we...

    One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

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