home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ittybittycomputers.com
/
www.ittybittycomputers.com.tar
/
www.ittybittycomputers.com
/
Courses
/
Prior
/
ADS
/
Sep16.cc
< prev
next >
Wrap
C/C++ Source or Header
|
2006-10-18
|
2KB
|
60 lines
/* Sept.16 Example Solution (C++) */ /*points*/
#include <iostream>
using namespace std;
struct arap { int i35[35]; };
/*d*/ void oddneg(int & i); /*1*/
void oddneg(int & i) {if (i%2 !=0) i = -i;} /*2*/
int main () {
int i;
/*a*/ arap loc; /*1*/
/*b*/ arap * dyn = new arap; /*1*/
/*a*/ for (i=35; i>0; i--) loc.i35[35-i] = i*i; /*2*/
/*c*/ *dyn = loc; /*2*/
/*e*/ for (i=0; i<35; i+=3) oddneg(loc.i35[i]); /*2*/
/*f*/ for (i=0; i<35; i+=5) oddneg(dyn->i35[i]); /*2*/
/*g*/ for (i=0; i<35; i++) /*1*/
cout << i << " " << loc.i35[i] << " " << dyn->i35[i];
/*h*/ delete dyn; /*1*/
} /* end main */
--------------------------------------------------------------
/* Sept.16 Example Solution (pure C) */
#include <stdio.h>
struct araps { int i35[35]; };
typedef struct araps arap;
/*d*/ void oddneg(int * i); /*1*/
void oddneg(int * i) {if (*i%2) *i = -(*i);} /*2*/
int main () {
int i;
/*a*/ arap loc; /*1*/
/*b*/ arap * dyn = (arap *) malloc(sizeof(arap)); /*1*/
/*a*/ for (i=35; i>0; i--) loc.i35[35-i] = i*i; /*2*/
/*c*/ *dyn = loc; /*2*/
/*e*/ for (i=0; i<35; i+=3) oddneg(&loc.i35[i]); /*2*/
/*f*/ for (i=0; i<35; i+=5) oddneg(&dyn->i35[i]); /*2*/
/*g*/ for (i=0; i<35; i++) /*1*/
printf("%d %d %d \n", i, loc.i35[i], dyn->i35[i]);
/*h*/ free(dyn); /*1*/
} /* end main */