Sep 4, 2009 at 4:19am UTC
// employee: example with structs
#include <iostream>
#include <string>
using namespace std;
struct AddressType{
unsigned streetNumber;
string streetName;
unsigned zip;
};
struct EmployeeType{
string name;
double rate;
double hours;
AddressType address;
};
void f1( AddressType address );
void f2( AddressType & address );
void f3( const AddressType & address );
void f4( AddressType * address );
void f5( const AddressType * address );
void output( const EmployeeType staff[], unsigned employees );
void output( const EmployeeType & employee );
int main(){
AddressType pierce = { 6201, "Winnetka", 91371 };
f2( pierce );
f3( pierce );
f4( &pierce );
f5( &pierce );
EmployeeType staff[] = {
{"Tom" ,100, 3,{123,"Main" ,99999}},
{"Dick" , 99,100,{456,"Victory",90000}},
{"Harry", 0, 40,{789,"Mason" ,91234}},
};
staff[2].address = staff[0].address;
staff[2].address.zip = staff[1].address.zip;
output( staff, 3 );
} // main
void f1( AddressType address ){
// complicated thing mangling a copy of the struct without
// mangling the original struct
} // f1
void f2( AddressType & address ){
++address.zip;
}
void f3( const AddressType & address ){
cout <<address.streetNumber <<" " <<address.streetName <<" "
<<address.zip <<endl;
}
void f4( AddressType * address ){
++address->zip;
}
void f5( const AddressType * address ){
cout <<address->streetNumber <<" " <<address->streetName <<" "
<<address->zip <<endl;
}
void output( const EmployeeType staff[], unsigned employees ){
for( unsigned i = 0; i < employees; ++i )
output( staff[i] );
}
void output( const EmployeeType & employee ){
cout <<employee.name <<" $" <<employee.rate <<" " <<employee.hours
<<" hours at ";
f3( employee.address );
}
Sep 4, 2009 at 4:57am UTC
Is this another one of these threads where people post answers to test questions so they can copy off them later?
Sep 4, 2009 at 6:18am UTC
im so sorry, it was my only quick escape to post something before the proffesor turned the pc off, since i was already signed in. how can i delete the post, actually no, leave it, ill have questoins by sunday on this, once i move more stuff around.
Sep 4, 2009 at 1:26pm UTC
lol I guess you were right firedraco.