this is the majority of the assignment
Quote
Create a function called howMany that will search a two dimensional array for the the number of occurences a particular number is found within the array. Your function should return the number of occurences the number appears within the array and the cooridnates that each one is found.
Your function at the very least should take as arguments the number to search for, and the two dimensional array. You are going to need some mechanisim to return the coordinates. You could use a string, an array, or a 2D array here but I will leave that up to you. This means your function needs at least 3 arguments!
b.) Create another function that will take as arguments integer values that represent row, column coordinates. return the value at that location
c.) Write a function that will fill the array with random numbers from 1 - 10. Initially, your array should be 10 rows by 9 columns
Finally write some kind of driver to demostrate the functionality of your program. It would be nice if you used some kind of a loop and a simple menu scheme.
Your function at the very least should take as arguments the number to search for, and the two dimensional array. You are going to need some mechanisim to return the coordinates. You could use a string, an array, or a 2D array here but I will leave that up to you. This means your function needs at least 3 arguments!
b.) Create another function that will take as arguments integer values that represent row, column coordinates. return the value at that location
c.) Write a function that will fill the array with random numbers from 1 - 10. Initially, your array should be 10 rows by 9 columns
Finally write some kind of driver to demostrate the functionality of your program. It would be nice if you used some kind of a loop and a simple menu scheme.
i think what i have for code is write, but can someone help me with this driver? did i do it right?
rep for help
thanks everyone
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
void fill(int a[][9], int row);
void print(int a[][9], int row);
int howMany(int a[][9], int num);
//===========================================================
int main()
{
int array[10][9];
int num = 0, occ;
fill(array,9);
print(array,9);
cout << "Enter the number to search for: ";
cin >> occ;
occ = howMany(array, num);
while(num = true)
{
cout << "Number of occurrences; " << occ << endl;
}
cout << "Not found " << endl;
return 0;
}
//===========================================================
void fill(int a[][9], int row)
{
srand(time(0));
for(int row = 0; row < 10; row++)
{
for(int col = 0; col < 9; col++)
{
a[row][col] = (rand() % 10) + 1;
}
}
}
//===========================================================
void print(int a[][9], int row)
{
for(int row = 0; row < 10; row++)
{
for(int col = 0; col < 9; col++)
{
cout << a[row][col] << "\t";
}
}
}
//===========================================================
int howMany(int a[][9], int num)
{
int count = 0;
for(int r = 0; r < 10; r++)
{
for(int c = 0; c < 9; c++)
{
if(a[r][c] == num)
{
// a[10][10] = r; //i dont really know what this line is for? lol
// a[9][9] = c;
count++;
cout << "row: " << r << "\t"<< " col: " << c << " contains the number " << num << endl;
}
}
}
return count;
}
OK changes: i got the code to run, but it doesnt run right, it just outputs number of occurances 0 a million times.
UGH SO CLOSE


Sign In
Create Account


Back to top










