You are allowed to bring 1/2 page (8.6" x 5.5") of notes (1 sided only) and a calculator to the first exam.
Be sure to know:
Write out the output of the following program:
(It is recommended that you trace the variables (i.e. write out the progression of the values held by the variable), so you can gain back points if you make a mistake.)
#include <stdio.h>
int main () {
int var1;
int var2;
int var3;
var1 = 2;
var2 = 10;
var3 = 5;
while (var1 <= var2) {
printf("var1: %d\n", var1);
printf("var2: %d\n", var2);
var1 = var1 + 1;
var2 = var2 - 1;
if (var2 <= 9) {
printf("A\n");
if (var1 >= 8) {
printf("C\n");
} else {
if (var3 < 2) {
printf("E\n");
}
}
if (var1 == var2) {
printf("%d == %d\n", var1, var2);
} else {
if (var1 + 4 <= var2 + var3) {
printf("F\n");
}
}
}
var3 = var2 - var1;
}
return 0;
}
(Write Your Own Program Problem:)
A moving average can be very useful in statistics and financial applications. It is also known as the rolling average, running average, moving mean, or running mean. For systems engineers, they might recognize it as a type of finite impulse response filter.
For this problem, our simple moving average (SMA) will be defined as the unweighted mean of the previous n data points. The formula is given below. N = the most recent data point. n = the size of the window or how many data points to average.
You might need a moving average when you are analyzing stock prices, lab experiment data, or power level consumption of a satellite.
Write a program that will allow the user to enter in data points. After each data point entered, the program will return the simple moving average using a moving average calculation with window size = 3. That is the average of the last 3 data points entered.
Assume the user will enter valid decimal numbers. and that the initial data points entered are all 000.
The program ends when the user inputs 999.
Don’t worry about rounding or truncating errors. Just let printf handle the precision.
Please enter in your data point (999 will end this program):
[user enters 1.0]
The current moving average is 0.333333
Please enter in your data point (999 will end this program):
[user enters 1.0]
The current moving average is 0.666667
Please enter in your data point (999 will end this program):
[user enters 1.0]
The current moving average is 1.000000
Please enter in your data point (999 will end this program):
[user enters 1.0]
The current moving average is 1.000000
Please enter in your data point (999 will end this program):
[user enters 999]
Ending program...
Please enter in your data point (999 will end this program):
[user enters 100]
The current moving average is 33.333333
Please enter in your data point (999 will end this program):
[user enters 200]
The current moving average is 100.000000
Please enter in your data point (999 will end this program):
[user enters 300]
The current moving average is 200.000000
Please enter in your data point (999 will end this program):
[user enters 400]
The current moving average is 300.000000
Please enter in your data point (999 will end this program):
[user enters 999]
Ending program...
Please enter in your data point (999 will end this program):
[user enters 200]
The current moving average is 66.666667
Please enter in your data point (999 will end this program):
[user enters 400]
The current moving average is 200.000000
Please enter in your data point (999 will end this program):
[user enters 300]
The current moving average is 300.000000
Please enter in your data point (999 will end this program):
[user enters 100]
The current moving average is 266.666667
Please enter in your data point (999 will end this program):
[user enters 300]
The current moving average is 233.333333
Please enter in your data point (999 will end this program):
[user enters 200]
The current moving average is 200.000000
Please enter in your data point (999 will end this program):
[user enters 400]
The current moving average is 300.000000
Please enter in your data point (999 will end this program):
[user enters 999]
Ending program...
Write a program that calculates how long it will take you to walk x amount of miles. Assume your walking speed is 3.1 miles/hour.
The program should prompt the user to enter the amount of miles to walk and should print out the time it would take in minutes. Both of those values should be float. The program should continue to prompt the user to enter a new amount of miles until the user enters 0. When the user enters 0 the program should quit. You should write and use the function with the prototype given below. You should also use a macro for your walking speed. Name this macro "SPEED".
float Estimated_Time_Of_Arrival(float miles);
//Given: given the amount of miles needed to travel as a float value
//Return: Returns the amount of minutes it would take to walk given miles as a float value
Write and use this function in your main program.