Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ how can I read this datafile in for use? I want a user to be prompted a r

ID: 3771647 • Letter: I

Question

In c++ how can I read this datafile in for use?

I want a user to be prompted a random capital, pop, size, zone, nickname, or bordering states. Then they can try and guess the state or state symbol.

I used: input.ignore(10000,' ');
   input.ignore(10000,' ');
   input.ignore(10000,' '); to ignore first 3 lines of junk code.

Symbol Capital Nickname 0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999000000 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 Alabama Heart of Dixie Last Frontier Grand Cany Natura.l FL,GA,MS, TN none CA, CO,NM, NV, UT LA,MO,MS,oK,TN, TX AK Juneau 48 Arizona 3229CST Little Rock Sacramento ansas ornia Colorado Connecticut CT Centennial State Constitution State nver KS,NE,NM, OK, UT,WY,AZ EST EST laware Tallahassee 3 22 EST/CST Everglade State NC,SC,TN, FL,AL none MT ,NV,0R, UT, WA,WY IN,KY,MO,WI, IA IL,MI,KY,OH IL,WI,Mo,NE, SD,MN 39 14 PST/MST Gem State Illino Indiana Indianapolis 16 38 EST/CST Hoosier State Kansas Kentucky KS 34 15CST/MST America's Bread Basket MO, NE,OK, CO Frankfor 26 37EST/CST Bluegrass State MO,0H, TN, VA,WV, IL, IN MS, TX,AR Baton Rouge 25 31 CST EST EST EST Louisiana Mary Massachusetts MA Pine Tree State Chesapeake State Baked Bean State PA, VA,WW,DE NH, VT, CT, RI,NY Boston ansin 10 11 EST/CST Great Lakes State Minnesota Mississippi Missouri Montana Nebraska Nevada ND,SD,WI, IA AL,AR, LA, TN IA,NE,KS,oK,AR, TN,KY,IL ND,SD,WY, ID SD,WY, CO,KS,MO, IA CA,AZ,UT. ID,OR North Star State ality Jackson Jefferson City 18 21 CST Helena MS CST Show-Me State 37 16CST/MST Cornhusker State Carson City 35 7PST/MST Silver State Concord Trenton ew Hampshire Granite State New Jersey EST Land of Enchantment OK,TX,UT,co,AZ eW EST North Carolina NC North Dakota ND VA,SC,GA, TN MN, SD,MT PA,WV, KY, IN,MI TX,KS,MO, AR,NM, CO 47 19 CST/MST Peace Garden State Bismarck Oklahoma City 28 20 CST Harrisburg oklahoma ner 27 9 PST/MST Beaver State 6 33 EST EST EST Keystone State Ocean State ennsvIvania PA WV, NY,NJ,MD,0H, DE Rhode Island R Providence arolina ST/MST Mount Rushmore State ND,MN, IA, NE,WY,MT VA,KY,NC, GA,AL,MS,AR,MO OK,AR, LA,NM WY, ID,CO,NM,AZ, NV NH,MA, NY WV, NC, TN, KY,MD 46 17 C 17 36EST/CST Volunteer State Pierre Tennessee ashville exas 2 2 CST/MST Lone Star State MST EST EST Salt Lake City 33 13 Vermont Green Mountain State Old Dominion Evergreen State Richmon Olympia Charleston Madison Cheyenne EST CST PA,MD, VA, KY,0H Wisconsirn MT, SD,NE, co, UT, ID

Explanation / Answer

we use the fact that data is properly indented.

code:

#include <bits/stdc++.h>
using namespace std;

string trim(string s){
   int ind=s.length();
   for(int i=s.length()-1;i>=0;i--){
       if(s[i]!=' '){
           ind=i;
           break;
       }
   }
   return s.substr(0,ind+1);
}


int main(){
ifstream inf;
inf.open("input.txt");
string s;
//remove first three lines by just reading them
getline(inf,s);
getline(inf,s);
getline(inf,s);
//variable to store data of each state
string state;
string sym;
string cap;
int pop;
int size;
string zone;
string nickname;
vector<string> border_states;
while(getline(inf,s)){
   state=trim(s.substr(0,15));
   sym=s.substr(15,2);
   cap=trim(s.substr(23,14));
   stringstream ss;
   ss<<s.substr(38,7);
   ss>>pop>>size;
   zone=trim(s.substr(49,9));
   nickname=trim(s.substr(58,25));
   string bs=trim(s.substr(83));

   if(bs!="none"){
       int i=0;
       while(i<bs.length()){
           border_states.push_back(bs.substr(i,2));
           i=i+3;
       }
   }

   // cout<<state<<" "<<sym<<" "<<cap<<" "<<pop<<" "<<size<<" "<<zone<<" "<<nickname<<" "<<bs<<endl;

}


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote