Monday 4 April 2011

Exam Cheatsheet

So my exam for Computer Programming II is this Thursday, and having looked at the course outline my prof made for us, it clearly states that we are allowed to bring in "...one page during the exam time to assist you in memorizing some syntactic matters." So basically this means that we can bring in a page full of examples of everything we learned this semester. Hopefully nobody reminds her about this and makes her change her mind... She's pretty cool though, so I'm sure if we all show up with them, she'll be cool with it. 


Anyway, I decided to share mine with everyone here! Feel free to use it as a reference, or even as study help for your own class!


Download Link 1


Calling by reference:

int x=0;

int *ptr;
ptr=&x;           //ptr now points to x

void function(int *y)
{
       *y++;   //y points to x
}

int arr[5];
arr[3]; //same as *(arr+3)

pointer to function:
double (*fp)(double,double);

fp=pow; //fp now acts like pow

Useful String Functions:
int atoi( const char *nPtr )
char *gets( char *s );
char *strcpy( char *s1, const char *s2 )
char *strcat( char *s1, const char *s2 )
char *strstr( const char *s1, const char *s2 );

Structs:
typedef struct dummyname
{
       int x;
       //elements
}StructName;

StructName identifier;

indentifier.element=value;

Dynamic Memory:
ptr = (int*)malloc(5*sizeof(int));

Linked Lists:
typedef struct node
{
       char data;
       struct node *next;
}Node;

Node *p;
p=(Node*)malloc(sizeof(Node));
p->data=’a’;
p->next=head;
head=p;

Enum:
typedef enum dummyname
{
       sun,mon,tues...
}Weekday;
(sun=0,mon=1,....)

force values:
enum{sun=5,mon=8,...};


Union:
As large as its largest element.
Holds one at a time.
Declare like a struct.

Preprocessor:
#define SQUARE(x) ((x)*(x))
#undef
#if, #ifdef, #else, #endif

#define TOKCAT(x,y) x ## y

Variable Length Args:
int funct(int n,...)
{
       va_list args;
       va_start(args,n);//n is first param
loop()      variable=va_arg(args,type);
       va_end(args);
}

Command Line Args:
int main(int argc,char *argv[])

iostream:
using namespace std;
cout<<”stuff”;
cin>>variables;

Default Args:
int func(int x=1);

Templates:
template <class T>
T square(T value)
{
       return value*value;
}

int x=square(5);
float y=square(5);

Classes:
Class ClassName
{
public:
void func();
       const int x;
private:
      
       void inlineFunct(){return 0;};
       //private ones
};

void ClassName::funct()
{}

//constuctor
ClassName::ClassName()
{/*default values*/}

//destructor
ClassName::~ClassName(){}
Data Initializer:
ClassName::ClassName()
       :x(0)
{/*default values*/}
Composition:
Class1::Class1(Class2 &identifier)
{}

Friend Functions:
class ClassName
{
       friend void func();
public:
private:
}

void func(ClassName name)
{
       //access private stuff
}

new and delete:
int ptr = new int(3.141592654);
int arr = new int[10];
delete []arr;

Static Class Members:
ClassName::var
InstanceName.var

ClassName::ClassName()
{
       var++;
}

Operator Overloading:
class ClassName
{
friend ostream& operator<<( ostream&, const ClassName&);

ClassName& ClassName::operator=(const ClassName x)
{
       var1=x.var1;
return *this;
}

ostream& operator<<(ostream &o, const ClassName x)
{
       o<<x.var1<<etc;
return o;
}

11 comments:

  1. That's really cool of her to let you do that.

    Good luck on the exam!

    ReplyDelete
  2. Man, I gotta teach myself how to make basic apps in Access within the next week and a half. I better get to it.


    ~H. Coct

    ReplyDelete
  3. this actually helped me with exam :X so nice thank you

    ReplyDelete
  4. looks okay to me, good luck on the exam.

    ReplyDelete
  5. Good luck with your test,im sure you'll do well.

    ReplyDelete
  6. I remember we got this for my programming course, must be a universal thing :D

    ReplyDelete
  7. thanks for refreshing knowledge :) good luck

    ReplyDelete
  8. My Digital Design teacher did the same, it made the test a bit too easy :p

    ReplyDelete