







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Spring 2009;
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!
#define identifier replacement-text
#define PI 3.
CIRCLE_AREA(x)
(x)
(x)) ... area = CIRCLE_AREA(4); // expanded to: area
Conditional Preprocessor Directives
Conditional preprocessor directives enable you to control the execution ofother preprocessor directives and the compilation of program code - #ifdef is used to determine if a preprocessor directive has been defined - #ifndef is used to determine if a preprocesor directive has not been defined - #endif is used to denote the end of the conditional preprocessor directive - NOTE: This is often used when including header files that have classes defined, which issomething you will learn in the object-oriented programming class next semester #ifndef DEBUG #define DEBUG - #endif
C is not an object-oriented language, though C++ is - C++ is a superset of C, meaning that anything you cando in C you can also do in C++
In C, the closest construct we have to object-orientation is structures, which logically groupvariables together - In C++, a object (which is an instance of a class) hasboth variables and functions
// in a file called Bank_Account.cpp #include “Bank_Account.h” Bank_Account::Bank_Account(double bal, int acct, char* name) { balance = bal; account_number = acct; strcpy(customer_name, name); } void Bank_Account::deposit(double amount) { balance += amount; } void Bank_Account::withdraw(double amount) { balance -= amount; } double Bank_Account::check_balance() { return balance; }
#include “Bank_Account.h” void main() { Bank_Account ba1(2000.30, 1234, “jeff”); Bank_Account ba2(3000.40, 2345, “mike”); ba1.deposit(1000.00); ba2.withdraw(2000.00); printf (“ba1 balance = %.2lf\n”, ba1.check_balance()); printf (“ba2 balance = %.2lf\n”, ba2.check_balance()); }