1 Replies - 280 Views - Last Post: 25 February 2016 - 02:24 PM Rate Topic: -----

#1 zspar   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-February 16

C++ Programming Assignment Help Program terminated with signal 11

Posted 25 February 2016 - 02:18 PM

This is the assignment: Write a program that outputs a histogram of student grades for an assignment. First, the program will input the number of grades and create a dynamic array to store the grades. Then, the program should input each student's grade as an integer and store the grade in the dynamic array.

The program should then scan through the array and compute the histogram. In computing the histogram, the minimum value of a grade is 0 but your program should determine the maximum value entered by the user. Use a dynamic array to store the histogram. Output the histogram to the console.

For example, if the input is:

Enter number of grades: 6
Enter grades (each on a new line):
20
30
4
20
30
30
Then the output histogram should be:
4 *
20 **
30 ***

My program works fine for me but when I submit it online it tells me "Program terminated with signal 6." Im not sure what this is and im not sure what in my program is causing it.

Here is my code:

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
int numGrades;
int i,j;
int max = 0;
int *list, *hist;

cout << "Enter number of grades:" << endl;
cin >> numGrades;
list = new int[numGrades];
cout << "Enter grades (each on a new line):\n";

for(i=0;i<numGrades;i++)
{
cin >> *(list+i);
}

for(i=0;i<numGrades;i++)
{
if(max<*(list+i))
max = *(list+i);
}

hist = new int[max];

for(i=0;i<=max;i++)
{
int no=0;
for(int j=0;j<numGrades;j++)
{
if(i==*(list+j))
no++;
}
*(hist+i)=no;
}

cout << "Histogram:" << endl;
for(i=0;i<=max;i++)
{
if(*(hist+i)!=0)
{
cout << right << setw(3) << i << " ";
for(j=0;j<*(hist+i);j++)
cout << "*";
}
if(*(hist+i) != 0)
cout << endl;
}

delete []hist;
delete []list;

return 0;
}
Any help is appreciated, thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Programming Assignment Help Program terminated with signal 11

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14423
  • View blog
  • Posts: 57,820
  • Joined: 12-June 08

Re: C++ Programming Assignment Help Program terminated with signal 11

Posted 25 February 2016 - 02:24 PM

Do not open duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1