Object Oriented Programs

I am having trouble getting started on a couple programs.. I took an intro to programming class awhile and now I am in an advanced course and our instructor gave us some programs already without doing any review and so I don't exactly remember everything..

I was hoping I can post these programs here with help through the steps of getting the program right.. I don't want anyone to think Im asking to just to it for me as I know I need to learn from it but it is due soon and I am worried about falling behind..

I need help writing a program that declares a 50 element integer array and fill the array with random numbers between 0 and 25 inclusive. After the array is filled it then needs to output the following statistics: sum, mean, mode, largest value, and smallest value. The program should use functions to fill the array and compute each of the statistics.

Then the second program is writing a program that uses a string array to store a list of items on a grocery list. It should allow users (via menu) to add an item to the list, and display the list. Also to assume it wont need to contain more than 10 items... Functions for each 'function' of the program would be nice..

Any help will be greatly appreciated!!
You should post your effort to date. For example: I need help writing a program that declares a 50 element integer array and fill the array with random numbers between 0 and 25 inclusive...
Take it as far as you can go and post what you have. Then there'll be some context in which to offer assistance.
I'm sorry but I don't even know where to begin.. I'm willing to take this step by step with someone there isn't really a tutor where I am and I can't afford one either..
You said you need review. Here's a little review:

int foo[16];//declares an array of 16 integers named "foo"

If you're using std::rand() and std::srand() to generate pseudo-random numbers, it's handy to wrap that functionality in a function - but that may be out of the scope of your class material. Therefore, it's alright to generate and assign pseudo-random numbers like this:

1
2
3
int min = 0;
int max = 25;
int value = min+(rand()%(max+min+1));


Don't forget to seed std::rand() with std::srand() before you use it.
Also make sure to only seed it once at the beginning of your program.

You can pass an array to a function like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

void print_average(int foo[]) {

	int average = 0;
	//calculate average

	std::cout << "The average is:\t" << average << std::endl;
}

int main() {

	const unsigned short num_elements = 16;
	int foo[num_elements] = {0};

	print_average(foo);

	return 0;
}
//For Saving Random Number from 0 to 25 (Inclusive) see the following code.

#include<iostream>
using namespace std;

#define n 50

int main()
{
srand(time(NULL));

int array[n];

//Filling Array With Random Numbers
for(int i=0;i<n;i++)
{
array[i]= (rand()%25) + 1;
}

//Printing Array
for(int i=0;i<n;i++)
{
cout << "Element No." << i+1 << " is:\t" << array[i] << endl;
}

cin.ignore();
return 0;
}
Topic archived. No new replies allowed.