LAB 01: Standard Deviation Lab

Objective
Learning C programming, C array processing. Topics include
  1. Compiling C programs
  2. keyboard I/O:printf() and scanf() (C) cout/cin (C++),
  3. file creation and file i/o: FILE *infile, FILE *outfile, and fopen() (C)
    fscanf() and fprintf() (C)
    ifstream infile() and ofstream outfile() (C++),
  4. Constants: #define MAXVALS 100 (C)
    const int MAXVALS=100; (C++)
  5. static array: int myarray[MAXVALS]: C and C++
  6. dynamic arrays: C:
    int *myarray;
    scanf("%d", &numVals); myarray=(int *)malloc(sizeof(int)*numVals);
    "malloc" stands for "memory allocation"
  7. deletion of dynamic arrays
    delete myarray (C++)
    free(myarray) (C)
  8. dynamic arrays: C++:
    int *myarray;
    cin >> numVals; myarray=new int[numVals];
  9. "Random" numbers in C and C++

Part 1

  1. Download these programs to write random numbers to a file: randomNumFile.c, (for C++ see randomNumFile.cpp)
    right click on the C file, choose "Download Link", save as .c (for c++ use .cpp)
  2. Compile each program
    C: gcc -o randomNumFile randomNumFile.c
    (C++: g++ -o randomNumFileCPP randomNumFile.cpp)
  3. To create a generic executable name, use:
    gcc randomNumfile.c
    This makes an executable named a.out
  4. Run each program to create files of 50 or more random numbers
    ./randomNumFile (or ./a.out)
  5. Look at the contents of each of the number files to verify the programs worked.

Part 2 - Static and Dynamic Arrays in C