Download presentation
Presentation is loading. Please wait.
Published byMatthew Daniel Modified over 9 years ago
1
CSC 107 – Programming For Science
2
History of C Dennis Ritchie developed C from 1969 – 1973 While at Bell Labs, created language to develop Unix Based upon B, an earlier programming language (Also used other, less funny, languages)
3
History of C Popular since 1978 book by Kernighan & Ritchie Language grown organically since its creation Companies often add own features beyond standards
4
History of C++ Created by Bjarne Stroustrup to add objects to C Immediately added other features to improve C In 1983, renamed as C++ to show all the changes Name is an inside joke: "++" is increment operator Book published soon after in '85 Updated for quick growth 2.0 release in 1989 1998 adopted as ISO standard C++ 201 x in development now
5
C Versus C++ C++ is designed to be as compatible with C as possible, thereby providing a smooth transition from C
6
C Versus C++ C++ C
7
C Versus C++ C
8
Latest standard of C added most C++ features But classes & objects still not part of C language For this reason, also not a part of CSC 107 C++ compiles almost all C programs natively Differences are minimal and easily avoided C++ is “looser C” once objects are removed Several annoying restrictions removed from C Often supported in C anyway, since make life easier
12
Computers have no common-sense do what you tell them to do They will only do what you tell them to do NOT what you want them to do NOT what you want them to do, which often differs
13
Case-Sensitivity Example of computers being very literal And language not helping by fixing what you say main, Main, & MAiN treated as different words Case of the letters matters, not just the words Could be different, so C++ won’t change Main to main Can help prevent easy mistakes from swapping names With just a little practice, becomes second nature
14
“Whitespace” One (very small) way C++ actually helps you C++ treats whitespace equally – spaces, enters, & tabs Does not matter if there is none, 1, or 1000000000000 Whitespace cannot be within a symbol “ : : ” and “ :: ” are treated differently One or more blanks between words needed Wecansplitwordsbutthecomputercannot
15
“Whitespace” One (very small) way C++ actually helps you C++ treats whitespace equally – spaces, enters, & tabs Does not matter if there is none, 1, or 1000000000000 Whitespace cannot be within a symbol “ : : ” and “ :: ” are treated differently One or more blanks between words needed Wecansplitwordsbutthecomputercannot
16
Your First C++ Program #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }
17
#include Statements #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } Nearly every C++ file begins with this directive May add more #include to include other files Contents of included file usable as if it were here Easy way to copy ideas across multiple files Programs can use two types of #include statements Include system file using #include #include “ filename ” includes a file you wrote
18
Watch Me Pull a Rabbit #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } For now, automatically start each file with this line Details are unimportant – consider it magic
19
Watch Me Pull a Rabbit #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } For now, automatically start each file with this line Details are unimportant – consider it magic
20
Your First C++ Program #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }
21
Using Commands #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } More “magic”, but using has less important purpose Tells compiler to make shortcut & save some typing Two types of using statements to choose from Specify single shortcut with using std::cout using std; gives you a list of shortcuts to use Unlike #include statements, using never required Do not worry about it – will not be using them
22
Your First C++ Program #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }
23
main Function #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } All C++ programs contain function called main Tells computer where to start running program Code inside the braces will be what is executed For the moment, consider this more “magic”
24
main Function #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end } All C++ programs contain function called main Tells computer where to start running program Code inside the braces will be what is executed For the moment, consider this more “magic”
25
Comments Vital Vital for writing and maintaining any program Not required to run program - only for human eyes Computer simply ignores anything in a comment Use to describe code in simple English Sie konnen auch auf Deutsch screiben o U c%d wrte n txt msg Should be used liberally I add comments where cannot see what code does Impossible to have too many comments, if readable
26
Comments in C++ Double slash comments continue to line’s end a = a – 4; // Hi, Mom! // This entire line is a comment! /* … */ comments can be on one or more lines a = a - /* Hi, Mom! */ 4; /* This comment takes an entire line. */ /* This is a really long comment that * goes on to multiple lines. The stars on * lines 2 and on are optional, but * makes things easier to read. */
27
Your Turn Get in groups of 3 & work on following activity
28
For Next Lecture Read sections 4.1 – 4.10 in book for Monday What is a data type? What are variables? How can we use variables in a program? How are literal, constant, & variable different? Week #1 weekly assignment due Tuesday Problems available on Angel – covered 1 st two already If problem takes more than 10 minutes, TALK TO ME!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.