A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

How to generate a program in C++ that gives the output as follows - consider as dash. ----* ---*** --***** -******* *********

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    using a loop?

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    cout << "----*\n---***\n--*****\n-*******\n*********" << endl;

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Use a for loop, or maybe a nestled for loop. You start with 4 underscores and decrement by one on each line. You add two asterisks on each line. Start the problem, post any further questions/problems you have.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You should use a loop

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There are many ways to do this, one of them is to store the content of each line in array/vector of strings and then perform the following code: copy(strTable.begin(), strTable.end(), ostream_iterator<string> (cout, "\n")) // vector version or: copy(strTable, strTable+size, ostream_iterator<string> (cout, "\n")) // array version -- you have to know how many elements you have

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    for (int i=0; i<5; i++) { for (int j=0; j<4; j++) { if (j < 4-i) cout << "-"; else cout << "**"; } cout << "*" << endl; }

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Well, I, for one, think that providing a ready-made program as an answer to a question like this is not very helpful. Being able to copy&paste is not a skill you want to instill. Now, to the question itself: 1) Do you know how to output characters in C++? 2) Do you know how to use variables and loops? 3) What can you tell about the number of '-' and '*' characters in each row? How do they change? If you can answer these questions, you should be able to write your own program. Good luck!

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Wops... I agree... I wrote it without actually thinking about it, but you're right.

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    u need to use for loop 3 times ,one for the space, one for the stars, and one for the rows

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    great, now try generating this: |*----| |-*---| |--*--| |---*-| |----*| |---*-| |--*--| |-*---| |*----| |-*---| ...

  11. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.