Review problems 2

Review problems 2#

Activity 54 (Operator precedence)

You want to calculate the following formula in C#.

\[ y = ax^{3}+ (b-1) x+c \]

Which of the following expressions calculate the formula?

  1. y = a * x * x * x + b - 1 * x + c

  2. y = a * (x * x * x) + (b - 1) * (x + c)

  3. y = a * (x * x * x) + b - 1 * x + c

  4. y = a * x * x * x + (b - 1) * x + c

  5. y = (a * x) * x * x + b - 1 * (x + c)

  6. y = (a * x * x * x) + (b - 1) * x + c

  7. y = a * Math.Pow(x, 3) + b - 1 * x + c

You donโ€™t have to write any code to answer this question

Hint

Activity 55 (Coding a mathematical formula)

Write a program that receives the required input from the user and calculates y from Operator precedence. Your program should be able to accept decimal numbers like 1.2, -0.9.

For example, for a=1, b=1, c=1, and x=0.1, you should get 1.001.

Assume that the user will always provide numbers and no letters.

Warning

Dependent on the country you have selected on your operating system, you have to use , or . as the decimal separator. Otherwise 0.1 will be interpreted as 1.

Hint

Activity 56 (Processing invalid user input)

Upgrade your solution from Activity 55 so that your program does not choke ๐Ÿคฎ if the user provides wrong input like this:

Let me calculate y = ax^3 + (b-1)x + c for you ๐Ÿ™‚
a? ๐Ÿ˜›
Unhandled exception. System.FormatException: The input string '๐Ÿ˜›' was not in a correct format.

Your program should react recover like a boss as follows:

Let me calculate y = ax^3 + (b-1)x + c for you ๐Ÿ™‚
a? ๐Ÿ˜›
Your input is not a decimal number, please try again. โ†บ
a?

Steps:

  1. Design a control flow using a flowchart

  2. Implement your flowchart using C#.

If you copy paste blocks, this is fine for this problem. You donโ€™t have to implement any functions. We will implement functions in another problem.

Hint

Activity 57 (Drawing balls)

We will use raylib in this activity. Raylib is a simple library to develop games.

Install it by searching for Raylib-cs in the package manager (NuGet nuget).

Then use the following template to test your installation:

using Raylib_cs;

Raylib.InitWindow(800, 480, "Hello World");

while (!Raylib.WindowShouldClose())
{
    Raylib.BeginDrawing();
    Raylib.ClearBackground(Color.White);

    Raylib.DrawText("Hello, world!", 12, 12, 20, Color.Black);

    Raylib.EndDrawing();
}

If the template above does not work, then try the template here

Milestones:

  1. Draw a single ball

  2. Draw 10 balls in a row

  3. Draw three rows of balls with 10 balls in each row

  4. Draw the ball on another location. In other words, make it move.

  5. Create 10 balls with random colors at random places.

  6. Add velocities to each ball, so that their position changes at each frame, i.e., pos = pos + vel for x and y coordinates.

  7. If a ball goes outside the view, it should pop up again at the other side of the screen.

::