Array Histogram Program

Page 1 of 1

3 Replies - 360 Views - Last Post: 14 May 2013 - 05:43 AM Rate Topic: -----

#1 ericblites  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-May 13

Array Histogram Program

Posted 14 May 2013 - 01:03 AM

I've tried do complete this code as much as possible but am now completely stuck. I have gotten help up to this point, but I have entered question marks in the parts where I am struggling. I have attached a sample output screen of what the program is supposed to do. I'm trying to create 20 random numbers between 1 and 7, and creating 10 characters. Here's the code I have so far. I'm unsure how to generate this histogram.

#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;

void bubblesort( int [], int );
void bubblesort( ?, ? ); // function overloading to sort characters
void print(int[], int);
void printH(int[], int);
void print(?,?);  // function overloading to print characters
void printH(?,?);   // function overloading to print histogram for characters
int findLargest ( int a[ ] , int size )

int main()
{
	int i, magic, size;
	int high;
	int low ;
       int a[100]; // declare an integer array named a with size 100
	int b[100] // declare a character array named b with size 100
	int largest = -9999;
	
	cout << "how many random numbers do you want to create? (no more than 100)\n";
	? // read user input into variable size
	if (size > 100) 
	{
		cout << "too many, program ends.\n";
		return -1;
	}
	cout <<"enter the smallest and largest random number you want to create:\n";
	? // read user input into variables low and high

	srand(time(NULL));
	 
{ 
     for (int i = 0; i < 100; i++) 
      { 
       if (a[i] > largest) 
       largest = a[i]; 
} 
	return largest; 
}  //write a for loop to run the code inside { }. The total loops = size. 
	{
		magic = rand() % (high-low+1) + low;
		a[i] = magic;
		srand(time(NULL)+i*i+3);
	}

	cout << "\nthe random numbers generated are: \n";
	? //write a statement to call print function to print a
	bubblesort (a, size);
	cout << "\nthe random numbers after sort:\n";
	? //write a statement to call print function to print a
	cout << "\nthe histogram of the numbers:\n";
	printH(a,100);

	cout << "\n\nhow many random lower case characters do you want to create? (no more than 100)\n";
	cin >> size;
	if (size > 100) 
	{
		cout << "too many, program ends.\n";
		return -1;
	}
	
	high = 122;
	low = 97;
	srand(time(NULL));
	for (i = 0; i < 100; i++)
	{
		magic = rand() % (high-low+1) + low;
		b[i] = magic;
		srand(time(NULL)+i*i+3);
	}

	cout << "\nthe characters generated are: \n";
	print(b, size);
	bubblesort (b, size);
	cout << "\nthe characters after sort are: \n";
	print(b, size);
	cout << "\nthe histogram of the charaters:\n";
	printH(b,size);
	return 0;
}

void bubblesort( int x[], int len )
{
	? //write function definition to bubble sort the integer array x[], len is the size of x[]
}
void bubblesort(?,? )
{
	? //write function definition to bubble sort a character array
}
void print (int a[], int len)
{
	? //write function definition to print an integer array
}
void printH (int a[], int len)
{
	//function definition to print histogram of a sorted integer array
int current, shows;
	current = -1;
	shows = 0;
	for (int i = 0; i < len; i++)
	{
		if (current != a[i] )
		{
			current = a[i];
			cout << "\n" << a[i] << " *";
		}
		else
			cout << "*";
	}
	cout << endl;
}
void print (?,?)
{
	? //write function definition to print a character array
}
void printH (?,?)
{
	? //write function definition to print histogram of a sorted character array
}

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Array Histogram Program

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4236
  • View blog
  • Posts: 13,305
  • Joined: 25-December 09

Re: Array Histogram Program

Posted 14 May 2013 - 04:29 AM

I suggest you start by studying the function tutorials contained in my signature, then perhaps the following link might help: Function Overloading and Functions II

Read the tutorials and give the concept a try. If you still have problems, or questions come back and ask specific questions.



Jim
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3652
  • View blog
  • Posts: 11,421
  • Joined: 05-May 12

Re: Array Histogram Program

Posted 14 May 2013 - 05:38 AM

Dude, you've posted exactly the same code twice before in this forum?
http://www.dreaminco...-array-program/
http://www.dreaminco...lesort-program/

Are you hoping this third time is the charm? You really need to show some effort in your attempt to solve this assignment.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4236
  • View blog
  • Posts: 13,305
  • Joined: 25-December 09

Re: Array Histogram Program

Posted 14 May 2013 - 05:43 AM

Good catch. Topic closed.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1