homework9-godara

homework9-godara - ECE 1574 Homework Set #9 Problem Solving...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 1574 Homework Set #9 Problem Solving with C++ Due date: 3/28/10 by 11:55 p.m. This assignment is to be done individually Complete the lab exercise and answer questions 1 and 2 during the lab session. Answer the other questions later. LAB EXERCISE 1. Use the statement int set [20]; Write a program that uses pointers to store the value 0 in the first ten elements of the array and 99 in the second 10 elements of the array. Output the values of the array to the screen and capture the output as part of your solution. #include <iostream> using namespace std; int main() { int i; int set[20] = {0,0,0,0,0,0,0,0,0,0,99,99,99,99,99,99,99,99,99,99}; for (i = 0; i < 20; i++) { cout << set[i] << " " ; } cout << endl; return 0; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. Write a program that dynamically allocates an array large enough to hold a user- defined number of test scores. Once all of the scores are entered, the array should be passed to a function that sorts them into descending order. Another function should calculate the average score. A third function should calculate the standard deviation for the scores. The program should display the sorted list of scores, the average, and the standard deviation. Use pointer notation rather than arrays. Be sure that your program dynamically allocates enough memory to handle the number of values that a user might want to enter. The first number a user enters tells the program how many scores will be entered. Be sure that your program checks to ensure that input values are between 0 and 100 inclusive. Supply at least three sets of input data and display the corresponding output to convince us that your program works properly. #include <iostream> #include <new> #include <cmath> using namespace std; int avg( int *, int ); //proto int sort( int *, int ); //proto double stdDev ( int *, int , double ); //proto // * int main() { int numgrades, i ; cout << "How many grades do you wish to process? Enter here: " ; cin >> numgrades; int *grades = new int [numgrades]; //creates an array for (i = 0; i < numgrades; i++) { cout << "Enter a grade to be processed: " ; cin >> grades[i]; if (grades[i]<0 || grades[i]>100) { cout << "ERROR: Grades need to be in between 0 and 100. Please re-enter a new grade: "
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

homework9-godara - ECE 1574 Homework Set #9 Problem Solving...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online