Question

In: Computer Science

Task G. Checkerboard (3x3) Write a program checkerboard3x3.cpp that asks the user to input width and...

Task G. Checkerboard (3x3)

Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) Don't use function. Please explain in detail and make it simple. And be clear with the {}. Thank you in advance.

Example 1:

Input width: 16
Input height: 11

Shape:
***   ***   ***
***   ***   ***
***   ***   ***
   ***   ***   *
   ***   ***   *
   ***   ***   *
***   ***   ***
***   ***   ***
***   ***   ***
   ***   ***   *
   ***   ***   *

Example 2:

Input width: 27
Input height: 27

Shape:
***   ***   ***   ***   ***
***   ***   ***   ***   ***
***   ***   ***   ***   ***
   ***   ***   ***   ***   
   ***   ***   ***   ***   
   ***   ***   ***   ***   
***   ***   ***   ***   ***
***   ***   ***   ***   ***
***   ***   ***   ***   ***
   ***   ***   ***   ***   
   ***   ***   ***   ***   
   ***   ***   ***   ***   
***   ***   ***   ***   ***
***   ***   ***   ***   ***
***   ***   ***   ***   ***
   ***   ***   ***   ***   
   ***   ***   ***   ***   
   ***   ***   ***   ***   
***   ***   ***   ***   ***
***   ***   ***   ***   ***
***   ***   ***   ***   ***
   ***   ***   ***   ***   
   ***   ***   ***   ***   
   ***   ***   ***   ***   
***   ***   ***   ***   ***
***   ***   ***   ***   ***
***   ***   ***   ***   ***

Solutions

Expert Solution

Thanks for the question, here is the simple program in C++; that draws the checkers board for any input

==========================================================================

#include<iostream>
using namespace std;

int main(){
   int width;
   int height;
   int alternate_width;
   cout<<"Input width: "; cin>>width;
   cout<<"Input height: "; cin>>height;
   int rowType;
   int colType;
   for(int row=0; row<height; row++){
       rowType = row/3;
       if(rowType%2==1){
           alternate_width=width-3;
           cout<<" ";
       }else{
           alternate_width=width;
       }
          
       for(int col=0; col<alternate_width; col++){
           colType=col/3;
           if(colType%2==0)cout<<"*";
           else cout<<" ";  
       }
       cout<<endl;
   }
}


Related Solutions

Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a...
Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) . Don't use function. Example 1: Input width: 16 Input height: 11 Shape: *** *** *** *** *** *** *** *** *** *** *** * *** *** * *** *** * *** *** *** *** *** *** *** *** *** *** *** * *** *** *...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
Write a program that asks the user to input a set of floating-point values. When the...
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.5 pts Your code with comments A screenshot of the execution Test Case:       Enter float: 1.0...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Write a program named StringWorks.java that asks the user to input a line of text from...
Write a program named StringWorks.java that asks the user to input a line of text from the keyboard.   Ask the user if they want their answers case sensitive or not. You output should be the list of words in the sentence including duplicates A sorted list of the words (alphabetically) A sorted list of words listed backwards (where z comes before a) A randomly shuffled list of works the list of words in the sentence alphabetically removing duplicates. You need...
Write a C++ program using separate void which asks the user to input side of a...
Write a C++ program using separate void which asks the user to input side of a square, radius of a circle , height and base of a triangle and finds the area of squares, circles and triangles. Then using main function display the area of square, circle and triangle
1. Write a Java program that asks the user to input a positive integer n first,...
1. Write a Java program that asks the user to input a positive integer n first, then create an array of size n. Fill n random integers between 5 and 555, inclusively, into the created array. Output the sum of all the integers in the array and the average of all the integers in the array. 2 .Find the output of the following Java program and explain your answer
Must implement a simple program that asks the user for a width and a height, storing...
Must implement a simple program that asks the user for a width and a height, storing them as double values. Afterwards, you compute area and perimeter as if the shape were a rectangle. Output the results. Then, you compute the area and perimeter as if the shape were a right triangle and you have been given the base and height. Area and Perimeter Calculator Enter width: 3 Enter height: 5 If your shape is a rectangle, its area is 15.0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT