Question
Okay so the program runs but the output is blank it just says Name Catagory and reveals no data so here is the new code
Okay so the program runs but the output is blank it just says
Name Catagory
and reveals no data so here is the new code I need it to display what the output shows in the question
-------------------------------------------------------------------------------------------------------------
#include
#include
#include
#include
using std::ifstream;
using std::cout;
using std::endl;
using std::string;
using namespace std;
class Bubble
{
private:
static const int SIZE = 10;
string val[SIZE];
int cc;
string hurricanes[40];
int category[40];
ifstream inRandom; //input file
//methods
void openFile();
void testFile();
void closeFile();
void populate(); //read through the file populating the array
void bubblesort();
void display();
public:
void driver();
};
/******************MAIN****************/
int main()
{
Bubble b; //object of class BUBBLE
b.driver(); //order of execution
system("pause");
return 0;
}
/*****************Method Definitions*********************/
//Bubble: driver
//order of execution
void Bubble::driver()
{
openFile(); //open the input file
populate(); //populate the array with the contetns of the input file
closeFile(); //closes the input file
bubblesort(); //sort the array using the bubblesort method
display(); //display the output
}
//Bubble: openFile
//open the input file
void Bubble::openFile()
{
ifstream infile;
infile.open("FloridaHurricanes.txt");
int cc = 0;
string hurricanes[40];
int category[40];
while (infile >> hurricanes[cc])
{
infile >> category[cc];
cc++;
}
}
//Bubble: testFile
//test if the input file opened properly
void Bubble::testFile()
{
if (!inRandom)
{
std::cerr << "Colors.txt did not open properly." << endl;
system("pause");
exit(1999);
}
}
//Bubble: closeFile
//close the input file
void Bubble::closeFile()
{
inRandom.close();
}
//Bubble: populate
//populate the array with the input file values
void Bubble::populate()
{
for (int i = 0; i < SIZE; i++) //Everytime this loops it increases the value of "i" by 1 which then reads a seperate line of the file and assigns that data the val variable to the next number ex: i[0] = 77, i[1] = 66 ...
inRandom >> val[i];
}
//Bubble: bubblesort
//sort the array using the bubblesort method
void Bubble::bubblesort()
{
for (int i = 0; i < cc; i++)
{
for (int j = 0; j < cc - 1 - i; j++)
{
if (hurricanes[j] > hurricanes[j + 1])
{
string temp = hurricanes[j];
hurricanes[j] = hurricanes[j + 1];
hurricanes[j + 1] = temp;
int temp1 = category[j];
category[j] = category[j + 1];
category[j + 1] = temp1;
}
}
}
}
//Bubble: display
//display the contents of the sorted array
void Bubble::display()
{
cout << left;
cout << setw(12) << "Name" << setw(12) << "Category" << endl;
for (int i = 0; i < cc; i++)
cout << setw(12) << hurricanes[i] << setw(12) << category[i] << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started