notes:cprog
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog [2014/11/16 15:25] – [11/13/2014] mp010784 | notes:cprog [2018/11/20 08:24] (current) – [Other] sdiarra | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======C/C++ Programming Course | + | <WRAP centeralign round box> |
+ | < | ||
+ | < | ||
+ | <fs 125%>Course Wiki Page</ | ||
+ | </ | ||
- | For help with wiki syntax: | + | ======Projects====== |
+ | ===cci0=== | ||
- | * [[http:// | + | ===dtr0=== |
- | * [[https:// | + | |
- | =====09/ | + | ===sof0=== |
- | Class Notes Project (this) | + | ===dow0=== |
- | author - provides content | + | |
- | designer - provides stylistic tweaks, DocuWiki syntax | + | |
- | reviewer - provides recommendations to content and style | + | |
- | Access Lab46 mail using alpine(e-mail system) | + | ===mbe0=== |
- | will be implementing a points system for doing some ambiguous task of awesomeness or something to that effect per week and drawing a persons name to earn the point for that week? | + | |
- | ====Variables==== | + | ===cbf0=== |
+ | ===cos0=== | ||
- | 73 | + | ===pnc0=== |
- | 3.14 | + | |
- | ' | + | |
- | " | + | |
- | " | + | |
- | " | + | ===mbe1=== |
- | single quotes are used for a single character, | + | ===pnc1=== |
- | more than a single character and double quotes("" | + | |
- | 0xdeadbeef memory address (usually in hexadecimal) | + | ===gfo0=== |
+ | ===oop0=== | ||
+ | <color # | ||
- | your user name in Unix is stored in the variable $USER | + | **Objective** |
- | ====To Make a Variable==== | + | The objective of this project is to get a stronger grasp of object-oriented programming, |
- | | + | **Background** |
- | | + | |
+ | Over the last few weeks we have covered multiple ways of implementing object oriented model; using the single file method of doing things, and multiple files method of doing things. Using that skill-set, you(we) must implement a program that will replicate the functions of a calculator. | ||
- | declaring variables: | + | **Scope** |
- | type name; | + | |
- | declaring and initializing in one line: | + | |
- | type name = 0; | + | |
- | ====Data types of Variables==== | + | For the scope of this project, as long as you implement a program that adopt the object-oriented methodology in C++ - there are no other particular restrictions. |
+ | **Program** | ||
- | int - integer | + | Replicate the functionality of a calculator, with the ability to accomplish multiple mathematical functions. Given a set of inputs the program must have the capability to compute the numbers based on the functions. |
- | char - character | ||
+ | ======URLs====== | ||
+ | **String Formating(fprintf)** | ||
+ | http:// | ||
- | math style: | + | **Standard Template Library** |
- | x+2=y | + | http:// |
- | computer style - variable goes to the left, isolated: | ||
- | y=x+2 | ||
- | '*' - reference | + | **Vector Reference** |
+ | http:// | ||
+ | ======Notes====== | ||
+ | <color # | ||
- | '&' | ||
- | ' | + | As a follow to our discussion this week, typedef is a naming convention used in C/C+, its primary use case is to declare various data-types. Defining data types in C can be a tedious task, some data types and variables names only can up to 1/2 of an 80-85char line of code, which ultimately will result in either unreadability, |
- | + | < | |
- | '0...' is assumed to be an octal value | + | unsigned long long int a_very_long_variable_name |
- | + | ||
- | ====Memory Address Table==== | + | |
- | + | ||
- | | ^ 0 ^ 1 ^ 2 ^ 3 ^ | + | |
- | ^ 0 | 5 (a) | + | |
- | ^ 1 | + | |
- | ^ 2 | + | |
- | ^ 3 | 0x12 | + | |
- | + | ||
- | in class source | + | |
- | < | + | |
- | # | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int a = 5; | + | |
- | int b = 0x3D, c = 073; | + | |
- | int *d; | + | |
- | char e, *f; | + | |
- | e = ' | + | |
- | d = &c; | + | |
- | f = &e; | + | |
- | + | ||
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | return (0); | + | |
- | } | + | |
</ | </ | ||
- | |||
- | This is compiled with: | ||
- | < | ||
- | or | ||
- | < | ||
- | as long as the source code file (var1.c)isn' | ||
+ | an optimization for this line would be the following: | ||
- | program is run with: | + | <code> |
- | <cli> | + | |
+ | typedef unsigned long long int ulli_t; | ||
+ | ulli_t a_very_long_variable_name = some+expressions+here; | ||
- | my output: | + | //much cleaner than the above version(could be better) |
- | address of a is : 0x7ffffa714a1c\\ | ||
- | address of b is : 0x7ffffa714a18\\ | ||
- | address of c is : 0x7ffffa714a14\\ | ||
- | address of d is : 0x7ffffa714a08\\ | ||
- | address of e is : 0x7ffffa714a07\\ | ||
- | address of f is : 0x7ffffa7149f8\\ | ||
- | a contains: 5\\ | ||
- | b contains: 61\\ | ||
- | c contains: 59\\ | ||
- | d contains: 0xfa714a14\\ | ||
- | e contains: X\\ | ||
- | f contains: 0x7\\ | ||
- | d dereferenced is: 59\\ | ||
- | f dereferenced is: X\\ | ||
- | |||
- | End Notes - Tuesday September 02, 2014 - MJP\\ | ||
- | |||
- | |||
- | **Author** - Matthew Page | ||
- | |||
- | (Note to guys following me, I'm putting up the content and resisting my OCD-like urge to format the text in some way to leave something for you guys to do, with one exception, I am throwing the code tags around today' | ||
- | |||
- | **Designer** - Dan Shadeck | ||
- | |||
- | Created headlines for sections of the notes. Used the ordered list item for "To Make a Variable" | ||
- | |||
- | **Reviewer** - Mike Merrick | ||
- | |||
- | Simple spelling corrections. Great and useful tips and help in these notes for everyone | ||
- | |||
- | **Master of the known universe (and beyond) - Matthew Haas** | ||
- | |||
- | Beautiful job all around- this should serve as an excellent example for future note taking sessions. I made 3 quick changes-- | ||
- | - in the memory table, address 0x00, you had "int a"... shouldn' | ||
- | - if you noticed the c variable in the memory table above was rendering as a copyright symbol ' | ||
- | - I added the language to the code tag, as well as line numbers. View the section source to see how this is done. You'll notice that identifying the language will enable color coding. | ||
- | |||
- | But as I said: excellent work, one and all. | ||
- | =====09/ | ||
- | |||
- | ====Var1.c==== | ||
- | |||
- | <code c 1> | ||
- | # | ||
- | int main() | ||
- | { | ||
- | int a=5; | ||
- | int b=0x3D, c=073; | ||
- | int *d; | ||
- | char e, *f; | ||
- | e = ' | ||
- | | ||
- | | ||
- | |||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | | ||
- | | ||
- | |||
- | return (0); | ||
- | } | ||
</ | </ | ||
+ | Although **typedef** appears to be defining only types, it removes some overheads down the road as a developer, | ||
- | If we look at the var1.c we notice that a, b, c, d, e, and f are all variables available in the main() code block. This is an example of variable scope. Anything that is declared outside of the main() code block would be called global or file scope. With in our main() code block we can also have sub-blocks of code. This is called sub-scope. | + | ------- |
+ | <color # | ||
- | ====Scope==== | + | Undef is a directive in that is available in C and C++. It as the form of #undef when called. Undef is used as a complement to the #define, as a preprocessor directive it is used to enclosed a #define statement to make sure there is no naming conflict |
- | Below is a representation | + | |
- | < | + | < |
- | /* Ex: Global Scope */ | + | |
- | int c; | + | |
- | { | + | |
- | /*Ex: Block Scope */ | + | |
- | int a; | + | |
- | { | + | |
- | /*Ex: Sub-Scope */ | + | |
- | int b; | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
- | ====Variable Declaration and Initialization==== | + | easy peasy! |
- | Declaration and initialization of variables can be done all in one or as two separate things. | + | ======Other====== |
+ | ------- | ||
+ | <color # | ||
- | * declaration: | + | Recently I have discovered |
- | * initialization: | + | < |
- | * both: int a=5; | + | |
- | + | ||
- | This small piece of Var1.c is a good example of this! | + | |
- | < | + | |
- | int a=5; | + | |
- | int b=0x3D, c=073; | + | |
- | int *d; | + | |
- | char e, *f; | + | |
- | e = ' | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | + | A working | |
- | Looking at line 4 & 5 in the above code also demonstrates the use pointers and characters. | + | |
- | + | ||
- | Char e, *f; is the declaration | + | |
- | e = ' | + | |
- | + | ||
- | ***I'm going to need some help on the pointer portion of this :/*** | + | |
- | + | ||
- | ====Pointers Cont.==== | + | |
- | To Define a pointer variable proceed with its name in asterisk. I.E. | + | |
- | + | ||
- | <code c> | + | |
- | int *ptr; // The ' | + | |
- | // a pointer variable to set aside said allotment | + | |
- | // of bytes in memory. | + | |
- | + | ||
- | int j, k; | + | |
- | + | ||
- | k = 2; | + | |
- | j = 7; <-- line 1 | + | |
- | k = j; <-- line 2 | + | |
- | </ | + | |
- | + | ||
- | In the above, the compiler interprets the j in line 1 as the address of the variable j (its lvalue) and creates code to copy the value 7 to that address. In line 2, however, the j is interpreted as its rvalue (since it is on the right hand side of the assignment operator ' | + | |
- | + | ||
- | + | ||
- | ptr + 1; would be a memory allocation of 4 decimal. using the unary ++ operator, either pre- or post-, increments the address it stores by the amount sizeof(type) where " | + | |
- | + | ||
- | ====References for Chapter 1==== | + | |
- | + | ||
- | "The C Programming Language" | + | |
- | B. Kernighan and D. Ritchie | + | |
- | Prentice Hall | + | |
- | ISBN 0-13-110362-8\\ | + | |
- | + | ||
- | + | ||
- | + | ||
- | ====Format Specifiers==== | + | |
- | + | ||
- | " | + | |
- | + | ||
- | We cannot know the actual address of variable as it changes everytime we run the program, so we reference the address of the variable.\\ | + | |
- | + | ||
- | a,b,c are integers\\ | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | + | ||
- | " | + | |
- | + | ||
- | " | + | |
- | American Standard Code for Information Interchange.\\ | + | |
- | 7-bit/8-bit ASCII | + | |
- | 16-bit Unicode (first 8 bytes are ASCII) | + | |
- | other ones, IBM-EBCDIC | + | |
- | + | ||
- | e = 'A';\\ | + | |
- | same as:\\ | + | |
- | e = 65;\\ | + | |
- | + | ||
- | 4 bytes - integer\\ | + | |
- | 2 bytes - " | + | |
- | 1 byte - " | + | |
- | + | ||
- | All chars need to be placed in between single quotes as displayed above. | + | |
- | + | ||
- | This is compiled with: | + | |
- | < | + | |
- | or | + | |
- | < | + | |
- | as long as the source code file (var1.c)isn' | + | |
- | + | ||
- | + | ||
- | program is run with: | + | |
- | < | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | **Author Note:** Matt I was going to add the portion about compiling var1.c and running it but doing this with out styling is going to kill me. Do you want to add this portion from what you already made? If this is an issue just shoot me an email [[dshadeck@corning-cc.edu|dshadeck@corning-cc.edu]]. | + | |
- | + | ||
- | **Designer Note:** Added the compile and run section, as well as format specifiers section. | + | |
- | + | ||
- | + | ||
- | **Reviewer: | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | =====09/ | + | |
- | ====status==== | + | |
- | First I would like to remind everybody of this useful command that is now available to us: | + | |
- | + | ||
- | < | + | |
- | lab46:~$ status cprog | + | |
- | </ | + | |
- | + | ||
- | This will display your progress on attendance, opus, and projects. | + | |
- | + | ||
- | ====scanf==== | + | |
- | Today we were introduced to a new function called scanf. To prompt users for something to scan you must leave the \n new line identifier out. Then continue on to the scanf function. In the first perimeter type the data type you intend to scan. for example, you would type %d for an integer. | + | |
- | + | ||
- | Scanf changes something and put it in some address. | + | |
- | + | ||
- | In the next perimeter you would use the & operator to assign the scanned info to a variable. We used this function to create a nifty program that calculates averages. | + | |
- | + | ||
- | <code c 1> | + | |
- | #include < | + | |
- | main() | + | |
- | { | + | |
- | int a; | + | |
- | int b; | + | |
- | int c; | + | |
- | int d; | + | |
- | float avg; | + | |
- | + | ||
- | printf(" | + | |
- | scanf(" | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | + | ||
- | avg=(float)(a+b+c+d)/ | + | |
- | + | ||
- | printf(" | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ===side notes=== | + | |
- | *(float) is declared during the math equation to get the modulus. | + | |
- | *In the last printf the first integer and the answer' | + | |
- | + | ||
- | **Author & Designer: Derek Southard.** | + | |
- | **Just a reminder to do HG Pull then HG Push at each class and lab.** | + | |
- | **Reviewer: Sudesh Tiwari.** | + | |
- | + | ||
- | =====09/ | + | |
- | + | ||
- | Today in class we went over addressing multiple variables without having to write a statement for each individual variable being entered in. | + | |
- | + | ||
- | <code c> | + | |
- | # | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int number[2]; | + | |
- | int i; input; | + | |
- | number[0]=0; | + | |
- | number[1]=0; | + | |
- | + | ||
- | printf(" | + | |
- | scanf(" | + | |
- | for(i=o; | + | |
- | { | + | |
- | number[1]= number[1]+1; | + | |
- | if(number[1]> | + | |
- | + | ||
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | + | ||
- | ====Average program with an array==== | + | |
- | + | ||
- | <code c 1> | + | |
- | + | ||
- | #include < | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | float avg = 0; | + | |
- | int score[4], count = 0; | + | |
- | for(count = 0; count < 4; count = count +1) | + | |
- | { | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | avg = avg + score[count]; | + | |
- | } | + | |
- | avg = avg/ | + | |
- | printf(" | + | |
- | return(0); | + | |
- | } | + | |
- | /* or int score[]={73, | + | |
- | for is a loop like a while */ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ====Format String Specifiers==== | + | |
- | Variable type Length Modifier Example | + | |
- | + | ||
- | short int, unsigned short int h short int i = 3; printf( " | + | |
- | long int or unsigned long int l long int i = 3; printf( " | + | |
- | wide characters or strings l wchar_t* wide_str = L"Wide String"; | + | |
- | long double L long double d = 3.1415926535; | + | |
- | + | ||
- | + | ||
- | You can print all of the normal C types with printf by using different placeholders: | + | |
- | int (integer values) uses %d | + | |
- | float (floating point values) uses %f | + | |
- | char (single character values) uses %c | + | |
- | character strings (arrays of characters, discussed later) use %s | + | |
- | + | ||
- | + | ||
- | + | ||
- | **Author Jacques Gates** | + | |
- | + | ||
- | **Designer Michael Merrick** | + | |
- | + | ||
- | **Reviewer: Derek Southard. Made some minor spelling changes and added the average program with the array.** | + | |
- | =====09/ | + | |
- | Today we took the program we wrote on 09/14/2014 and reworked it to count in different base numbers. | + | |
- | + | ||
- | <code c 1> | + | |
- | #include < | + | |
- | #define MAX 2 // When ever the computer sees MAX it counts it as 2. | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int base, | + | |
- | for(i=0; | + | |
- | { | + | |
- | number[i]=0; | + | |
- | } | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | for(i=0; | + | |
- | { | + | |
- | printf(" | + | |
- | number[MAX-1]=number[MAX-1]+1; | + | |
- | if(number[MAX-1]> | + | |
- | { | + | |
- | number[MAX-1]=0;// | + | |
- | number[MAX-2]++;// | + | |
- | } | + | |
- | } | + | |
- | return(0); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | increment of a variable ( up or down 1) use | + | |
- | + | ||
- | ++i; up | + | |
- | +i; down | + | |
- | + | ||
- | MAX 2 is a variable used to do different functions in the same program. Changing the number after MAX allows you to change parameters in the program MAX at 2 the numbers will be 0,1 and the program will run 2 times. | + | |
- | + | ||
- | With this we are able to count in bases from 2-10. | + | |
- | We were also asked to attempt making it count to three digits then four before the next class. | + | |
- | + | ||
- | We also discussed a couple of math tricks like 25². add 1 to the first number and then multiply for this it would | + | |
- | 2+1=3 | + | |
- | 3*2= 6 | + | |
- | for 5 | + | |
- | 5*5=25 hence you only being able to do numbers ending in 5 | + | |
- | + | ||
- | For multiplication of eleven, take the two end numbers and place them on the sides then add the numbers together for the middle | + | |
- | so it would look like | + | |
- | 32 | + | |
- | *11 | + | |
- | 352 | + | |
- | + | ||
- | This lead into a take home project where we have to write a program that solves squares of 5 through this style. | + | |
- | + | ||
- | Author-David Woodcock (Sorry it took so long to upload I was very busy the past 2 days) | + | |
- | + | ||
- | Designer Jacques Gates made a couple spelling corrections and corrected the math tips./ tricks, definition of MAX | + | |
- | + | ||
- | Reviewer- Zack Golden made some spelling/ | + | |
- | =====09/ | + | |
- | + | ||
- | Today in class we went over our base counter program. We saw that whenever we took our program to the next digit there was a pattern. For example, 2 digit has MAX-1, 3 digit MAX-1 and MAX-2, and 4 Digit has MAX-1, | + | |
- | + | ||
- | <code c 1> | + | |
- | #include < | + | |
- | #define MAX 6 | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int base, i, input, j, number[MAX]; | + | |
- | + | ||
- | for(i = 0; i < MAX; i++) | + | |
- | { | + | |
- | number[i] = 0; | + | |
- | } | + | |
- | + | ||
- | printf(" | + | |
- | scanf(" | + | |
- | + | ||
- | printf(" | + | |
- | scanf(" | + | |
- | + | ||
- | for(i = 0; i < input; i++) | + | |
- | { | + | |
- | for (j = 0; j < MAX; j++) | + | |
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | number[MAX-1] = number[MAX-1] + 1; | + | |
- | + | ||
- | for (j = 1; j < MAX; j++) | + | |
- | { | + | |
- | if (number[MAX-j] > (base-1)) | + | |
- | { | + | |
- | number[MAX-j] = 0; | + | |
- | number[MAX-(j+1)] = number[MAX-(j+1)] + 1; | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | return(0); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Just a reminder that our assignment called " | + | |
- | + | ||
- | + | ||
- | Author- Zack Golden | + | |
- | designer - Sudesh Tiwari | + | |
- | reviewer - Dan Shadeck | + | |
- | + | ||
- | + | ||
- | + | ||
- | **xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx** \\ \\ | + | |
- | + | ||
- | =====09/ | + | |
- | + | ||
- | + | ||
- | **New Project announced - Day of the Week**\\ | + | |
- | + | ||
- | a programmatic solution to a mental math trick to determine the day of the week that January 1st of a given year willf all on, by associating a number with each day of the week as:\\ | + | |
- | + | ||
- | ^ Sunday | + | |
- | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | | + | |
- | + | ||
- | *Note: We are now on our next cprog project called Day of Week. You can find this on the project page. | + | |
- | + | ||
- | this is the safe way to determine sizes instead of hard coding, as for example, a 32 bit system and a 64 bit system would have diffent sizes:\\ | + | |
< | < | ||
- | sizeof(long int)*6 | + | //From my own laptop |
- | </code> | + | system("ssh user@lab46.corning-cc.edu status cprog") |
- | + | | |
- | __**DataType Sizes**__ | + | |
- | + | ||
- | <code c 1> | + | |
- | + | ||
- | #include < | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | printf("A char is %ld bytes.\n", sizeof(char)); | + | |
- | printf(" | + | |
- | | + | |
- | | + | |
- | printf(" | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | + | ||
- | | + | |
- | //If you want to know the size of datatype in long ints use %ld (this is the safe way to | + | |
- | //do it if you have a newer compiler. Therefore, this program prints the size of a char, | + | |
- | // | + | |
- | //an int and long int are of the same size. | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | **Author** - Mike Merrick\\ | + | |
- | **Designer** - Derek Southard - note to author: Aren't these the 9/23 notes from unix? I will put up the new 9/23 code we did (in cprog) + tag and explain it it. \\ **Note to reveiwer: Add anything you think I may have missed. Also, you may want to delete the top portion of the notes.** \\ | + | |
- | + | ||
- | (Thank you for fixing my mistake)mmerrick\\ | + | |
- | + | ||
- | **Reviewer** - Matthew Page - added a header for this day 09/23/2014, added a little bit up top\\ | + | |
- | =====09/ | + | |
- | + | ||
- | {{http:// | + | |
- | + | ||
- | Datatype cont' | + | |
- | __Sizeof( )__ | + | |
- | signed or unsigned | + | |
- | - char | + | |
- | - short int | + | |
- | - long int | + | |
- | - long long int | + | |
- | + | ||
- | 3 bit = 2^3 = 8 possible combinations | + | |
- | Unsigned Signed | + | |
- | 000 0 +0 | + | |
- | 001 1 +1 | + | |
- | 010 2 +2 | + | |
- | 011 3 +3 | + | |
- | 100 4 -4 | + | |
- | 101 5 -3 | + | |
- | 110 6 -2 | + | |
- | 111 7 -1 | + | |
- | + | ||
- | Is most significant bit | + | |
- | 0=positive | + | |
- | 1=negative | + | |
- | + | ||
- | **Two complement** | + | |
- | -inverting the first number and adding one | + | |
- | 100 101 110 111 | + | |
- | 010 010 001 000 | + | |
- | +1 +1 +1 +1 | + | |
- | -100 = -011 = -010 = -001 | + | |
- | + | ||
- | 0000 0000 | + | |
- | 1111 1111 | + | |
- | 256 unique values | + | |
- | • Unsigned char | + | |
- | • (0-255) | + | |
- | • (Signed char) | + | |
- | • (-128 - +127) | + | |
- | + | ||
- | FFFF | + | |
- | 1111 1111 1111 1111 ----- 16 bits | + | |
- | +127 is the maximum signed value | + | |
- | + | ||
- | **LOGIC in C**\\ | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | + | ||
- | Examples of AND and OR | + | |
- | + | ||
- | AND | + | |
- | AB X | + | |
- | 00 0 | + | |
- | 01 0 | + | |
- | 10 0 | + | |
- | 11 1 | + | |
- | + | ||
- | OR | + | |
- | AB X | + | |
- | 00 0 | + | |
- | 01 1 | + | |
- | 10 1 | + | |
- | 11 1 | + | |
- | **Author** - Sudesh Tiwari | + | |
- | **Editor** - David Woodcock - I was busy with two other projects from another class this week I am going have to leave this up to the reviewer if he wants. | + | |
- | **Reviewer** - Matthew Page - added my pic of the board from class today, fixed LOGIC section with nowiki tags. Still have to clean this up a little.\\ | + | |
- | =====09/ | + | |
- | + | ||
- | __Makefile__ | + | |
- | + | ||
- | * collection of actions instructing Make how to perform the task. | + | |
- | * "make help" to bring up actions | + | |
- | * use “make” to make things | + | |
- | + | ||
- | __CMD arguements__ | + | |
- | + | ||
- | * argc- argument counter (at least one) | + | |
- | * argv- argument vector, an array of strings | + | |
- | * first argument must be int, second must be char | + | |
- | + | ||
- | __ Program__ | + | |
- | * CLA.c | + | |
- | + | ||
- | <code c 1> | + | |
- | + | ||
- | # | + | |
- | + | ||
- | int main(int argc, char **argv) | + | |
- | { | + | |
- | int i; | + | |
- | printf(" | + | |
- | printf(" | + | |
- | for(i=0; | + | |
- | printf(" | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
</ | </ | ||
- | + | **Note that the script would prompt you to enter your <color #ed1c24>password</color>.** | |
- | + | ||
- | + | ||
- | __Pipe Math assignment__ | + | |
- | + | ||
- | | + | |
- | | + | |
- | * coverts ascii to number using atoi(3), value=atoi(argv[1]); | + | |
- | * cd pipemath to access files | + | |
- | + | ||
- | Author- Zack Golden, you can email me at justgolden07@gmail.com if you have questions or suggestions. | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ##### OCT 2 2014######## | + | |
- | OCT 2 2014 | + | |
- | + | ||
- | if (a==1) | + | |
- | { | + | |
- | || | + | |
- | } | + | |
- | if(a==2) | + | |
- | { | + | |
- | || | + | |
- | } | + | |
- | + | ||
- | vs | + | |
- | + | ||
- | if(a==1) | + | |
- | { || | + | |
- | } | + | |
- | else if (a==2) | + | |
- | { | + | |
- | + | ||
- | || | + | |
- | } | + | |
- | + | ||
- | + | ||
- | if statements work | + | |
- | code | + | |
- | code | + | |
- | code | + | |
- | compare a,1 | + | |
- | begin part 2014 | + | |
- | code | + | |
- | code | + | |
- | code | + | |
- | + | ||
- | + | ||
- | fetch | + | |
- | decode | + | |
- | execute | + | |
- | store | + | |
- | + | ||
- | all program in memory | + | |
- | + | ||
- | crafty people came up with | + | |
- | + | ||
- | fetch decode encode store (Four stage pipeline) | + | |
- | + | ||
- | Key POINT USE IF AND IF ELSE STATEMENTS | + | |
- | + | ||
- | + | ||
- | loops and whiles are expensive in the pipeline | + | |
- | + | ||
- | + | ||
- | new code: | + | |
- | readability = less efficient vs writable=more efficient | + | |
- | + | ||
- | + | ||
- | readability tool | + | |
- | modularity | + | |
- | subroutine | + | |
- | procedure | + | |
- | Function | + | |
- | + | ||
- | + | ||
- | IE: y=F(atoi(argv[1])); | + | |
- | + | ||
- | + | ||
- | how to write a function: | + | |
- | variable= name give to a regain of memory | + | |
- | declare | + | |
- | define/ initiation | + | |
- | + | ||
- | functions | + | |
- | declare | + | |
- | define | + | |
- | + | ||
- | functions are made global most of the time because they are used troughs the program | + | |
- | to make global make outside of main | + | |
- | + | ||
- | (Parameters) | + | |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | int sum(int *arr, int n);< | + | |
- | float average(int, | + | |
- | + | ||
- | =====10/ | + | |
- | + | ||
- | =====10/ | + | |
- | + | ||
- | =====10/ | + | |
- | + | ||
- | =====10/ | + | |
- | **10/ | + | |
- | **Knowledge Assessment during class time** | + | |
- | + | ||
- | Topics include variables, functions and function calls | + | |
- | if statements, Binary. | + | |
- | + | ||
- | Use the ' | + | |
- | Reviewed the file. | + | |
- | Discussed Library and header files. | + | |
- | < | + | |
- | < | + | |
- | + | ||
- | Declared global function. A function that can be called anywhere in the program. | + | |
- | int | + | |
- | float average(int, | + | |
- | + | ||
- | int main() | + | |
- | This line initiates the declaration of a function. Essentially, | + | |
- | Declared local function. | + | |
- | + | ||
- | =====10/ | + | |
- | \\ __**USEFUL FUNCTIONS**__ \\ | + | |
- | *malloc - which stands for " | + | |
- | *sizeof - function that returns the size of a specified datatype. \\ __**EXAMPLE (goes with our funcfun program.)**__ \\ \\ <code c 1> | + | |
- | scores=(int*)malloc(sizeof(int)*num); | + | |
- | /*size of returns thesize of an int and multiply' | + | |
- | the number of ints aka num,(num=4 in this case), then | + | |
- | malloc allocates the specified amount of memory. In this | + | |
- | case, it will take 4 bytes times 4 bytes giving 16 bytes, | + | |
- | which is just enough to store 4 integers.*/ | + | |
- | *(scores+0) | + | |
- | / | + | |
- | you can dereference the things at the address shifted up | + | |
- | from the starting adress.*/ | + | |
- | </ | + | |
- | \\ __**DATA STRUCTURES**__ \\ | + | |
- | *The WIKIPEDIA [[http:// | + | |
- | *A node is another word for a structure, they can be used together: structure node. | + | |
- | *A structure pointer looks like this ->, instead of this *. \\ __**MATT' | + | |
- | /* | + | |
- | * structs.c | + | |
- | * | + | |
- | | + | |
- | * | + | |
- | * To compile: gcc -o structs1 structs1.c | + | |
- | * | + | |
- | */ | + | |
- | # | + | |
- | //# | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int i; | + | |
- | char entry[80], entries = 4, junk; | + | |
- | + | ||
- | struct person { | + | |
- | char name[80]; | + | |
- | int age; | + | |
- | float height; | + | |
- | }; | + | |
- | + | ||
- | do { | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | } while (entries <= 0); | + | |
- | + | ||
- | struct person people[entries]; | + | |
- | + | ||
- | for(i=0; i< | + | |
- | { | + | |
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | // prompt | + | |
- | printf(" | + | |
- | + | ||
- | scanf(" | + | |
- | // | + | |
- | // | + | |
- | + | ||
- | // prompt for age (integer) | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | + | ||
- | // prompt for height (float) | + | |
- | printf(" | + | |
- | scanf(" | + | |
- | + | ||
- | // Get newline out of the input stream | + | |
- | junk = fgetc(stdin); | + | |
- | // | + | |
- | } | + | |
- | + | ||
- | printf(" | + | |
- | for(i=0; i< | + | |
- | { | + | |
- | printf("# | + | |
- | } | + | |
- | printf(" | + | |
- | + | ||
- | printf(" | + | |
- | for(i=0; i< | + | |
- | { | + | |
- | printf("# | + | |
- | } | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | </ | + | |
- | \\ __**Author, Designer, & Reviewer**__ \\ --- //[[|Derek Southard]] 2014/10/24 20:39// | + | |
- | + | ||
- | + | ||
- | =====10-28-2014===== | + | |
- | Knowledge Assessment 31 Oct 2014 | + | |
- | REVIEW | + | |
- | Interacting with files inside the file system | + | |
- | -fundamental actions to files | + | |
- | - Open | + | |
- | - Read | + | |
- | - Write | + | |
- | - Append | + | |
- | - create | + | |
- | - remove/ | + | |
- | - Seek/ | + | |
- | + | ||
- | Lets Explore some of these features (datafile.txt) | + | |
- | + | ||
- | how to interact with files is File *fprt; | + | |
- | | + | |
- | they return a FILE * ( file pointer) | + | |
- | + | ||
- | | + | |
- | F seek=scroll keys in the file | + | |
- | the computer thinks on a 1D stystle with the idea of everything being on one line | + | |
- | + | ||
- | + | ||
- | When ever you use fpfrintf three file pointers are auto created | + | |
- | -file Stdin, stdout, | + | |
- | + | ||
- | Example of the Code: | + | |
- | <code c 1> | + | |
- | #include <stdio.h> | + | |
- | # | + | |
- | + | ||
- | int main() | + | |
- | + | ||
- | { | + | |
- | char c; | + | |
- | int i; | + | |
- | int count=0; | + | |
- | FILE *fptr; | + | |
- | fptr=fopen(" | + | |
- | + | ||
- | + | ||
- | if(fptr==NULL) | + | |
- | + | ||
- | { | + | |
- | fprintf(stdout, | + | |
- | exit(1); | + | |
- | + | ||
- | } | + | |
- | | + | |
- | // | + | |
- | while((c=fgetc(fptr))!=EOF) | + | |
- | { | + | |
- | + | ||
- | // | + | |
- | fprintf(stdout," | + | |
- | } | + | |
- | fclose(fptr); | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | + | ||
- | + | ||
- | </code> | + | |
- | + | ||
- | Author/ | + | |
- | + | ||
- | =====11-04-2014===== | + | |
- | We started C++ today (C++ programming is 90% similar to C) | + | |
- | Object Oriented programming C++ | + | |
- | + | ||
- | Three major points of **Object Oriented Programming: | + | |
- | *Polymorphism | + | |
- | *Inheritance | + | |
- | *Encapsulation | + | |
- | + | ||
- | The biggest difference between C programming and C++: \\ C++ is able to use functions with its structures which are called classes instead. | + | |
- | + | ||
- | Our introduction to classes (private and public) | + | |
- | <code c 1> | + | |
- | #include < | + | |
- | + | ||
- | class rectangle | + | |
- | { | + | |
- | public: // member functions | + | |
- | + | ||
- | int area(); | + | |
- | int perimeter(); | + | |
- | rectangle(); | + | |
- | rectangle(int, | + | |
- | + | ||
- | private: // member variables | + | |
- | + | ||
- | int length; | + | |
- | int width; | + | |
- | }; | + | |
- | // defining our classes area, | + | |
- | int rectangle:: | + | |
- | { | + | |
- | return((length*width)); | + | |
- | } | + | |
- | + | ||
- | int rectangle:: | + | |
- | { | + | |
- | return((2*width)+(2*length)); | + | |
- | } | + | |
- | rectangle:: | + | |
- | { | + | |
- | length=0; | + | |
- | width=0; | + | |
- | } | + | |
- | rectangle:: | + | |
- | { | + | |
- | this-> | + | |
- | this-> | + | |
- | } | + | |
- | int main() | + | |
- | { | + | |
- | int area, | + | |
- | area=0; | + | |
- | perimeter=0; | + | |
- | rectangle rect1; | + | |
- | rectangle *rect2; | + | |
- | rect2=new rectangle(4, | + | |
- | // | + | |
- | area=rect1.area(); | + | |
- | perimeter=rect1.perimeter(); | + | |
- | printf(" | + | |
- | printf(" | + | |
- | area=rect2-> | + | |
- | perimeter=rect2-> | + | |
- | printf(" | + | |
- | printf(" | + | |
- | + | ||
- | return(0); | + | |
- | } | + | |
- | + | ||
- | + | ||
- | </ | + | |
- | + | ||
- | **Author-David Woodcock**\\ | + | |
- | **Designer-Derek Southard** - I did pretty it up, sorry I was late. I checked before they were wrote to design, then I forgot to come back until now. \\ | + | |
- | **Reviewer-Matthew Page** | + | |
- | + | ||
- | ====11-06-2014==== | + | |
- | + | ||
- | We did a little modifying from the previous rectangle.cc program we wrote on Tuesday. This one allows us to put in the length and width for rectangle 1 so we no longer get 0 for area and perimeter. | + | |
- | + | ||
- | <code c 1> | + | |
- | #include < | + | |
- | # | + | |
- | + | ||
- | class rectangle | + | |
- | { | + | |
- | public: // member functions | + | |
- | + | ||
- | int area(); | + | |
- | int perimeter(); | + | |
- | rectangle(); | + | |
- | rectangle(int, | + | |
- | int getlength(); | + | |
- | void setlength(int); | + | |
- | int getwidth(); | + | |
- | void setwidth(int); | + | |
- | + | ||
- | private: // member variables | + | |
- | + | ||
- | int length; | + | |
- | int width; | + | |
- | }; | + | |
- | // defining our classes area, | + | |
- | + | ||
- | int rectangle:: | + | |
- | { | + | |
- | return((length*width)); | + | |
- | } | + | |
- | + | ||
- | int rectangle:: | + | |
- | { | + | |
- | return((2*width)+(2*length)); | + | |
- | } | + | |
- | + | ||
- | rectangle:: | + | |
- | { | + | |
- | length=0; | + | |
- | width=0; | + | |
- | } | + | |
- | + | ||
- | rectangle:: | + | |
- | { | + | |
- | this-> | + | |
- | this-> | + | |
- | } | + | |
- | + | ||
- | int rectangle:: | + | |
- | { | + | |
- | return(length); | + | |
- | } | + | |
- | + | ||
- | void rectangle:: | + | |
- | { | + | |
- | this-> | + | |
- | } | + | |
- | + | ||
- | int rectangle:: | + | |
- | { | + | |
- | return(width); | + | |
- | } | + | |
- | + | ||
- | void rectangle:: | + | |
- | { | + | |
- | this-> | + | |
- | } | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int area, | + | |
- | area=0; | + | |
- | perimeter=0; | + | |
- | rectangle rect1; | + | |
- | rectangle *rect2; | + | |
- | rect2=new rectangle(4, | + | |
- | rect1.setlength(6); | + | |
- | rect1.setwidth(7); | + | |
- | area=rect1.area(); | + | |
- | perimeter=rect1.perimeter(); | + | |
- | printf(" | + | |
- | printf(" | + | |
- | area=rect2-> | + | |
- | perimeter=rect2-> | + | |
- | printf(" | + | |
- | printf(" | + | |
- | return(0); | + | |
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | __Standard ways of defining a class__ | + | |
- | + | ||
- | Public: This means that all of the functions below this(and any variables) are accessible to the rest of the program.NOTE: | + | |
- | + | ||
- | Private: Only the Function that contains the private parts can access them. | + | |
- | + | ||
- | Protected: This means that all the variables under this, until a new type of restriction is placed, will only be accessible to other functions in the class and child class. | + | |
- | + | ||
- | Matt gave us a little preview on inheritance which is what we will be covering next Tuesday. Here is some code and comments we went over at the end of class: | + | |
- | + | ||
- | <code c 2> | + | |
- | class shape // parent class | + | |
- | { | + | |
- | public: | + | |
- | shape(); | + | |
- | void setlength(int); | + | |
- | int getlength(); | + | |
- | void setwidth(int); | + | |
- | int getlength(); | + | |
- | + | ||
- | private: | + | |
- | int length; | + | |
- | int width; | + | |
- | }; | + | |
- | + | ||
- | class rectangle: | + | |
- | // single : to identify the class that is inheriting (rectanlge is inheriting from shape) | + | |
- | // rectangle is a child of shape | + | |
- | // everything is copied from shape into rectangle | + | |
- | // can only access the parents public parts not private (-_-) | + | |
- | + | ||
- | { | + | |
- | public: | + | |
- | rectangle(); | + | |
- | int area; | + | |
- | int perimeter(); | + | |
- | private: | + | |
- | friend int thing; //assigns friendship to a class allowing private variables to be access | + | |
- | }; | + | |
- | + | ||
- | class traingle: | + | |
- | { | + | |
- | public: | + | |
- | + | ||
- | }; | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | Author: Sudesh Tiwari \\ | + | |
- | Designer: Zack Golden \\ | + | |
- | Reviewer: David Woodcock \\ | + | |
- | + | ||
- | ====11/ | + | |
- | + | ||
- | + | ||
- | **Inheritance**\\ | + | |
- | -We're doing a base class and then from that a derived class.\\ | + | |
- | + | ||
- | Today' | + | |
- | + | ||
- | Starting with **node.h**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * node.h - a header file for something | + | |
- | * | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #ifndef _NODE_H | + | |
- | #define _NODE_H | + | |
- | #include < | + | |
- | + | ||
- | class Node { | + | |
- | public: | + | |
- | Node(); | + | |
- | Node(int); | + | |
- | void setValue(int); | + | |
- | int getValue(); | + | |
- | private: | + | |
- | int value; | + | |
- | }; | + | |
- | # | + | |
- | </ | + | |
- | + | ||
- | Next file, **create.cc**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * create.cc - another file for something | + | |
- | * | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #include " | + | |
- | + | ||
- | Node:: | + | |
- | { | + | |
- | value=0; | + | |
- | } | + | |
- | + | ||
- | Node:: | + | |
- | { | + | |
- | this-> | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Next file, **value.cc**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * value.cc - another file for something | + | |
- | * | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #include " | + | |
- | + | ||
- | void Node:: | + | |
- | { | + | |
- | this-> | + | |
- | } | + | |
- | + | ||
- | int Node:: | + | |
- | { | + | |
- | return(this-> | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Now we decided to make some directories so within lab46 prompt we run the following commands: | + | |
- | < | + | |
- | to make a directory called " | + | |
- | + | ||
- | < | + | |
- | to move node.h into node directory.\\ | + | |
- | + | ||
- | < | + | |
- | to move create.cc into node directory.\\ | + | |
- | + | ||
- | < | + | |
- | to move value.cc into node directory.\\ | + | |
- | + | ||
- | < | + | |
- | to change into the node directory.\\ | + | |
- | + | ||
- | Now we are creating object files from a couple of these source files, create.cc and value.cc with:\\ | + | |
- | < | + | |
- | and:\\ | + | |
- | < | + | |
- | and now if you look in the directory with ls:\\ | + | |
- | < | + | |
- | you can see the create.o and value.o object files.\\ | + | |
- | + | ||
- | Now we are going to create a static library which is classified as the older, " | + | |
- | A static library is really just an archive.\\ | + | |
- | + | ||
- | Now we create this archive by running: | + | |
- | < | + | |
- | we can see with ls:\\ | + | |
- | < | + | |
- | That we now have a library file called libnode.a in the directory.\\ | + | |
- | + | ||
- | <WRAP tip>We can extract the object files back out of the archived library file with < | + | |
- | + | ||
- | Now we are going to make a new directory called " | + | |
- | < | + | |
- | (gets out of node directory into parent directory)\\ | + | |
- | < | + | |
- | creates directory called " | + | |
- | < | + | |
- | changes into previous argument of last command, which in this case is the same as:\\ | + | |
- | < | + | |
- | + | ||
- | Now we have a new header file called, **SinglyLinkedNode.h**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * SinglyLinkedNode.h - another file for something | + | |
- | * | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #ifndef _SINGLY_H | + | |
- | #define _SINGLY_H | + | |
- | #include " | + | |
- | + | ||
- | class SinglyLinkedNode: | + | |
- | public: | + | |
- | SinglyLinkedNode(); | + | |
- | SinglyLinkedNode(int); | + | |
- | SinglyLinkedNode *getNext(); | + | |
- | void setNext(SinglyLinkedNode *); | + | |
- | private: | + | |
- | SinglyLinkedNode *next; | + | |
- | }; | + | |
- | #endif | + | |
- | </ | + | |
- | + | ||
- | Next file, Another, DIFFERENT, **create.cc**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * create.cc - another create.cc file for | + | |
- | | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #include " | + | |
- | + | ||
- | SinglyLinkedNode:: | + | |
- | { | + | |
- | this-> | + | |
- | this-> | + | |
- | } | + | |
- | + | ||
- | SinglyLinkedNode:: | + | |
- | { | + | |
- | this-> | + | |
- | this-> | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | last file, **next.cc**: | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * next.cc - another file for something | + | |
- | * | + | |
- | * | + | |
- | * *********************************************/ | + | |
- | + | ||
- | #include " | + | |
- | + | ||
- | SinglyLinkedNode * SinglyLinkedNode:: | + | |
- | { | + | |
- | return(this-> | + | |
- | } | + | |
- | + | ||
- | void SinglyLinkedNode:: | + | |
- | { | + | |
- | this-> | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Now we are creating object files again with these new files, create.cc (the new one) and nect.cc: | + | |
- | < | + | |
- | < | + | |
- | + | ||
- | which should create the two objecty files, create.o and next.o\\ | + | |
- | Actually these may fail because node.h is now in a new location.\\ | + | |
- | + | ||
- | So to follow the same error we all did in class we create a new directory, up one level with:\\ | + | |
- | < | + | |
- | creates a directory called " | + | |
- | < | + | |
- | moves the SinglyLinkedNode.h header file to the inc directory in the parent directory.\\ | + | |
- | < | + | |
- | moves the node.h header file in the node directory int he parent directory into the inc direcotry int he parent directory.\\ | + | |
- | < | + | |
- | shoudl show cirrent contents of ../inc which shoudl now include the two header files, SinglyLinkedNode.h and node.h.\\ | + | |
- | + | ||
- | Now we can reattempt to create the object files with:\\ | + | |
- | < | + | |
- | and then:\\ | + | |
- | < | + | |
- | + | ||
- | Now if we check the current directory with ls:\\ | + | |
- | < | + | |
- | It shoudl show the 2 object files, create.o and next.o\\ | + | |
- | + | ||
- | Last step (for today, we are actually plannign on building on this for Thursday 11/13/2014) is to archive these object files into a library archive called libSinglyLinkedNode.a with:\\ | + | |
- | < | + | |
- | and ls should show this file:\\ | + | |
- | < | + | |
- | should see libSinglyLinkedNode.a\\ | + | |
- | + | ||
- | <WRAP info> | + | |
- | + | ||
- | **AUTHOR: Matthew Page**\\ | + | |
- | **DESIGNER: Dan Shadeck**\\ | + | |
- | + | ||
- | ====11/ | + | |
- | + | ||
- | **Nodes**\\ | + | |
- | *By itself a node is useless.\\ | + | |
- | *Large companies have organizational units.\\\ | + | |
- | *productively useless, but organizationally valuable.\\ | + | |
- | + | ||
- | SinglyLinkedNode inherits node.\\ | + | |
- | + | ||
- | {{http:// | + | |
- | + | ||
- | A list of singly linked nodes or a singly linked list.\\ | + | |
- | + | ||
- | To access the the 3rd node we would go:\\ | + | |
- | a-> | + | |
- | + | ||
- | The beauty is that you do not need to know how many nodes you need until runtime.\\ | + | |
- | this is dynamic programming.\\ | + | |
- | the notion of fixed position like we have with arrays, we don;t have with this.\\ | + | |
- | + | ||
- | Doubly Linked List - a pointer to next and previous nodes.\\ | + | |
- | + | ||
- | {{http:// | + | |
- | Appending/ | + | |
- | + | ||
- | This is like holding balloons you have to change things in such a way that you don;t lose connection to them.\\ | + | |
- | + | ||
- | The code from class today, " | + | |
- | <code c 1> | + | |
- | / | + | |
- | * | + | |
- | * Matthew Page | + | |
- | * | + | |
- | * 11/ | + | |
- | * CSCS 1320 | + | |
- | * | + | |
- | * nodefun.cc - A file for main function, | + | |
- | | + | |
- | | + | |
- | * | + | |
- | | + | |
- | + | ||
- | #include < | + | |
- | #include " | + | |
- | + | ||
- | int main() | + | |
- | { | + | |
- | int i; | + | |
- | SinglyLinkedNode *start=NULL; | + | |
- | SinglyLinkedNode *tmp=NULL; | + | |
- | SinglyLinkedNode *tmp2=NULL; | + | |
- | + | ||
- | //setting up List of Singly Linked Nodes | + | |
- | start=new SinglyLinkedNode(7); | + | |
- | start-> | + | |
- | tmp=start-> | + | |
- | + | ||
- | //inserting a new node | + | |
- | tmp2=new SinglyLinkedNode(73); | + | |
- | tmp2-> | + | |
- | start-> | + | |
- | + | ||
- | //setting tmp to point to starting node | + | |
- | tmp=start; | + | |
- | + | ||
- | //print out our list with a loop | + | |
- | while (tmp!=NULL) | + | |
- | { | + | |
- | printf(" | + | |
- | tmp=tmp-> | + | |
- | } | + | |
- | printf(" | + | |
- | return (0); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | {{http:// | + | |
- | + | ||
- | A List of Singly Linked Nodes (one dimensional) is different from a Singly Linked List of Singly Linked Nodes (two dimensional).\\ | + | |
- | + | ||
- | {{http:// | + | |
- | + | ||
- | we compile todays code in conjunction with last class' | + | |
- | < | + | |
- | + | ||
- | **AUTHOR & DESIGNER: Matthew Page**\\ | + | |
- | **REVIEWER: | + |
notes/cprog.1416169539.txt.gz · Last modified: 2014/11/16 15:25 by mp010784