Hi all, I'm having a little bit of trouble with my code about structures. I posted the question, and I have a little bit of code. Any suggestion will help! Thanks!
_____________________________________________________________________________
Design a structure Student containing the following members:
1) Name;
2) Date of birth (it should be in turn a structure containing three members Year, Month, Day);
3) Phone number;
4) Major field of study.
Find appropriate data types for each field.
Test the Student structure in a main function. Creating an object of the Student type, assigning some meaningful values to all its fields and then printing them out.
Then in the same main function define an array of structures belonging to the Student structure and containing 3 elements. Assign all values to the elements of this array using initialization at the time of its definition. Display the content of the array created (use a loop).
_____________________________________________________________________________
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <cstdlib>
using namespace std;
struct student
{
char first_name[100];
char last_name[100];
double dob;
double number;
char major[100];
void print_structure()
{
cout << "First name: " << endl << first_name;
cout << "Last name: " << endl << last_name;
cout << "Date of Birth: " << endl << dob;
cout << "Phone number: " << endl << number;
cout << "Major: " << endl << major;
}
};
const int array_size = 5;
int main()
{
student stdnt[array_size];
for (int i = 0; i < 1; i++)
{
cout << "Enter first name" << endl;
cin >> stdnt[i].first_name;
cout << "Enter last name" << endl;
cin >> stdnt[i].last_name;
cout << "Enter date of birth (YYYYMMDD)" << endl;
cin >> stdnt[i].dob;
cout << "Enter phone number" << endl;
cin >> stdnt[i].number;
cout << "Enter major" << endl;
for (int i = 0; i < 1; i++)
{
stdnt[i].print_structure();
}
}
cout << "Student Information" << stdnt[array_size] <<endl;
return 0;
};
|