0

need help making a roster

need a list of 5 athletes. roster# name. age ex.1. ex1. ex1 ex2. ex2. ex2 ex3. ex3. ex3 ex4. e4. ex4 ex5. ex5. ex5

8th Sep 2016, 11:19 AM
mason kitzmiller
mason kitzmiller - avatar
5 Antworten
+ 1
#include <iostream> #include <string> using namespace std; struct Athlete { int id; string name; int age; }; int main() { int i, len; len = 3; Athlete *roster = new Athlete[len]; roster[0].id = 1; roster[0].name = "John"; roster[0].age = 24; roster[1].id = 2; roster[1].name = "Mike"; roster[1].age = 22; roster[2].id = 3; roster[2].name = "Dave"; roster[2].age = 25; for (i = 0; i < len; i++) { cout << "#" << roster[i].id << " " << roster[i].name << " " << roster[i].age << endl; } delete roster; return 0; }
8th Sep 2016, 11:50 AM
Zen
Zen - avatar
+ 1
I define a struct named Athlete that has 3 attributes (int id, string name, int age). Then in the main code, I create a dynamic array of 3 Athletes named roster, and initialize their attributes. Then I print their attributes, Athlete by Athlete.
8th Sep 2016, 1:03 PM
Zen
Zen - avatar
+ 1
This site provides lessons to learn the basics. http://www.sololearn.com/Course/CPlusPlus/ App: https://play.google.com/store/apps/details?id=com.sololearn.cplusplus As for actual coding, you can use the Code Playground to check out programs made by others and code your own. It's pretty convenient. You can also find exercices on the web.
8th Sep 2016, 2:23 PM
Zen
Zen - avatar
0
is there anyway you could break it down and sort of explain it? I'm trying to learn and it has been challenging. also thank you for the answer
8th Sep 2016, 12:51 PM
mason kitzmiller
mason kitzmiller - avatar
0
Thank you very much. I'm currently in computer science 1. everyone I talk to tells that you learn by doing but that is very vague. any suggestions?
8th Sep 2016, 1:08 PM
mason kitzmiller
mason kitzmiller - avatar