Wednesday, December 31, 2014

C PROGRAMMING

C PROGRAMMING

December 2013. The Fall 2013 semester has ended and I received my grades in all four classes. All A's.

Overall, I would say, that I was the top student in my "Introduction to Computer Security" class, because I had the highest grades in both midterm and final exams, and I did not ignore the professor's advice to contribute at least 3 discussions per week in the online class. Some of the students used to follow the professor's advice in the beginning of the class, but as the weeks wore on, most gradually posted very few while some, none at all.

For the next semester, Spring 2014, I was ready to tackle Advanced C++ and earn some money tutoring programming to beginning programming and web development students, including C, which is C++ without classes.

Programs written in C do not have classes. C is rather a procedural language, but is the first to optimize modular programming by using the concept of functions.

C can also represent a class type definition but the fields would not be private and it would not encapsulate its methods. Here is an example of a representation of a class the best that C can do.

This is the definition of the C header file cclass.h that represents a C class.

struct structclass {
   char *str; } astruct;
void setStr(char *c) {
   astruct.str = c;
}
char* getStr(void) {
   return astruct.str;
}

This is the user program that uses the C header file cclass.h that defines the closest to a class a C program can define. Note that it has a set and get methods like classes have.

#include <stdio.h>
#include "cclass.h"

int main(void) {
   setStr("Happy New Year\'s Eve!");
   puts(getStr());
   return (0);
}

Happy New Year!

John Sindayen

No comments:

Post a Comment