Electronics and Electrical Engineering watch

1. Don't really know what to do first year. 'Codeblocks'

Task 1 (30%): Create a project consisting of a single file named program.cpp
Create an empty “main” and check that program compiles: Let us get into the habit of very
frequent see if it still compiles checks. Don’t wait till the end of typing 10000 lines to see
if a code compiles! Fix the bugs one at a time as you go along, its easier.
Write in the main code lines to create an integer named i and then to ask the user via the
screen to enter a value for it in the range 0-10. We will calculate the square of their value.
Test if i is in the allowed range and if not, keep asking the user for a value until one in the
range 0-10 is entered3
. Print to the screen the square of i and ask if the user wishes to start the process again4
. If
not terminate the program.

Task 2 (35%): I think of fuel economy in terms of miles per gallon, MPG, but
the bike's display gives me miles travelled and the petrol pumps
tell me litres used.
Now modify the above program to the do the following
miles_per_gallon calculation.
MPG =4.55 * miles travelled / litres of fuel used

Create a function that accepts two floats representing miles and litres and then evaluates
and returns the MPG.
In the main code,
Ask the user to enter any values for miles and litres
Call the function and print to the screen the result for MPG
Once this works run your code and as the user enter miles=1 and litres=0
It is obvious5
that the code will crash – where and how?
Imagine we did not know why or where the crash occurred.
Start the program under the debugger6
.Step through the code one line at a time, until the
error is reached. You will get a message about floating point division by zero.
So first issue – WHERE IS THE ERROR OCCURRING – has been resolved.
The error message helps us identify WHAT CAUSED THE ERROR.
Examine the variables in the debugger to see that litres is indeed 0 – woops!
Programs don’t need to be that complicated before it becomes almost impossible to track
down errors on our own: LEARN HOW TO USE THE DEBUGGER NOW AT AN
EARLY STAGE
We often need/wish to manipulate a lot of data together.
You will please write a program to evaluate the average value of a set of float data.
We will store the float data in an array7
and we will assume a maximum of 10 values.
Write a function which must accept two arguments, the data array8
and how many data
values there are in it to be averaged. The function must return a float which is the average
of the data provided. Note if the user entered just 3 values then we must average over only
the first 3 array elements not all 10.
In the main code first create a float array to hold 10 values.
Then repeatedly ask the user how many floats they wish to enter until they enter a number
in the range 1-10.
Then ask them to enter that many data values and fill (part of) the array.
Call the averaging function and print the result to the screen.
By the way, you can choose any names you like for the data array, number of values and
the averaging function. BUT, it would daft to call them a, b and func right? When we debug
large codes we need as much help as possible, so be clear. So why not call them
data_array, number_data_elements and average_value ? Good Practice9
!

There is three tasks of it
Cus i'm first year so not sure what to do.
I hope someone can help me.
2. (Original post by Dazma17)
Don't really know what to do first year. 'Codeblocks'

Cus i'm first year so not sure what to do.
I hope someone can help me.

Related university courses

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: February 2, 2017
Today on TSR

Summer Bucket List is Back!

Start yours and you could win £150!

Why are girls so attracted to tall guys?

Poll

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE