Table of Contents

David Woodcock's fall2013 Opus

My Opus

Introduction

In this space you can provide a description of yourself, your pursuits, your interests. To fill out this section, click the edit button off to the right, delete this placement text, and type your original content.

C/C++ Programming Journal

“*=class days, -=Lab days”

08/28, 2013

08/29, 2013

  1. We discussed the higher levels of C.
  2. Went over Gnu Linux-GCC
  3. Discussed our first C code “HelloWorld.C”
  4. Gained access to class repository through bitbucket.org
  5. Created the code and tested it out then added more details to the program to get a return value such as a number.
#include <stdio.h>
int main(int a, char**b) {
       printf("hello, world\n");
return a;
}

08/30, 2013

  • Bash-Shell environment
  • Class Repo - src/cprog
  • $mv *.c ~/src “Moves all programs ending in .c to the repository”
  • $mkdir ~/src/cprog “makes directory cprog”
  • $mv *.c ~/src/cprog “moves all .c programs in src to cprog”
  • hg status
  • hg add
  • hg commit -m “adding code”\
  • hg push
  • hg update
  • hg log
  • cd src/cprog/

09,04, 2013

  • Data types
  • Char(character) \
  • short integer \
  • long integer Integers
  • integer /
  • long long integer /
  • Float \
  • Double Floating points
  • long double/

Char.c code written to show how char command works.

09,05, 2013

Went over 9899 manual in repository and discussed homework 1.Unix/Microsoft command reference 2. Mingw bin folder file description 3.GCC options for- Preprocesses/ compile/ assemble/ Link/ Individual 4. 9899 Section 5 5. 9899 Section 6 6. 9899 Section 7

09,05, 2013

Printf() = Function

Stdio.h= printf() / scanf()

Scanf() = function

09,13, 2013

./program – to run program(just a reminded) gcc -o program program.c (to compile program, another reminder)

with if must have exactly 1 “if” can have exactly 1 “else” 0 or more “else if”

if(arrc > 7) = if statement NOT!!! if loop

Created this program today.

#include <stdio.h> #include <stdlib.h> int main( ) {

   char *name,fi;
   name=NULL;
   fi=0;
   unsigned char age=0;
   printf("Please enter your name");
   name=(char*)malloc(sizeof(char)*20);
   scanf("%s", name);
   printf("%s, what is your age?",name);
   scanf("%hhu",&age);
   fi=*(name+0);
   printf("%s, your initial is %c (%hhu) and you are %hhu years old\n",name    ,fi,fi,age);
   return(0);

}

Week 4

If Statement Information
  1. “> greater than”
  2. “< less then”
  3. “>= greater than or equal to”
  4. “⇐ less than or equal to”
  5. “== Check equality ( is this equal to)”
  6. “!= not equals”
  7. “= sets equality”
  8. “if statements do not need a semicolon”
  9. “you can have if statements”
  10. “else statements”
  11. “with else if”
  12. “have have exactly 1 if”
  13. “can have only ”
  14. “exactly 1 else”
  15. “0 or more else if”
  16. “if(0) - true”
  17. “if(1) - false”

FILE * out; char outfile[] = ”/home/dwoodco2/public_html/image1.png”;

The first line creates a file and the second line contains the location of where the file is to be stored.

We were asked to create a checkered board and the CCC logo with a snowman and a house. http://lab46.corning-cc.edu/~dwoodco2/ccclogo.png http://lab46.corning-cc.edu/~dwoodco2/triangle1.png http://lab46.corning-cc.edu/~dwoodco2/blocks.png

After going through these programs for a very long time I have a better understanding of the placement of the blocks and the pixels.

Week 5

Arrays

An array is a homogeneous composite variable modifier type. I learned about Arrays last semester in Oppenheims class. They are basically a data type that can hold multiple variables. Arrays start at 0 when counting so if you are attempting to access array variable 2 you would enter arrayname[1]

char **b

char *b[]

char b[][]

Address 20 data 22 Address 21 data 23 Address 22 data 24 Address 23 data 29 Address 24 data a Address 25 data b Address 26 data c Address 27 data d Address 28 data e Address 29 data f Address 30 data g Address 31 data h Address 32 data i Address 33 data j

Week 6

Functions

Functions are sub-programs that allows for repackaging of code.

Functions require a prototype, function call, and the function definition.

We covered logic gates this week also, I learned about these in detail last semester in Computer essentials and problem solving.

We created this program in class this week to convert data into ASCII symbols.

# include<stdio.h>

int main() {

      char x =0;
      char y =0;
      printf("Enter a number (0-255); ");
      scanf("%hhu", &x);
      getchar();//function that grabs single input char of 1 byte from input stream
      //So it grabs the enter character and get's rid of it,   y=getchar() is equivalent
      printf("Enter a character: ");
      scanf("%c", &y);//Allows changes to be saved
      printf("x is numerically %hhu and characterally %c\n", x,x);//%hhu is int specifier, %c is char specifier
      printf("y is numerically %hhu and characterally %c\n", y,y);
      printf("x+48 characterally is %c\n",(x+48));//48 begins askii 0, so number entered will be printed
      printf("y+32 characterally is %c\n",(y+32));//32 added and subtracted will switch character to uppercase and lowercase
      return(0);

}

Week 7

This Week we took the knowledge assessment, it wasn't to difficult but I still worry when it comes to tests.

Week 8

This week we switched from programming in C code to C++ code, 99% of all code that works in C works in C++ one of the major differences between the two is how you compile.

C code you compile with GCC when it comes to C++ you compile with G++ code code.c

We rewrote the HelloWorld program in C++ it is basically the exact same program.

When using your own files you want to use ””, such as “header” When using standard libraries, use <>, such as <cstdio>

#include <iostream> using namespace std;

int main () {

cout << "Hello World!\n";
return 0;

}

Afterwards we wrote a meme program that was pretty fun.

#include<cstdio> #include<cstdlib> #include<cstring>

class animal { class= int public: void listen(); accessor methods

      void tell(char *);      // ^^^^^^^
      // Constructors
      animal();
       animal(char *);        // ^^^

private:

      char sound[80];

};

animal::animal() {

}

animal::animal(char *sound) {

      tell(sound);

}

void animal::listen() {

      printf("%s\n", sound);

}

void animal::tell(char *sound) {

      int i = 0;
      while (sound[i] != '\0')
      {
              this->sound[i] = sound[i];
              i++;
      }

}

int main() {

      animal cat;
      animal *dog = new animal("woof");

}

void animal::listen() {

      printf("%s\n", sound);

}

void animal::tell(char *sound) {

      int i = 0;
      while (sound[i] != '\0')
      {
              this->sound[i] = sound[i];
              i++;
      }

}

int main() {

      animal cat;
      animal *dog = new animal("woof");
      cat.tell("meow");
      cat.listen();
      dog->listen();
      return (0);

}

Week 9

This week we covered more information on C++ #ifndef and #define preprocessor statements tell the program I already have a copy so disregard.

We created more programs this week explaining the public and private features of C++, we also were shown in more detail how classes work.

class shapes {

      public:
      int side, base, height;
      int area;
      int perimeter;

shapes();

      int sarea();
      int sperimeter();
      int rarea();
      int rperimeter();
      int tarea();
      int tperimeter();

};

int main() {

      shapes square;
      shapes rectangle;
      shapes triangle;

printf(“The area of the square is %d\n”“, square.sarea());

      printf("The perimeter of the square is %d\n"", square.sperimeter());

printf(“The area of the rectangle is %d\n””, rectangle.rarea());

      printf("The perimeter of the rectangle is %d\n", rectangle.rperimeter());

printf(“The area of the equilateral triangle is %d\n”, triangle.tarea());

      printf("The perimeter of the equilateral triangle is %d\n", triangle.tperimeter());

return(0); }

Week 10

We broke down the basics of a computer in class this week. Basically they take input process it then give you output. The process step in a computer contains Fetch → Decode → Execute → Get Next Instruction Information is sent across the pieces of the computer at the speed of light but we are still attempting to get faster processing speeds.

Week 11 Debugger

A debugger allows programmers to interrupt execution of code and examine it in detail where the program stopped working. the command for debugging a program/

gcc -Wall -o code code.c -g gdb ./code

Now inside of the debugger there are multiple commands to assist you.

list - shows current location in code break - to set a breakpoints step - will take you to the next instruction next - will take you to the next line of code, will execute but skip over functions run - will run the program to the end or take you to the next breakpoints, if there is one print - print anything to screen, such as values in variables or addresses display - can select certain items, such as variables, and have them displayed each time the loop is executed set - assign a value to a variable exit - to leave

Week 12

We learned about Inheritance this week, we learned about how you can write multiple codes and compile them all together then run them together.

We created the Bignum.h program this week in multiple codes.

One of the biggest advantages of Inheritance is you can reuse a minor code from the list in other programs if you wanted.

Week 13

We learned about Polymorphism this week Polymorphism allows us to have two functions with the same name and parameters

EOCE was handed out.

Week 14

Thanksgiving Break

Week 15

We worked more on our EOCE This week

Bignum Inheritance and Signed/Unsigned

Since I did not have these complete I was up all night long after our meeting on Wednesday and was able to finish them finally. I had to use a couple of C programming websites to help me with the Bignum and Inheritance programs. I was finally able to finish them around 11pm though… They are listed under Bignum/Inheritance push in the repository.

Bignum

#include “BIGNUM.h” #include <iostream> #include <iomanip> #include <cstdlib> #include <cstdio>

using namespace std;

int main() {

  int choice;
  printf( "How would you like to increment or decrement a number?\n");
  printf( "\n0 - Subtraction");
  printf( "\n1 - Addition");
  printf( "\n2 - Multiplication");
  cin >> choice;
  BigNum num;
  num.setBase(10);
  int i,x;
  int loop1,loop2;
  int loop3,loop4;
  int loop5,loop6;
  int loop7,loop8;
  int sub1,sub2;
  int z,w;
          printf ("\nMultiplication\n");
          printf ("\nFirst Number: ");
          cin >> loop5;
          printf ("Second Number: ");
          cin >> loop6;
          {
          for(i=0;i<loop5;i++)
              {
              for(x=0;x<loop6;x++)
                  {
                  num.increment();
                  }
              }
          }
              num.print();
      }
      else if (choice == 1)
          {
          printf ("\nAddition\n");
          printf ("\nFirst Number: ");

cin » loop1;

          printf ("Second Number: ");
          cin >> loop2;
          {
          for(i=0;i<loop1;i++)
              {
              num.increment();
              }
          for(i=0;i<loop2;i++)
              {
              num.increment();
              }
          }
              num.print();
      }
      else
          {
          printf ("\nSubtraction\n");
          printf ("\nFirst Number: ");
          cin >> sub1;
          printf ("Second Number: ");
          cin >> sub2;
          {

if (sub1 > sub2)

                  {
                  loop3=sub1;
                  loop4=sub2;
                      {
                      for(i=0;i<loop3;i++)
                          {
                          num.increment();
                          }
                      for(i=0;i<loop4;i++)
                          {
                          num.decrement();
                          }
                      }
                          num.print();
              }
              else
              {
                  loop3=sub2;
                  loop4=sub1;
                  {
                  for(i=0;i<loop3;i++)
                      {

}

              else
              {
                  loop3=sub2;
                  loop4=sub1;
                  {
                  for(i=0;i<loop3;i++)
                      {
                      num.increment();
                      }
                  for(i=0;i<loop4;i++)
                      {
                      num.decrement();
                      }
                  }
                      num.print();
              }
          }
      }
  }
  return(0);

}

Inheritance

#include <cstdio> #include “tape.h” #include <iostream>

using namespace std;

int main() {

  tape t;
  char ans;
  string l;
  int val;
  int i;
  cout << "This's the tape, would you like a label? (y/n)" << endl;
  cin >> ans;
  if(ans==121)
  {
      cout << "What would you like a label (no spaces)?" << endl;
      cin >> l;
      t.setlabel(l);
      cout << "This tape is now labeled " << t.getlabel() << endl;
  }
  cout << "The current position is " << t.getpos() << " and it contains " << t.read() <<  endl;
  while(ans!=55)
  {
      cout << "0 - forward" << endl;
      cout << "1 - backward" << endl;
      cout << "2 - rewind" << endl;
      cout << "3 - read" << endl;
      cout << "4 - write" << endl;
      cout << "5 - forward multiple positions" << endl;
      cout << "6 - backward multiple positions" << endl;
      cout << "7 - quit" << endl;
      cin >> ans;
      switch(ans)
      {
          case 48:
              t.forward();
              cout << "the position is " << t.getpos() << endl;
              break;
          case 49:

cout « “the position is ” « t.getpos() « endl;

              break;
          case 50:
              t.rewind();
              cout << "the position is " << t.getpos() << endl;
              break;
          case 51:
              cout << "the value is " << t.read() << endl;
              break;
          case 52:
              cout << "please enter the value" << endl;
              cin >> val;
              t.write(val);
              break;
          case 53:
              cout << "how many spaces?" << endl;
              cin >> val;
              for(i=0; i<val; i++)
              {
                  t.forward();
              }
                              cout << "the position is " << t.getpos() << endl;
              break;
          case 54:
                              cout << "how many spaces?" << endl;
                              cin >> val;
                              for(i=0; i<val; i++)
                              {
                                      t.backward();
                              }
                              cout << "the position is " << t.getpos() << endl;
              break;
          case 55:
              return(0);
      }
  }

}

Signed/Unsigned

assessment.c bignum.h~ ccodeinfo classes classwork.save.1 helloworld.cc latch main.ccyyy rec.cc sign.cc~ triangle2.c lab46:~/src/cprog$ nano signedchar.c

GNU nano 2.2.4                                                 File: signedchar.c

#include <stdio.h> int main( ) {

   signed char sc=0;
   signed short int ss=0;
   signed int si=0;
   signed long int sl=0;
   signed long long int sm=0;
  printf("A signed char is %d byte\n",sizeof(sc));
   printf("Lower bounds is %hhd\n", ((unsigned char)(sc-1)/2)+1);
   printf("Upper bounds is %hhd\n\n", ((unsigned char)(sc-1)/2));
   printf("A signed short is %d bytes\n",sizeof(ss));
   printf("Lower bounds is %hd\n", ((unsigned short)(ss-1)/2)+1);
   printf("Upper bounds is %hd\n\n", ((unsigned short)(ss-1)/2));
   printf("A signed int is %d bytes\n",sizeof(si));
   printf("Lower bounds is %d\n", ((unsigned int)(si-1)/2)+1);
   printf("Upper bounds is %d\n\n", ((unsigned int)(si-1)/2));
   printf("A signed long is %d bytes\n",sizeof(sl));
   printf("Lower bounds is %ld\n", ((unsigned long)(sl-1)/2)+1);
   printf("Upper bounds is %ld\n\n", ((unsigned long)(sl-1)/2));
   printf("A signed long long is %d bytes\n",sizeof(sm));
  printf("Lower bounds is %lld\n", ((unsigned long long)(sm-1)/2)+1);
   printf("Upper bounds is %lld\n\n", ((unsigned long long)(sm-1)/2));

return(0);

}

#include <stdio.h> int main( ) {

   unsigned char uc=0;
   unsigned short int us=0;
   unsigned int ui=0;
   unsigned long int ul=0;
   unsigned long long int um=0;
   printf("A unsigned char is %d byte\n",sizeof(uc));
   printf("Lower bounds is %hhu\n", (uc));
   printf("Upper bounds is %hhu\n\n", (uc-1));
   printf("A unsigned short is %d bytes\n",sizeof(us));
   printf("Lower bounds is %hu\n", (us));
   printf("Upper bounds is %hu\n\n", (us-1));
   printf("A unsigned int is %d bytes\n",sizeof(ui));
   printf("Lower bounds is %u\n", (ui));
   printf("Upper bounds is %u\n\n", (ui-1));
   printf("A unsigned long is %d bytes\n",sizeof(ul));
   printf("Lower bounds is %lu\n", (ul));
   printf("Upper bounds is %lu\n\n", (ul-1));
   printf("A unsigned long long is %d bytes\n",sizeof(um));
   printf("Lower bounds is %llu\n", (um));
   printf("Upper bounds is %llu\n\n", (um-1));
   return(0);

}

Simple Addition Calc

#include<stdio.h>

int main() {

      char operator;
      float num1, num2;
      printf("+ : ");
      scanf("%c",&operator);
      printf("enter two operands: ");
      scanf("%f%f",&num1,&num2);
      switch(operator)

{

       case '+':
      printf("num1+num2=%.2f",num1+num2);
      break;

} return(0); }

Portfolio

cprog