1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#include <iostream>
#include <vector>
using namespace std;
void enter(vector<int>&num)//takes in the empty vector from main and has the user fill it
{
int ber;
const int MAX = 20;//const variable
for (int i = 0; i < MAX;i++) {
num.push_back(ber);
cout<<"enter numbers one at a time: (-1 to finish)";
int input; // if statement combined with break to exit loop early when -1 is entered
cin>>input;
if (input == -1)
break;
}
}
void avg(vector<int>&avr)//finds the average
{
vector<int>numero(100);
int counter=0, average=0, avgsum=0;
for(int i=0; i<counter; i++)
{
int avgsum=avgsum+numero[i];
}
average=(avgsum/counter);
}
void maxi(vector<int>&mum)//finds the maximum number from the set
{
int size = mum.size(); // establish size of the vector
int max = mum[0]; // start with first stored number
for(int m = 1; m<size; m++)//compares the values to find the highest number
{
if(mum[m] > max)
max=mum[m];
}
cout<<max; // return highest value
}
void range(vector<int>&nog)
{
int ran=0;
int size = mum.size(); // establish size of the vector
int max = mum[0]; // start with first stored number
for(int m = 1; m<size; m++)//compares the values to find the highest number
{
if(mum[m] > max)
max=mum[m];
}
int min = nog[0]; // start with first stored num
for(int l = nog.size(); l<nog.size(); l--)//goes down through the numbers
{
if(nog[l] < max)
min=nog[l];
}
cout<<max-min;//subtracts the maximum from the minimum to get the range
}
void mode(vector<int>&mo)
{
int s, nu=0;
int modenum, oldnum, cnum = -1, precount, count = 0;
for(int t = 0; t<mo; t++)//t counts how many numbers are in mo
{ }
for(int e = 0; e < t; e++)//while the size is less than the counter
{
precount = 0;
oldnum = (mo + e);
for (int n = 0; n < t; n++)//
{
if(cnum == oldnum)
oldnum = (mo + (e++));
}
for(int i = 0; i < t; i++)
{
if (oldnum == mo[i])
{
precount++;
}
}
cnum = oldnum;
if (precount > count)
{
count = precount;
modenum = cnum;
}
}
cout<<modenum;
}
void bar(vector<int>&num)
{
int one=0, two=0, three=0, four=0, five=0, six=0, seven=0, eight=0, nine=0, ten=0, number=0, counter=0;
for(int i=0; i<counter; i++)//goes through the shelves of the vectorto check them
{
if(num[i]>=1&&num[i]<=5)//goes through each number and stores in 1-10 which bracket they fall under
one++;
else if(num[i]>=6&&num[i]<=10)//goes through each number and stores in 1-10 which bracket they fall under
two++;
else if(num[i]>=11&&num[i]<=15)//goes through each number and stores in 1-10 which bracket they fall under
three++;
else if(num[i]>=16&&num[i]<=20)//goes through each number and stores in 1-10 which bracket they fall under
four++;
else if(num[i]>=21&&num[i]<=25)//goes through each number and stores in 1-10 which bracket they fall under
five++;
else if(num[i]>=26&&num[i]<=30)//goes through each number and stores in 1-10 which bracket they fall under
six++;
else if(num[i]>=31&&num[i]<=35)//goes through each number and stores in 1-10 which bracket they fall under
seven++;
else if(num[i]>=36&&num[i]<=40)//goes through each number and stores in 1-10 which bracket they fall under
eight++;
else if(num[i]>=41&&num[i]<=45)//goes through each number and stores in 1-10 which bracket they fall under
nine++;
else
ten++;//goes through each number and stores in 1-10 which bracket they fall under
}
cout<<"1-5: ";
for(int i=0; i<one; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"6-10: ";
for(int i=0; i<two; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"11-15: ";
for(int i=0; i<three; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"16-20: ";
for(int i=0; i<four; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"21-25: ";
for(int i=0; i<five; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"26-30: ";
for(int i=0; i<six; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"31-35: ";
for(int i=0; i<seven; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"36-40: ";
for(int i=0; i<eight; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"41-45: ";
for(int i=0; i<nine; i++)//it displays the number of astrisks for each set of numbers
{
cout<<'*';
}
cout<<endl<<"46-50: ";//it displays the number of astrisks for each set of numbers
for(int i=0; i<ten; i++)
{
cout<<'*';
}
}
int main()
{
vector<int>begin();
enter(begin());//passes an empty vector to enter() so it can be filled
avg(begin);
maxi(begin);
range(begin);
mode(begin);
bar(begin);
system("pause");
return(0);
}
|