Write a PL/SQL program to draw empire state building - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Thursday, October 5, 2017

Write a PL/SQL program to draw empire state building

Draw empire state building using PL/SQL program

Program:

DECLARE
total_pyramid_length NUMBER;
total_pyramid_width NUMBER;

left_pyramid_shade_count NUMBER :=0;
middle_pyramid_shade_count NUMBER:= 0;
right_pyramid_shade_count NUMBER:= 0;


lines_printed_count NUMBER := 0;
new_line_flag VARCHAR2(3) := 'YES';
check_which_building NUMBER;
amt_of_space_interms_line NUMBER;


middle_space NUMBER := 15; -- this is to keep the initial space between the two horizontal lines to be atleast 3 spaces
print_middle_space NUMBER;
noof_lines_occupied_in_1_space NUMBER := 1.5; -- no of lines occupied in one space
increment_space_by NUMBER := 2; -- space should be incremented inbetween the lines to make it look like a moon


space_occupied_in_middle NUMBER;
noof_pics_left_side NUMBER;
noof_pics_right_side NUMBER;


building_1_width NUMBER;
building_2_width NUMBER;
building_3_width NUMBER;
building_4_width NUMBER;
building_5_width NUMBER;
building_6_width NUMBER;







---- #### Procedur to print the shaded part in the background #### ----
PROCEDURE print_shade(para_width NUMBER, next_line NUMBER)
IS
BEGIN
FOR lines_printed IN 1 .. next_line
LOOP

FOR width_of_shade in 1 .. para_width
LOOP
DBMS_OUTPUT.PUT('|');
END LOOP;

IF new_line_flag = 'YES'
THEN
dbms_output.new_line;
ELSIF new_line_flag = 'NO'
THEN
NULL;
END IF;

END LOOP;
END;



---- #### END OF Procedur to print the shaded part in the background #### ----





----#### Procedure to print empty spaces #### ----
PROCEDURE print_empty_space(width_of_space NUMBER)
IS
BEGIN
FOR for_empty_space in 1.. width_of_space
LOOP
DBMS_OUTPUT.PUT(' ');
END LOOP;
END;
---- ####END OF procedure to print empty spaces #### ----






---- #### Procedure to calculate the left right shaded amount #### ----
PROCEDURE calc_left_right_shade
IS
BEGIN
amt_of_space_interms_line := (middle_pyramid_shade_count * 1.5); --taking 1 spaces occupies around 1.5 times the line
left_pyramid_shade_count := CEIL((total_pyramid_width - middle_pyramid_shade_count)/2);
right_pyramid_shade_count := (total_pyramid_width - left_pyramid_shade_count) - amt_of_space_interms_line; -- space occupies more
--area when commpared to line so remove the extra lines that we calculted
--taking 1.5 as a standard

END;
---- #### END OF Procedure to calculate the left right shaded amount #### ----




---- #### Procedure to print buildings #### ----
PROCEDURE print_buildings
IS
BEGIN
IF check_which_building = 1
THEN
middle_pyramid_shade_count := building_1_width;
calc_left_right_shade;


ELSIF check_which_building = 2
THEN
middle_pyramid_shade_count := building_1_width + building_2_width;
calc_left_right_shade;

ELSIF check_which_building = 3
THEN
middle_pyramid_shade_count := building_1_width + building_2_width + building_3_width;
calc_left_right_shade;

ELSIF check_which_building = 4
THEN
middle_pyramid_shade_count := building_1_width + building_2_width + building_3_width + building_4_width;
calc_left_right_shade;

ELSIF check_which_building = 5
THEN
middle_pyramid_shade_count := building_1_width + building_2_width + building_3_width + building_4_width + building_5_width;
calc_left_right_shade;

ELSIF check_which_building = 6
THEN
middle_pyramid_shade_count := building_1_width + building_2_width + building_3_width + building_4_width + building_5_width + building_6_width;
calc_left_right_shade;

END IF;

END;

---- #### END OF Procedure to print buildings #### ----





---- #### Procedure to Calculate the Left, Right , and Middle space #### ----
PROCEDURE calc_lft_rt_middl(para_middle_space NUMBER)
IS
BEGIN

space_occupied_in_middle := CEIL(middle_space * noof_lines_occupied_in_1_space);

noof_pics_left_side := FLOOR((100 - (space_occupied_in_middle))/2);
noof_pics_right_side := (100 - (noof_pics_left_side + space_occupied_in_middle) );

print_middle_space := middle_space;

new_line_flag := 'NO';

print_shade(noof_pics_left_side,1); -- printing the line on the left side
print_empty_space(print_middle_space); -- printing the space in between
print_shade(noof_pics_right_side,1); -- printing the line of the right side


DBMS_OUTPUT.NEW_LINE;


END;

---- #### END OF Procedure to Calculate the Left, Right , and Middle space #### ----




---- #### Proceudre to print the moon on top of the building #### ----

PROCEDURE print_moon
IS
BEGIN
-- top half of the circle

FOR noof_line_with_space in 1 .. 2
LOOP

calc_lft_rt_middl(middle_space);

middle_space := middle_space + increment_space_by ;

END LOOP;


-- bottom half of the circle
FOR bottom_half_circle in 1 .. 2
LOOP

middle_space := middle_space - increment_space_by ;
calc_lft_rt_middl(middle_space);

END LOOP;

new_line_flag := 'YES';
print_shade(100,2); -- prints the top part of the shade

END;
---- #### END OF Proceudre to print the moon on top of the building #### ----













BEGIN
total_pyramid_width:= 100;

building_1_width := 1;
building_2_width := 2;
building_3_width := 3;
building_4_width := 8;
building_5_width := 8;
building_6_width := 8;



print_shade(100,5); -- prints the top part of the shade
print_moon; -- calls the procedure to print the moon on top

--print_shade(100,5); -- prints the top part of the shade


FOR building_line_printed in 5 .. 50 -- lines printed is taken from 5 coz, 5 lines have already been printed in the print_shade
LOOP

IF building_line_printed BETWEEN 5 AND 9
THEN
check_which_building := 1;

ELSIF building_line_printed BETWEEN 10 AND 14
THEN
check_which_building := 2;
ELSIF building_line_printed BETWEEN 15 AND 19
THEN
check_which_building := 3;
ELSIF building_line_printed BETWEEN 20 AND 24
THEN
check_which_building := 4;
ELSIF building_line_printed BETWEEN 25 AND 29
THEN
check_which_building := 5;
ELSIF building_line_printed BETWEEN 30 AND 50
THEN
check_which_building := 6;

END IF;


print_buildings;


new_line_flag := 'NO';
print_shade(left_pyramid_shade_count,1);


new_line_flag := 'NO';
print_empty_space(middle_pyramid_shade_count);



new_line_flag := 'YES';
print_shade(right_pyramid_shade_count,1);

END LOOP;

END;



No comments:

Post a Comment