Answer to Question #160937 in C++ for Amar pratap singh

Question #160937

Fill in the blank in the following program that draws a figure resembling the letter 'Z' with sides (50, 100, 50) and the angle between them to be 60 degrees.




Remember that the turtle starts at the center of the canvas and facing right.


left(180); forward(50); right(B1); forward(B2); left(B3); forward(50);


What is B1?






What is B2?






What is B3?






Fill in the blanks to complete the code that prints the string:


“bccbccbccaaaaaaaaaabccbccbccaaaaaaaaaa”




repeat(B1){


repeat(B2){


cout<<"b";


repeat(B3){


cout<<"c";


}


}


repeat(B4){


cout<<"a";


repeat(2){


cout<<"a";


}


}


}


What is B1?






What is B2?






What is B3?






What is B4?






Fill in the blanks in the following program so that it draws the given picture. Each


figure is a rhombus with side 100 and interior angles (60, 120, 60, 120). The distance


between 2 adjacent rhombuses is 20 (between their closest vertices).




repeat(2){


repeat(2){


B1;


left(B3);


B1;


left(120);


}


right(120);


penUp();


B2;


penDown();


repeat(2){


B1;


left(120);


B1;


left(B3);


}


right(B3);


penUp();


B2;


penDown();


}




What is command B1?




forward(100)



forward(20)



backward(100)



backward(20)




What is command B2?




forward(100)



forward(20)



backward(100)



backward(20)


What is B3?






Suppose we have a 5 x 5 image.The pixels in the top row are numbered 0 through 4 left to right,the ones in the second row from the to are numbered 5 through 9 left to right, and so on. Suppose there is a 'T' in the middle. The horizontal bar is in the middle of the second row, and 3 pixels wide. The vertical bar is in the middle of the third column and is also 3 pixels wide. Only pixels of the 'T' are black, rest are white.




Suppose we flatten the image into an array(let's call it A, and it is indexed from 0) such that pixel number i goes into the array at index i. What is the index of a pixel in column a and row b? (Note that first row has a=0 and first column has b=0)




5 * j + i



5 * j * i



5 * i + j



5 * i + 5 * j








Which of the indices in the array correspond to black pixels ?




3



8



11



13


What is the total number of white pixels?






For the pixel at index i in the array, what are the corresponding row and column number (first row has row number 0, and second row has 1)?




Note: floor(x) is the largest integer that is less than or equal to x. ceil(x) is the smallest


integer that is greater than or equal to x.




floor(i/5), i%5



i%5, floor(i/5)



ceil(i/5), i%5



floor(i/5)+1, i%5






1
Expert's answer
2021-02-03T11:17:51-0500
#include <iostream>
using namespace std;
int main () {
    
    // the shown of letter z
    for (int i = 1; i <= 10; i++) {
        if (i == 1 || i == 10) {
            for (int j = 1; j < 10; j++) {
                cout << "#";
            }
            cout << endl;
        }
        else {
            for (int j = 1; j < 10; j++) {
                if (i + j == 10) {
                    cout << "#";
                }
                else {
                    cout << " ";
                }
            }
            cout << endl;
        }
    }
    // the shown of turtle
    for (int i = 1; i <= 11; i++) {
        for (int j = 1; j <= 11; j++) {
            if (i == j || i + j == 12) {
                cout << "#";
            }
            else {
                cout << " ";
            }
        }
        cout << endl;
    }
}


#include <iostream>
#include <conio.h>
using namespace std;
int main() {
    int i, j, rows;
    char ch;
    cout << "Enter the number of rows\n";
    cin >> rows;
    cout << "Enter the Symbol for pattern\n";
    cin >> ch;
    cout<<"\n";
    i=1;
    while(i <= rows) {
        //outer while loop
        j = 1;
        while(j <= rows - i) {
            //inner while loop
            cout << " ";
            //print space
            j++;
        }
        j = 1;
        while(j <= rows){
            //inner while loop
            cout << ch;
            //print character after space
            j++;
        }
    cout << "\n";
    //move to next line
    i++;
    }
    getch();
    return 0;
}



#include <iostream>
#include <conio.h>
using namespace std;
void repeatB1 () {
    cout << "bcc";
}
void repeatB2 () {
    cout << "aaa";
}
int main() {
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            repeatB1();
        }
        for (int j = 0; j < 3; j++) {
            repeatB2();
        }
    }
    return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog