Question

Use a loop structure and code a program that produ
Please answer (1,2,4)having issues
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable Perl Code:

# Number of A in a block
$numA = 3;

# Number of B in a block
$numB = 1;

# Variable for loop
$val_i = 1;

# Output
$out = "";

# Variable for loop
$val_j = 1;

# Number of space to be printed
$spaceAvail=0;

# Loop for number of lines
while ($val_i <= $ARGV[0])
{
   while ($val_j <= $val_i)
   {
       # Whwn new block starts
       if ($numA == 0 && $numB == 0)
       {
          $numA = 3;
          $numB = 1;
       }
       # Output A
       if ($numA > 0)
       {
          $out.= "A";
          $numA--;
       }
       # Output B
       else
       {
          $out.= "B";
          $numB--;
          $spaceAvail++;
       }
       $val_j++;
   }
   # Print output
   print($out . "\n");
  
   # Print required spaces
   for (my $i=0; $i <$spaceAvail; $i++) {
       print(" ");
   }
   $val_i++;
}

Add a comment
Know the answer?
Add Answer to:
Please answer (1,2,4)having issues Use a loop structure and code a program that produces the following...
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
  • In *PERL* Use a loop structure and code a program that produces the following output (Take...

    In *PERL* Use a loop structure and code a program that produces the following output (Take one parameter to let user specify how many lines need to be printed): A AA AAA AAAB AAABA AAABAA AAABAAA AAABAAAB

  • please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1....

    please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...

  • hey please answer in python 3 This is the test for these questions. it has to...

    hey please answer in python 3 This is the test for these questions. it has to be exactly the same as the Expected output. notice my code is very close to getting it but im always off by 0.01 or 0.02. Thank you for the help! In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may...

  • C++ please Project: Working with Text Write an object-oriented program the performs the following tasks: ....

    C++ please Project: Working with Text Write an object-oriented program the performs the following tasks: . Reads a text file provided along with this data and maintains it an object. Determines the number of characters and keeps in the object. Determines the number of words and retains the result in the object. Determines the number of paragraphs and keeps the result in the object. A possible class definition: class Textutil { string text = ** int words = @; int...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> //...

    in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

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
Active Questions
ADVERTISEMENT