0% found this document useful (0 votes)
55 views2 pages

Section Three Tutorial: 1. Debugging Pointers and References

1. The first section describes a program that converts temperature values between Celsius and Fahrenheit by passing values by reference and pointer into functions. The task is to locate and fix bugs in this code. 2. The second section involves a program that calculates the correlation between two data samples of heights and weights. The comments describe the steps needed and the task is to complete the program to obtain a correlation of around 0.78. 3. The third section adapts an existing medals program to calculate total medals won per million inhabitants for each country. The tasks are to complete the program ordering by this new metric and add one statement to calculate the correlation between medals and population with little expected correlation.

Uploaded by

SAKTHIVEL A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
55 views2 pages

Section Three Tutorial: 1. Debugging Pointers and References

1. The first section describes a program that converts temperature values between Celsius and Fahrenheit by passing values by reference and pointer into functions. The task is to locate and fix bugs in this code. 2. The second section involves a program that calculates the correlation between two data samples of heights and weights. The comments describe the steps needed and the task is to complete the program to obtain a correlation of around 0.78. 3. The third section adapts an existing medals program to calculate total medals won per million inhabitants for each country. The tasks are to complete the program ordering by this new metric and add one statement to calculate the correlation between medals and population with little expected correlation.

Uploaded by

SAKTHIVEL A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Section Three Tutorial

1. Debugging pointers and references


The program conversion_bugs.cpp converts an integer and a
floating point temperature from celsius into degrees fahrenheit.
Values are passed by reference into the functions, the integer value
with a reference and the floating point value with a pointer. Locate
and fix all of the bugs in the code.

2. Correlation
The aim of the program correlation.cpp is to find the
correlation between two data samples. One data sample has a list of
heights and other a list of weights. The comments throughout the
code indicate the steps needed to calculate the correlation between
the two data samples. Follow these steps and complete the program.
Ensure that the correlation between the data sets is approximately
0.78.

3. Population Weighted Medal Table


The program medals.cpp from tutorial 2 will now be adapted to
calculate the total number of medals won by each country divided by
the country’s population (in millions).
a) Using the comments in medals2.cpp as a guideline complete the program
to display the medals table ordered by total medals won per million
inhabitants of each country.
b) Show that there is little to no correlation between the medals tally at the 2004
Olympics to the total population of a country. The calculation of this
correlation must be implemented with just one extra statement to the existing
code.

1
Section Three Tutorial
Notes for Question 1

• Try and remove the bugs that do not involve pointers and references first so that
the more subtle errors are easier to find. Are there differences between the
function declarations and definitions? Are there type errors in the assignment
statements?

Notes for Question 2

• In this program you will use the functions you developed in stats. Remember
that the three functions are in every way like mathematical functions exp() and
sqrt(). All you need to provide is the correct number of input arguments of
the correct type.
• Unlike previous uses of stats the data will be read from a file. The code for this
step is already completed. Just make sure that the file statsfile.cpp is
included in the compilation step.
• Refer to any decent statistics book for the equation for the correlation
coefficient!

Notes for Question 3

• Leave the correlation calculation until part b).


• To calculate the correlation between medals tally and population you will have
to return to the correlation program from Question 2. Try and convert the code
contained in this program into a function that accepts two data samples as input
and returns the resulting correlation value.
• How will you call this correlation function from inside medals2.cpp? Make
sure that you have created all the necessary implementation and header files.
• Be careful with the compilation step! Have you included all the implementation
files needed for the program?

You might also like