Monday 15 July 2013

xcode - Stuck on C++ code using Structure -



xcode - Stuck on C++ code using Structure -

currently stuck , not sure go here...

i'm supposed write programme declares struct store info player. declare array of 10 components store info 10 baseball game players.

the programme reads file , stores info 10 baseball game players, including player’s team, name of player, number of homeruns, batting average, , runs batted in.

the programme prints out menu (in loop, can done 1 time again , again) giving user selection to:

print out users , statistics print out statistics specific player print out info specific team update info particular player (change 1 of statistics)

before programme terminates, give user alternative store info in output file.

if has tips or advice grateful... i'm new coding in c++ , stuck here... give thanks in advance...

#include <iostream> #include <fstream> using namespace std; struct baseballid { string teamname, playerfirstname, playerlastname; int homeruns, rbi; double batting_average; }; int main() { baseballid listofplayers[10]; ifstream infile; infile.open("/users/aleckleyer/desktop/computer science term 2/baseballstats.txt"); if (!infile) { cout << "error opening file!"; homecoming 0; } (int j = 0; j < 10; j++) { infile >> listofplayers[j].teamname >> listofplayers[j].playerfirstname >> listofplayers[j].playerlastname >>listofplayers[j].homeruns >> listofplayers[j].rbi >> listofplayers[j].batting_average; } cout << "please type next letter: "; cout << "\n(a) users , stats"; cout << "\n(b) specific player"; cout << "\n(c) print out specific team"; cout << "\n(d) update stats player"; char input = 0; cin >> input; if (input == 'a' || input == 'a') { printinfoall(*listofplayers[]); } if (input == 'b' || input == 'b') { } if (input == 'c' || input == 'c') { } if (input == 'd' || input == 'd') { } } void printinfoall(listofplayers1[]) { (int = 0; < 10; i++) { cout << &listofplayers[i]; } }

one thing did right making function of printinfoall (even if buggy). note not compile , there might more errors.

#include <iostream> #include <fstream> using namespace std; struct baseballid { string teamname, playerfirstname, playerlastname; int homeruns, rbi; double batting_average; }; void printinfo(const baseballid& id) { cout << id.teamname << " " << id.playerfirstname // , on!!!! << "\n"; // , newline. } void printinfoall(const baseballid listofplayers1[]) // need type , paramter { (int = 0; < 10; i++) { cout << printinfo(listofplayers[i]); // } } void printmenu() { // factor out components in easy reusable parts. cout << "please type next letter: "; cout << "\n(a) users , stats"; cout << "\n(b) specific player"; cout << "\n(c) print out specific team"; cout << "\n(d) update stats player"; } int main() { baseballid listofplayers[10]; // consider using std::vector instead // here ifstream infile; infile.open("/users/aleckleyer/desktop/computer science term 2/baseballstats.txt"); if (!infile.isopen()) // think isopen needed. { cout << "error opening file!"; homecoming 0; } (int j = 0; j < 10; j++) { infile >> listofplayers[j].teamname >> listofplayers[j].playerfirstname >> listofplayers[j].playerlastname >>listofplayers[j].homeruns >> listofplayers[j].rbi >> listofplayers[j].batting_average; // hmm trust indata don't check errors here. } // here should function, need restructure bit more printmenu(); char input = 0; cin >> input; switch(input) { case 'a': case 'a': printinfoall(*listofplayers[]); break; case 'b': // , on // code 'b' , 'b' break; .... default: printmenu(); break; } // @ point find out should have set in loop. homecoming exit_success; }

the reason adding const parameters user of functions can see promises not alter values.

c++ xcode

No comments:

Post a Comment