CIS2500 Lab One

Introductions

About Me

About The Lab

Lab Exam

RPI Setup

Expected Coding Conventions


Task One: Hello

Your first task is to write a program which prints “Hello, World!” to the stdout.

fill

The Rules:

  1. You need to have a function named hello which takes a string, wraps it with “Hello, {str}!, and prints it to stdout
  2. You need to separate your source files into the file hierarchy specified below

So something like this…

int main(int argc, char** argv){
    hello("World");
    hello("is it me you're looking for?");
}

Would give you this..

Hello, World!
Hello, is it me you're looking for?!

Setting Up Your File Hierarchy

Project
├── assets
├── bin
├── docs
├── include
├── src
└── README

Compilation

Extra: Include Guards aka Macro Guards

At the top of the header file put:

#ifndef __USERNAME__MODULE_NAME__
#define __USERNAME__MODULE_NAME__

At the bottom of the header file put:

#endif

Solution


Task Two: A Bit of Fun With File I/O

Your second task is to write a program that takes a plaintext file as an argument from the command line and prints it out as upper case.

fill

The Rules:

ie. running ‘bin/uppercase heartOfDarkness.txt’, containing…

One ship is very much like another, and the sea is always the same. In the immutability of their surroundings the foreign shores, the foreign faces, the changing immensity of life, glide past, veiled not by a sense of mystery but by a slightly disdainful ignorance; for there is nothing mysterious to a seaman unless it be the sea itself, which is the mistress of his existence and as inscrutable as Destiny.

Outputs This:

ONE SHIP IS VERY MUCH LIKE ANOTHER, AND THE SEA IS ALWAYS THE SAME. IN THE IMMUTABILITY OF THEIR SURROUNDINGS THE FOREIGN SHORES, THE FOREIGN FACES, THE CHANGING IMMENSITY OF LIFE, GLIDE PAST, VEILED NOT BY A SENSE OF MYSTERY BUT BY A SLIGHTLY DISDAINFUL IGNORANCE; FOR THERE IS NOTHING MYSTERIOUS TO A SEAMAN UNLESS IT BE THE SEA ITSELF, WHICH IS THE MISTRESS OF HIS EXISTENCE AND AS INSCRUTABLE AS DESTINY.

Using fgets

Using fopen

What’s in a char?

fill

Pseudocode

main(passedTxtFile) {

  /**
   * Open text file
   */
  textFile = openFile(passedTxtFile, read mode)

  /**
   * Print text before transformation
   */
  print("Text Before:")
  print(text)

  /**
   * Transform text, print results 
   */
  uppercase(text);
  print("Text After:")
  print(text)
}


/**
 * uppercase
 *   transformes passed char array to uppercase and prints the result to stdout
 * Arguments
 *   text
 *     the char array to transform 
 *  Return Values
 *    None
 */
uppercase(text) {

  index = 0

  do while text at index exists:

    currentChar = text at index

    if currentChar >= 'a' and currentChar <= 'z':
        text at index = text at index - 32

    increment index
}

Solution