Create a text file of the following data.
called data.txt
1000 4.0
1000 2.0
1000 1.5
1010
2.0
1010 2.2
1010 1.9
1050 2.8
1050 4.2
1100 1.7
1100
1.6
1250 2.2
1250 4.5
1300 4.0
1300 5.1
1300 3.4
1350
1.1
1350 1.2
1350 2.0
Lake ID Lake
Name
---------------------------------------
1000 Chemo
1010 Eddington
1050 Hopkins
1100 Toddy
1250 Branch
1300 Phillip
1350 Green
#include
#include
using namespace std;
int main ( )
{
int lakeid; // Lake ID declartion
double fishwgt; // fish weight in pounds declartion
char LakeName; // Lake name in Charchter declartion
ifstream fin; // declare input file stream object
fin.open ("data.txt"); // open the file
if ( fin.fail( ) )
{
cerr << "open failure";
exit(1); // end the program with an error return code
}
fin >> lakeid >> fishwgt; // read the int lakeid and the double fishwgt values
switch (lakeid)
{
case 1000 : LakeName = "Chemo";
case 1010 : LakeName = 'Eddington';
case 1050 : LakeName = 'Hopkins';
case 1100 : LakeName = 'Toddy';
case 1250 : LakeName = 'Branch';
case 1300 : LakeName = 'Phillip';
case 1350 : LakeName = 'Green';
}
cout << lakeid <<"\t"<<<"\n";
fin.close();
return 0;
}
#include
#include
#include
#include
#include
int main ( )
{
unsigned int lakeID;
double fishWeight;
std::string lake;
std::vector lakes;
std::vector lakesID;
std::vector fish;
std::ifstream data( "data.txt" );
if( data.is_open() != true )
{
std::cerr << "open failure";
return 1;
}
while( data >> lakeID >> fishWeight )
{
lakesID.push_back(lakeID );
fish.push_back( fishWeight );
}
data.close();
for( unsigned int i = 0; i < lakesID.size(); i++ )
{
switch( lakesID[i] )
{
case 1000: lake = "Chemo"; break;
case 1010: lake = "Eddington"; break;
case 1050: lake = "Hopkins"; break;
case 1100: lake = "Toddy"; break;
case 1250: lake = "Branch"; break;
case 1300: lake = "Phillip"; break;
case 1350: lake = "Green"; break;
}
lakes.push_back( lake );
}
std::cout << std::fixed << std::setprecision(1) << std::left;
for( unsigned int i = 0; i < lakesID.size(); i++ )
std::cout << std::setw(8) << lakesID[i] << std::setw(10)
<< lakes[i] << std::setw(10) << fish[i] << std::endl;
}
std::vector
وذلك حتى لا يقوم محرك الموقع بالتخلص من المحددات التي تبدأ وتنتهي بأقواس (<، >) كما حدث معك (بالإضافة لأسباب أخرى كالجمالية 😄 ).