CSE102 – Computer Programming Homework #1

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

Professor Oak who is known as Pokémon creator, lost his laboratory on a
explosion because of an mischievous fire Pokémon. After so much effort, Prof. Oak
rebuild his own lab but he couldn’t activate Pokémon creating machine because
storage of the machine has broken. Professor can do wonders with Pokémon’s but
he doesn’t know anything about software developing. Therefore, he asked
students of Gebze Technical University for help to make the machine functional
again. Professor send an image of the old machine’s control panel that is shown
below:
MENU
Create Body
Set Color
Load Moves
Set Attack Power
Show Current Pokémon
You are expected to code a function for each menu option. Write the code of the
functions that are shown below by obeying given function prototypes.
Part 1. [20pts] Write a function that takes shape of the Pokémon as an input
and calculates area of the shape and returns it. Parameters that are used to
calculate the area of the shape must be taken from the user in the function.
Number of the parameters can be changed according to the shape of the Pokémon.
The shapes could be rectangular, square or circular and all the shape types must
be pre-defined on the program like: Square is 1, rectangular is 2 and circular is 3.
The function prototype is:
double CreateBody (int shape)
Part 2. [20pts] Write a function that takes a color code as an integer input to
paint the Pokémon and returns revised color code. If the color code is between 0
Page 1 of 3
CSE102 – Spring 2019 Homework #1
and 1000 then the function returns modulo five of the code, otherwise, it always
returns 1 as the revised color code. The colors could be red, yellow, blue, black or
white and all the colors must be pre-defined on the program like: red is 0, yellow is
1, blue is 2, black is 3 and white is 4. The function prototype is:
int SetColor (int color)
Part 3. [20pts] Write a function that takes shape and size of the body as an
input and calculates length of one move of the Pokémon and returns the length.
The length of one move is equal to perimeter of the body (Assume that the shorter
edge is 5 if the shape is rectangular). The function prototype is:
double LoadMoves(int shape, double body_size)
Part 4. [20pts] Write a function that specifies attack power of the Pokémon. It
takes lower and upper bound of the attack power and generates a random integer
attack power between the bounds and returns the power. The function prototype is:
int SetAtackPower(int lower_bound, int upper_bound)
Part 5. [20pts] Write a function that prints created Pokémon with its wonderful
specifications like the figure that is shown below:
(Rectangular Pokémon example)
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
Name: Rectangular Pokémon
Size: 35
Color: Red
Move: 24
Attack Power: 78
(Circular Pokémon example)
X
X X
X
Name: Circular Pokémon
Size: 28.26
Color: Blue
Move: 18.84
Attack Power: 102
As you notice, the shapes of the Pokémon’s are dynamic and that means you
should print them according to their size. On the figure that is shown above, the
function prints X’s by the length of the edges on vertical and horizontal direction
(Assume that the shorter edge is 5 if the shape is rectangular). If the shape is
Page 2 of 3
CSE102 – Spring 2019 Homework #1
circular then put tabs between two X’s which are on the middle of the shape as
much as minus one of the radius of the shape, and align the other rows as
expected by using the middle row. The function prototype is:
void ShowPokemon(int shape, double body_size, int color, double
move_length, int attack_power)
The main function must be like as shown above:

int main ()
{
int shape, color, attack_power;
double size_of_body, move_length;
shape = RECTENGULAR / CIRCULAR / SQUARE // Pick one of them
size_of_body = CreateBody (shape)
color = 798
color = SetColor(color)
move_length = LoadMoves(shape, size_of_body)
attack_power = SetAttackPower (0, 150)
ShowPokemon(shape, size_of_body, color, move_length, attack_power)
}
General Rules:
1. Obey and don’t broke the function prototypes that are shown on each part,
otherwise, you will get zero from the related part.
2. The program must be developed on Linux based OS and must be compiled
with gcc compiler, any problem which rises due to using another OS or
compiler won’t be tolerated.
3. Note that if any part of your program is not working as expected, then you
can get zero from the related part, even it’s working in some way.
4. Upload your .zip file on to Moodle to deliver your homework. The zip file
must consist of one .c file that contains the code of your solutions. Name
format can be found on the top of this homework sheet.
5. You can ask any question about the homework by sending an email to
b.koca@gtu.edu.tr .
Page 3 of 3