Question #4965

Write a program that does the following:

• Input is a list of (any number of) n positive integers, terminated by input of -1.

• Output is a (sideways) histogram which represents the list of numbers. Specifically, the output consists of n lines. Each line i consists of x asterisks, where x is the ith number in the input.

• Input is a list of (any number of) n positive integers, terminated by input of -1.

• Output is a (sideways) histogram which represents the list of numbers. Specifically, the output consists of n lines. Each line i consists of x asterisks, where x is the ith number in the input.

Expert's answer

// Histogram of the entered values.cpp : Defines the entry point for the console

application.

//

#include "stdafx.h"

#include "conio.h"

#include

<iostream>

using namespace std;

int _tmain(int argc, _TCHAR*

argv[])

{

int value;

int countfor1=0;

int countfor2=0;

int

countfor3=0;

int countfor4=0;

int countfor5=0;

int

arrayvalue[1000];

cout<<"Enter

value:";

for(;;){

cin>>value;

if(value>=1 &&

value<=5){

if(value==1){

countfor1++;

}

if(value==2){

countfor2++;

}

if(value==3){

countfor3++;

}

if(value==4){

countfor4++;

}

if(value==5){

countfor5++;

}

}else{

break;

}

}

char str1[80];

strcpy

(str1,"");

for(int i=0;i<countfor1;i++){

strcat

(str1,"*");

}

char str2[80];

strcpy (str2,"");

for(int

i=0;i<countfor2;i++){

strcat (str2,"*");

}

char str3[80];

strcpy (str3,"");

for(int i=0;i<countfor3;i++){

strcat

(str3,"*");

}

char str4[80];

strcpy (str4,"");

for(int

i=0;i<countfor4;i++){

strcat (str4,"*");

}

char str5[80];

strcpy (str5,"");

for(int i=0;i<countfor5;i++){

strcat

(str5,"*");

}

cout<<"\n"<<"Output"<<"\n";

cout<<"1

"<<str1<<"\n";

cout<<"2

"<<str2<<"\n";

cout<<"3

"<<str3<<"\n";

cout<<"4

"<<str4<<"\n";

cout<<"5

"<<str5<<"\n";

getch();

return 0;

}

application.

//

#include "stdafx.h"

#include "conio.h"

#include

<iostream>

using namespace std;

int _tmain(int argc, _TCHAR*

argv[])

{

int value;

int countfor1=0;

int countfor2=0;

int

countfor3=0;

int countfor4=0;

int countfor5=0;

int

arrayvalue[1000];

cout<<"Enter

value:";

for(;;){

cin>>value;

if(value>=1 &&

value<=5){

if(value==1){

countfor1++;

}

if(value==2){

countfor2++;

}

if(value==3){

countfor3++;

}

if(value==4){

countfor4++;

}

if(value==5){

countfor5++;

}

}else{

break;

}

}

char str1[80];

strcpy

(str1,"");

for(int i=0;i<countfor1;i++){

strcat

(str1,"*");

}

char str2[80];

strcpy (str2,"");

for(int

i=0;i<countfor2;i++){

strcat (str2,"*");

}

char str3[80];

strcpy (str3,"");

for(int i=0;i<countfor3;i++){

strcat

(str3,"*");

}

char str4[80];

strcpy (str4,"");

for(int

i=0;i<countfor4;i++){

strcat (str4,"*");

}

char str5[80];

strcpy (str5,"");

for(int i=0;i<countfor5;i++){

strcat

(str5,"*");

}

cout<<"\n"<<"Output"<<"\n";

cout<<"1

"<<str1<<"\n";

cout<<"2

"<<str2<<"\n";

cout<<"3

"<<str3<<"\n";

cout<<"4

"<<str4<<"\n";

cout<<"5

"<<str5<<"\n";

getch();

return 0;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment