C++ Code on designing an image

Asked By 0 points N/A Posted on -
qa-featured

Hi!

I was designing this code but I face bit problem the first two lines of this code execute fine but the next “$” are displayed but not in the same way I was expecting. Can anybody will help me designing this code in such a way that I may get the “$” in the following manner.

                                                                      $   $   $   $                                              

                                                              $             $    

                                                              $             $

                                                                     $   $   $   $ 

SHARE
Best Answer by MShani
Answered By 0 points N/A #87608

C++ Code on designing an image

qa-featured

Judging from your image, I'm going boldly guess that your image looks something as follows:

0$0$0$0$
$000$000
00000000
$000$000
0$0$0$0$
 
Where the 0 represents the space.
 
I do apologize from horrid ASCII art but knowing the amount of space really helps with the coding. Anyway as this is a very simple artwork, you can just get by with hardcoding.
 
But if you insist of coding it properly with loops, you can take reference from the following pseudo code.
 
function altLine() {
while ( n != 4 ) print " $"
}
 
function midLine() {
while ( n != 2) print "$ "
}
 
main() {
altLine()
midLine()
midLine()
altLine()
}
 
Hope this is of help to you.
Best Answer
Best Answer
Answered By 0 points N/A #87610

C++ Code on designing an image

qa-featured

Hi,

I don’t have turbo C++ software right now, but I am sending you the code working in the C++ compiler. All you need to do is copy the code in your compiler with new source file and save it.

After compiling you can see the result on the screen. And if you want it only in turbo C++ compiler, you need to take the idea from here and replace some coding with turbo C coding like replace “cout<<” with print, etc.

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

int n=1;

void fLine()

{

 for(n=1;n!=5;n++)

 cout<<"$";

 }

void hLine() {

for(n=1;n!=3;n++)

 cout<<"$";

}

void main()

{

fLine();

cout<<endl<<endl;

hLine();

cout<<endl<<endl;

hLine();

cout<<endl<<endl;

fLine();

getch();

}

Here I use fLine as a function name of “Full Line” and hLine as a function name of “Half Line”. We define and initialize a variable n with 1 in the start and after that we will use it as a loop indicator in both of the functions. Here we will use for loop, in turbo c compiler you can also use While loop instead of for loop.

In first fLine function we use the instruction printing “$” until it reaches to 5, because we need to print $ sign four times. In first hLine function we use the instruction printing “$” until it reaches to 3, because we need to print $ sign two times.

In main function, we call the functions and between the callings of two functions we print “endl” means line ending instruction, after this line reading, compiler will end printing on current line, start from the next line, and print the next output on next line. Hope it will be helpful for you.

Related Questions