Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.224.73.124
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/cchansen/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cchansen/assignment2.cpp
//	File Name: assignment2.cpp
//
// Author:      Caitlin Hansen
// Instructor:  Dr. Wang
// Class:       Cs 212
// Due Date:    Feb. 9, 2009
// Compile:     g++ assignment2.cpp
// Run:         ./assign2.out
//
// Goal: 	The program prompts user to input 10 integers, then print the 
// 		smallest, largest, and average number found in an array.
//


#include <iostream>
#include <iomanip>

using namespace std;

const int MAX = 10;

// Function Prototypes

void readNum(int data[]);
int gradeSmallest(int data[]);
int gradeLargest(int data[]);
float gradeAverage(int data[]);

int main()
{
	int num[MAX];
	int small;
	int large;
	float average;

	// read the data to array
	readNum(num);   // call function

	cout << fixed << setprecision(1);	// force fixed for floats

	// find the smallest grade integer
	small = gradeSmallest(num);
	large = gradeLargest(num);
	average = gradeAverage(num);

	// output
	cout << endl;
	cout << "The smallest grade is: " << small << endl;
	cout << "The largest grade is: " << large << endl;
	cout << "The average grade is: " << average << endl;
	cout << "\n\nDone.Bye-Bye.\n\n";
	return 0;
}

// function that reads 10 numbers to an array
void readNum(int data[])
{
	cout << "Please input " << MAX << " your grade integers: " << endl;
	
	for(int i = 0; i < MAX; i++)
		cin >> data[i];
}

// function to find the smallest
int gradeSmallest(int data[])
{
	int s = data[0];
	for(int i = 1; i < MAX; i++)
	{
		if(s > data[i])
			s = data[i];
	}
	return s;
}

// function to find the largest grade integer
int gradeLargest(int data[])
{
	int l = data[0];
	for(int i = 1; i < MAX; i++)
	{
		if(l < data[i])
			l = data[i];
	}
	return l;
}

// function to find the average grade integer
float gradeAverage(int data[])
{
	int sum = 0;
	float average = 0.0;
	for(int i = 0; i < MAX; i++)
		sum = sum + data[i];
	average = (static_cast<int>(sum * 100.0) / MAX) / 100.0;
	return average;
}

Stv3n404 - 2023