# Electronics and Electrical Engineering watch

Announcements
1. This is some questions from my course, here is the program 'codeblocks'

There are 3 tasks. If someone can help me to do, I will be really happy
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
!

Thank you
2. (Original post by Dazma17)
This is some questions from my course, here is the program 'codeblocks' .........................

There are 3 tasks. If someone can help me to do, I will be really happy
Thank you
Apologies from the start for being so blunt, but I think you need to take in some truths:

This task is not and should not be about anyone helping you to get good marks.

This is about YOU learning the very basics of coding, compiling and debugging in whatever language your course has chosen (from the file extension in your first task that language is C++) and to start the habit of good disciplined coding practices.

It's an engineering degree with you learning to be an engineer and being adept at using the tools you need to practice as an engineer. Think of it as a learned skill like a carpenter or artist uses tools to produce their work.

The only way you can do that is to pick up the tools and use them. Start by getting a good book teaching C++ programming, go 'hands on', learn the fundamentals and only then follow the instructions given by your coursework.

The SAMS publisher produced an excellent 'teach yourself' series, see here: https://www.amazon.co.uk/Sams-Teach-.../dp/067232072X

There is no shortcut on this.

If you are studying electronics, then your life will in good measure revolve around analysing a problem, decomposing it, designing a set of algorithms to solve it, coding it, compiling, running, debugging and testing.

Unless you get your hands dirty now, you will struggle with everything else the course asks from you.

Not least of which will be your final dissertation which will inevitably require a complex project you designed, built and tested yourself.

Effort now will pay rewards when the tasks get a lot harder. Start now. Good luck.

### 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

### Exam Jam 2018

Join thousands of students this half term

### Solo - A Star Wars Story

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