// file: lecture_21/myprog.cc // // local include files // #include #include #include "myprog.h" // main: myprog // // This is a driver program that does some very simple things. // int main(int argc, const char** argv) { // declare an instance of a the structure "joe" // //struct joe my_joe; //JOE my_joe; // assigning data // //my_joe.x = 27.0; //my_joe.y = 99.0; //fprintf(stdout, "the value of my_joe.x is %f (%f)\n", my_joe.x, my_joe.y); /* fprintf(stdout, "memory analysis:"); fprintf(stdout, "the struct is at %u\n", &my_joe); fprintf(stdout, "x is at %u\n", &my_joe.x); fprintf(stdout, "c is at %u\n", &my_joe.c); fprintf(stdout, "y is at %u\n", &my_joe.y); fprintf(stdout, "the sizeof the struct is at %u\n", sizeof(my_joe)); */ // assign data as a pointer // //JOE* foo = new JOE; //foo->x = 99.0; //foo->y = 27.0; //fprintf(stdout, "the values are (my_joe: %f) (foo: %f)\n", my_joe.x, foo->x); // let's shoe shop // MYSH myshoe; myshoe.brand = (char*)"Nike"; myshoe.size = (float)9.5; //setsize(&myshoe); fprintf(stdout, "brand: %s\n", myshoe.brand); fprintf(stdout, "size: %f\n", myshoe.size); // memory packing // //fprintf(stdout, "my shoe is located at %u\n", &myshoe); //fprintf(stdout, "my shoe.size is located at %u\n", &myshoe.size); //fprintf(stdout, "my shoe.width is located at %u\n", &myshoe.width); // create an array of shoes // MYSH lots_of_shoes[99]; fprintf(stdout, "shoe no. 3: size = %f\n", lots_of_shoes[3].size); // exit gracefully // return(0); } // implement the print function // void setsize(shoes* shoe_a) { shoe_a->size = 27.0; return; }