Image

Imagetransmogrify wrote in Imagecpp

struct program

i have to do this project using structs that prints out 10 records in table form, using headings. the records must be sorted alphabetically by last name. it must also search for all phone numbers with area code 973 and print them out. i was thinking of having it sort things alphabetically and searching for records with that area code when a specific command is put in. i'm a beginner programmer and i'm not really sure how to go about that...if else statements perhaps? then how does one set things up to allow a command to perform that specific action? here's what i have so far...i'm having problems cuz i get errors like this: cannot convert from 'char [2]' to 'char' pointing to the birthday part of the array. any help would be greatly appreciated.


#include <iostream.h>
#include <iomanip.h>
struct dob
{
char month;
char day;
char year;
};
struct phone
{
char * area;
char * exchange;
char * extension;
};
struct person
{
char * last;
char middle;
char *first;
phone number;
dob birthday;
};
ostream & operator << (ostream & output, person); // prototype to overload
void main()
{
person profile [10];

profile[0].last = "Smith";
profile[0].middle = 'Q';
profile[0].first = "John";
profile[0].number.area = "732";
profile[0].number.exchange = "780";
profile[0].number.extension = "4428";
profile[0].birthday.month = "6";
profile[0].birthday.day = "3";
profile[0].birthday.year = "1983";

cout << profile[0] << endl;


}

ostream & operator << (ostream & output, person x)

{
output << setw(10) << x.first;
output << setw(2) << x.middle;
output << setw(10) << x.last;
output << setw(3) << x.birthday.month << "/";
output << setw(3) << x.birthday.day << "/";
output << setw(5) << x.birthday.year;
output << setw(4) << x.number.area << "-";
output << setw(4) << x.number.exchange << "-";
output << setw(5) << x.number.extension;
output << endl;

return output;
}


cross posted in: Imagecoders_haven Imagepcgeeks