Review problems 2#
Activity 54 (Operator precedence)
You want to calculate the following formula in C#.
Which of the following expressions calculate the formula?
y = a * x * x * x + b - 1 * x + cy = a * (x * x * x) + (b - 1) * (x + c)y = a * (x * x * x) + b - 1 * x + cy = a * x * x * x + (b - 1) * x + cy = (a * x) * x * x + b - 1 * (x + c)y = (a * x * x * x) + (b - 1) * x + cy = a * Math.Pow(x, 3) + b - 1 * x + c
You donโt have to write any code to answer this question
Hint
section Operator precedence
section Math expressions
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
section Operator precedence
section Conversion between datatypes
Convert.*orTryParse
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:
Design a control flow using a flowchart
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
section flowcharts
section Conversion between datatypes
Convert.*vsTryParse
section Boolean logic
negation
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 ).
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:
Draw a single ball
Draw 10 balls in a row
Draw three rows of balls with 10 balls in each row
Draw the ball on another location. In other words, make it move.
Create 10 balls with random colors at random places.
Add velocities to each ball, so that their position changes at each frame, i.e.,
pos = pos + velfor x and y coordinates.If a ball goes outside the view, it should pop up again at the other side of the screen.
::