Write a PL/SQL program to draw a car - 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 a car

Draw a car using PL/SQL

Program:

DECLARE

len_of_car_top NUMBER := 20; -- taking length of car top as a constant value
space_infront_of_car NUMBER := len_of_car_top * 3; -- Multiply by 3 to make enought space for the front of the car
space_btn_frnt_back_glass NUMBER := len_of_car_top + 25; -- This is the space between the front and back glass equating to
-- the len of the top of car,coz inc the

space_infront_engine NUMBER;
last_middle_space NUMBER;

print_space VARCHAR2(1) := 'Y';
tot_car_width NUMBER;

engine_line NUMBER;
bumper_line NUMBER;

tire_size1 NUMBER := 15;
tire_size2 NUMBER := 15;

tire_size3 NUMBER := 15;








---- #### Procedure to print empty space in the front before printing something #### ----
PROCEDURE print_empty_hori_space(para_len_of_empty_line NUMBER)
IS
BEGIN
FOR empty_line_len in 1 .. para_len_of_empty_line
LOOP
DBMS_OUTPUT.PUT(' ');
END LOOP;

END;
----#### END of procedure to print empty space in the front before printing something #### ----







-- #### PROCEDURE to print a horizontal line of stars #### ----

PROCEDURE print_hori_line(para_len_of_line NUMBER)
IS
BEGIN

IF print_space = 'Y'
THEN
print_empty_hori_space(space_infront_of_car); -- multily by 3 to make enough space for the front engine
END IF;


FOR for_line_len in 1 .. para_len_of_line
LOOP

DBMS_OUTPUT.PUT('+');
END LOOP;
END;

---- #### end of Procedure to print a horizontal line of stars #### ----







---- #### Procedure to print empty lines for the picture to move down #### ----
PROCEDURE print_empty_lines(para_noof_empty_lines NUMBER)
IS
BEGIN

FOR space_above in 1 .. para_noof_empty_lines
LOOP
dbms_output.new_line;
END LOOP;
END;

----#### End of Procedur to print empty line for the picture to move down #### ----






---- #### Procedrue to print slant lines of the car front and rear glass #### ----
PROCEDURE print_frnt_rear_glasses(para_len_of_glass NUMBER)
IS
BEGIN

FOR print_middle_space in 1 .. para_len_of_glass
LOOP
space_infront_of_car := space_infront_of_car - 4; -- this will reduce the space infront of the car to get a


print_empty_hori_space(space_infront_of_car); --slant appears for the front glass of the car

DBMS_OUTPUT.PUT('+');

print_empty_hori_space(space_btn_frnt_back_glass);

DBMS_OUTPUT.PUT('+');
DBMS_OUTPUT.NEW_LINE;

space_btn_frnt_back_glass := space_btn_frnt_back_glass + 6;
END LOOP;
space_infront_engine := space_infront_of_car;
last_middle_space := space_btn_frnt_back_glass;
--DBMS_OUTPUT.PUT_LINE(SPACE_INFRONT_ENGINE);
--DBMS_OUTPUT.PUT_LINE(LAST_MIDDLE_SPACE);
END;


---- ####END OF procedure to print slant lines of the care for front and rear glass #### ----





---- ####Procedure to print bumper and engine of the car #### ----
PROCEDURE print_engine_n_bumper --(para_len_of_engineNbumper NUMBER)
IS
BEGIN
engine_line := space_infront_of_car - 37;
print_space := 'N';


print_empty_hori_space(25);
print_hori_line(engine_line);
print_empty_hori_space(LAST_MIDDLE_SPACE);

print_hori_line(engine_line );
DBMS_OUTPUT.NEW_LINE;

END;

---- ####END OF Procedure to print bumper and engine of the car #### ----






----#### Procedure to print the front and rear vertical lines in the car #### ----

PROCEDURE frnt_rear_verti_lines
IS
BEGIN

FOR len_of_front_verti_lines in 1 .. 3
LOOP
print_empty_hori_space(25);
DBMS_OUTPUT.PUT('*');


/* --delete

print_empty_hori_space(60);
dbms_output.put('+');
print_empty_hori_space(7);
dbms_output.put('+');

-- delete*/


tot_car_width := LAST_MIDDLE_SPACE - 10 ;
print_empty_hori_space(engine_line + LAST_MIDDLE_SPACE + engine_line + 19);
DBMS_OUTPUT.PUT('+');
DBMS_OUTPUT.NEW_LINE;
END LOOP;

END;

----#### END OF Procedure to print the front and rear vertical lines in the car #### ----





---- #### Procedure to print the bottom part of the car #### ----
PROCEDURE bottome_of_car
IS
BEGIN
print_empty_hori_space(25);
print_hori_line(tot_car_width);
DBMS_OUTPUT.NEW_LINE;
END;

---- #### Procedure to print the bottom part of the car #### ----





---- #### Procedrue to print wheels of the car #### ----
PROCEDURE wheels_of_car
IS
BEGIN

FOR tire in 1 .. 2
LOOP

print_empty_hori_space(25);
print_empty_hori_space(tire_size1);
DBMS_OUTPUT.PUT('*');
print_empty_hori_space(tire_size2);
dbms_output.put('*');





print_empty_hori_space(35);

Print_empty_hori_space(tire_size3);
DBMS_OUTPUT.PUT('*');
print_empty_hori_space(tire_size2);
dbms_output.put('*');

tire_size1 := tire_size1 + 3 ;
tire_size2 := tire_size2 - 8;

tire_size3 := tire_size3 + 9;



dbms_output.new_line;
END LOOP;


END;
---- #### Procedrue to print wheels of the car #### ----






BEGIN

print_empty_lines(5); -- this will print 5 empty lines, this will make the picture to go down by 5 lines

print_hori_line(len_of_car_top); -- this will print a horizontal line
dbms_output.new_line;
print_frnt_rear_glasses(3);
print_engine_n_bumper;
frnt_rear_verti_lines;
bottome_of_car;
wheels_of_car;


END;

No comments:

Post a Comment