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
5 Respostas
+ 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;
}
+ 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.
+ 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.
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
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?