1-2P Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SIT102 – Introduction to Programming

Answers for 1.2P Shape Drawing


Student Name:
Student ID:

Question 1: Why do we create procedures? What are the advantages of doing this? How will
this helps make it easier to build larger programs?

Procedures can be used throughout a program, making them simpler and


quicker to code.
There are various advantages of procedure oriented programming languages :-

1. It is good for general purpose programming


2. We can re-use pieces of code in a program without writing them
again, by the virtue of method calling.
3. We can structure a program based on these methods and have a
cleaner and more maintainable code when compared to the
languages it succeeded 

When writing programs it is very easy to end up with long-winded, repetitive


code which is hard to understand and debug. This is because the same task
often needs to be carried out in different places in the program. Procedures
can be used throughout a program, making them simpler and quicker to code.

Question 2: C++ programs start executing from a specific location in the code. Where do
these instructions start executing from? In what order will these instructions be executed?

Every C++ program has a primary function that must be named main().


The main() function serves as the starting point for program execution. It
usually controls program execution by directing the calls to other functions in
the program.

Question 3: There are different (overloaded) version(s) defined for fill_rectangle(…) in


SplashKit ( https://www.splashkit.io/api/graphics/#group-fill-rectangle ). With an aid of one
of its available versions (please choose one), elaborate the definition of fill_rectangle(…) in
regard to its input parameters. Give an example for each input parameter (what could be a
valid passed-in value) respectively in a procedure call to it.

This element specifies a fill rectangle. When stretching of an image is specified, a source
rectangle, srcRect, is scaled to fit the specified fill rectangle.

Each edge of the fill rectangle is defined by a percentage offset from the corresponding edge of
the shape's bounding box. A positive percentage specifies an inset, while a negative percentage
specifies an outset. For example, a left offset of 25% specifies that the left edge of the fill
rectangle is located to the right of the bounding box's left edge by an amount equal to 25% of
the bounding box's width.

Pass value to fill_rectangle(…) procedure


 fill_triangle(COLOR_ORANGE, 250, 450, 400, 300, 550, 450);
    fill_triangle(COLOR_ORANGE, 250, 150, 400, 300, 550, 150);
    fill_triangle(COLOR_PURPLE, 250, 150, 400, 300, 250, 450);
    fill_triangle(COLOR_PURPLE, 550, 150, 400, 300, 550, 450);
    fill_rectangle(COLOR_WHITE, 350, 250, 100, 100);
    fill_ellipse(COLOR_BLACK, 375, 275, 50, 50);
    fill_rectangle(COLOR_WHITE, 385, 285, 30, 30);

-- End of questions (3) --

You might also like