99 017
Assignments Done
98.9%
Successfully Done
In May 2021

# Answer to Question #4965 in C++ for Savi

Question #4965
Write a program that does the following:
&bull; Input is a list of (any number of) n positive integers, terminated by input of -1.
&bull; 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.
1
2011-11-04T09:51:01-0400
// 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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!