C Cheat .pdf

File information

Original filename: C_Cheat.pdf
Title: Microsoft Word - C_Cheat.doc
Author: Margaret

This PDF 1.4 document has been generated by PScript5.dll Version 5.2.2 / Acrobat Distiller 6.0 (Windows), and has been sent on pdf-archive.com on 16/06/2016 at 07:21, from IP address 99.64.x.x. The current document download page has been viewed 515 times.
File size: 13 KB (2 pages).
Privacy: public file

Download original PDF file

C_Cheat.pdf (PDF, 13 KB)

Share on social networks

Link to this file download page

Document preview

C/C++ Cheat Sheet
For your reference; this sheet will also be included in exams
CISC 124, fall 2004
Sample C++ Program:
#include <stdio.h>
#include <string.h>
class Employee {
char name[51];
double wage; // hourly wage
double payOwed;
Employee(char n[], double w) {
strcpy(name, n);
payOwed = 0;
} // end constructor
virtual void pay(double hours) {
payOwed += wage * hours;
} // end pay
double amountToPay() {
return payOwed;
} // end amountToPay
void setWage(double wage) {
this->wage = wage;
void zero() {
payOwed = 0;
} // end zero
// prints employee
virtual void print() {
printf("name = %s, ", name);
printf("wage = $%.2f, ", wage);
printf("payOwed = $%.2f",
} // end print
void println() {
} // end println
}; // end class Employee

class Salesperson: public Employee {
double rate;
Salesperson(char name[],
double wage,
double rate)
: Employee(name, wage) {
this->rate = rate;
} // end constructor
void payForSale(double amount) {
payOwed += amount * rate;
} // end payForSale
void print() {
printf("Salesperson ");
printf(", rate: $%.2f\n", rate);
} // end print
}; // end Salesperson
int main(void) {
Employee mickey("Mickey Mouse", 20);
Salesperson *donald =
new Salesperson("Donald Duck",
10, 0.15);
Employee *company[2];
company[0] = &mickey;
company[1] = donald;
for (int i = 0; i < 2; i++) {
} // end for
} // end main

printf formats:
%d: integer
%f: float or double
%s: string (char array)
%c: char (single character)
scanf formats:
%d: integer
%f: float
%lf: double (first character is L, not one!)
%s: string (char array)
%c: char (single character)
string methods:
/* to use these methods, you
must include <string.h> */
strcpy(char dest[], char src[])
copies src into dest
int strlen(char s[])
returns length of s
int strcmp(char s1[], char s2[])
returns negative if s1 < s2,
0 if s1 == s2
positive if s1 > s2
strcat(char dest[], char src[])
adds src to the end of dest
abstract classes and methods:
virtual void sound(char s[]) = 0;
// Reminder: no "abstract" keyword.
// Class headers do not indicate
// whether the class is abstract or
// not. A class is abstract if it
// contains any abstract methods.

Document preview C_Cheat.pdf - page 1/2

Document preview C_Cheat.pdf - page 2/2

Related documents

c cheat
constants 1
sheet 2 2015
java 7 a comprehensive tutorial pg 620 628
crefcard v2 2

Link to this page

Permanent link

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..

Short link

Use the short link to share your document on Twitter or by text message (SMS)


Copy the following HTML code to share your document on a Website or Blog

QR Code

QR Code link to PDF file C_Cheat.pdf