Question

Modify your code from the previous exercise so that it could easily be modified to display...

Modify your code from the previous exercise so that it could easily be modified to display a different range of numbers (instead of 1234567890) and a different number of repetitions of those numbers (instead of 60 total characters), with the vertical bars still matching up correctly. Write a complete class named NumbersOutput. Use two class constants instead of "magic numbers,", with one constant set to 6 for the number of repetitions, and the other set to 10 for the range of numbers. Put the for loop code in your class's main method.

For example, if your number-of-repetitions constant is set to 7 and your range constant is set to 5, the output should be the following:

    |    |    |    |    |    |    |
12340123401234012340123401234012340
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
  int n, range;
  cout<<"Enter n for number of repitions: ";
  cin>>n;
  cout<<"Enter range: ";
  cin>>range;
  for(int i=0;i<n;i++)
    cout<<right<<setw(range)<<"|";
  cout<<endl;
  while(n!=0){
    for(int i=0;i<range;i++)
      cout<<i;
    n--;
  }
}

Sample Output :

Output1:

> clang++-7 -pthread -std=c++17 -o main main.cpp ?./main Enter n for number of repitions: 7 Enter range: 4 012301230123012301

Output 2:

> clang++-7 -pthread -std=c++17 -o main main.cpp > ./main Enter n for number of repitions: 8 Enter range: 5 I | 0123401234012

Note - If query, do ask in comment section. PLEASE LIKE the solution for my motivation

Add a comment
Know the answer?
Add Answer to:
Modify your code from the previous exercise so that it could easily be modified to display...
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
  • (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming...

    (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...

  • The following C++ program is a slightly modified version of Program 5.20 from Gary J. Bronson...

    The following C++ program is a slightly modified version of Program 5.20 from Gary J. Bronson textbook. In this program, you compute and display the average of three grades of each student for a class of four students. You need to modify the code to compute and display the class average as well as the standard deviation. Your code changes are as follows: 1. The variable “double grade” should be replaced by a two-dimensional array variable “double grade[NUMSTUDENTS][NUMGRADES].” Also replace...

  • Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp...

    Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp Is posted here: // This program reads data from a file into an array. Then, it // asks the user for a number. It then compares the user number to // each element in the array, displays the array element if it is larger. // After looking at entire array, it displays the number of elements in the array larger // than the user...

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • Provide immediate feedback for each mistyped sentence. To do so, modify the Test class’s present_test method...

    Provide immediate feedback for each mistyped sentence. To do so, modify the Test class’s present_test method so that it informs the player a mistake has been made, then display the challenge sentence followed by the player’s sentence so the player can determine where the error lies. #-------------------------------------------------------------------------- #  # Script Name: TypingChallenge.rb # Version:     1.0 # Author:      Jerry Lee Ford, Jr. # Date:        March 2010 #  # Description: This Ruby script demonstrates how to apply conditional logic  #              in order...

  • For this assignment please complete the following exercise. Submit your completed source code (*.cpp) and screenshots...

    For this assignment please complete the following exercise. Submit your completed source code (*.cpp) and screenshots demonstrating you successfully ran the program by the due date. ======== Mortgage Class Design a class that will represent a home mortgage. The constructor should accept the loan amount, interest rate, and number of years to pay off the loan. The class should have member functions for returning the monthly payment amount and the total amount paid to the bank at the end of...

  • Enhance and correct a Tic Tac Toe game. The game is intended to be played against...

    Enhance and correct a Tic Tac Toe game. The game is intended to be played against a computer. The object TicTacToeBoard is initialized to indicate if the computer is the player 1 or player 2. Your task is to allow turns between the player and computer and to determine if a winner exists. Keyboard input implies using the Scanner object. Review Section 7.7 in the textbook. Ideally, do 1 task at a time and test the results. The tasks are...

  • Currently, the game allows players to play as many times as they wish. It does not...

    Currently, the game allows players to play as many times as they wish. It does not provide any feedback on how the players are doing, however. Modify the game so that it keeps track of the number of games played as well as the average number of guesses made per game. To implement this change, add the following list of global variables to the beginning of the script’s Main Script Logic section. Assign each variable an initial value of zero....

  • Please help with this, and leave comments explainging the code you wrote, thank you for your...

    Please help with this, and leave comments explainging the code you wrote, thank you for your help Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there...

  • Modify your PredictGPA.java file from Lab 2 to create a method called GPA that takes a...

    Modify your PredictGPA.java file from Lab 2 to create a method called GPA that takes a string argument (the grade) and returns the corresponding value (ie 4.0 for an A, 3.33 for a B+, etc). Use this method call to reduce the “redundant” code that you had in Lab 2. The program must otherwise still run correctly as to the directions in Lab 2 and compute the GPA after using the method calls to determine the appropriate grade values. Trying...

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