bg287

csc 201 Final Review

Posted in csc201 by bnmng on 2010 12/06

Remember the old stuff.
Nothing on linked lists. 14.1 and 14.2 only.
Remember arithmatic.
Remember if doing arithmetic with mixed types, the stronger type prevails.
If doing math with chars, you loose the char aspect. You hgave to cast it back in. ch=’A’;
Know the ignore command. cin.ignore(100,\n) ignores 100 chars or endl whichever first.
Difference between Extraction operator and .get. >> skips whitespaces (spaces, tabs, and newlines).
String Functions: Know the string library.
+ operator becomes the concatinate operator. Size indicates the size of the string. Substring operator.
subst always yields a string. at always yields a character.
using files: need to use fstream.
A program using files needs file handles, need to open files, in place of cin and cout, name of file stream.
Comparing strings: Lexicographical comparisons.
Lexicographical doesn’t work on cstrings. Wasn’t clear about that in chapter 3.
looping. Think about the parts of the loop. What they do, how they terminate.
Event control loops: Sentianl, EOF, and flag controled.
In sentinals and EOF, priming read.
while (data1) // Tests for EOF, tests for valid input and tests for file open.
Nesting of loops.
Functions.
Basic procedures (which use void)
call by value //Can pass a constant, or an expression, or a variable, or a coercable variable
call by reference //Can only pass the right type of variable
Procedures yield values by a called by reference variable.
Value yielding functions: return values with the return statement.
Scope: If a name is the same in an inner scope and outer scope.
Scope applies to formal arguments.
Local variables are created when a function is called.
Static to retain value. Statics are created at the first call.
User defined tyypes.
Typedef
Enumeration: Can’t read or write an enumeration type.
Remember when you have to cast to assign a value of an enumerator
Structs: Allows to block dissimilar types together.
Structs: Aggregate assignment; Call by value; call by reference
Arrays:
If we have an array of structs, remember the format for the name: ie mylist[3].member
Classes: abstract data types
Know the concept of data hiding
Class functrions: Constructor, observer, destructor, iterator, transforers
Observer functions are identifyable with the word const.
Selection Sort
Not responsible for binary search
Pointers.
Dangling Reference; Memory Leak; Innaccessible Object

Advertisements

Posted in csc201 by bnmng on 2010 11/29

Homework passed out
Chapter 14(14.4 to 14.8 Linked List)
Examp Prep 22, 27 & 28
Warmup 13 & 14.
for question 13, assume the list has been established with at least 9 or 19 nodes, and that currptr points somewhere in the middle. Also, head points to the first node on the list. For part a, the “first list elemetn is the one pointed to by currptr, not head.
for question 14 Use the data definitions given for 13, but assume that the list is empty to start with. (otherwise the code asked for would result in a memory lead).

Link Lists.

csc 201 20101122 Notes

Posted in csc201 by bnmng on 2010 11/22

Program 4 is due during the final.
Final is Wed December 8th.
There will be a lab December 1st.
Homework assignment due Monday.
Homework reading: Chapter 14.4 – 14.8 Keeping in mind the objectives which where passed out in class.

Example using “friend”.
//Using a member function
list3=list1.merglists(list2)
//Using friend
frind Public.Section
list3=mergelists(list1,list2)

csc 201 20101117 Notes

Posted in csc201 by bnmng on 2010 11/17

Read 14.2 and 14.3
Today: Going over Test 3
Pointers
Pointer variables
Pointer

Wed: No attendance. Mr. Sterling will be available.

A pointr is a variable whose vaue is the address of a location in memory.
int* ptr; //ptr will wild the address of an int.

int x;
x=12;

int* ptr;
ptr = &x;

x = 12, ptr = the address of x (maybe 2000 or something),

cout << *ptr; //prints 12, the value of the contents at the memory of x.

*ptr = 5; // changes the value at the address ptr to 5;

char msg[] = "Hello";

char* ptr;
ptr=msg; //Don't need an & because an array is already an address

*ptr='M'; Changes the H in Hello to M.
ptr++; //increments the address
*ptr='a'; Changes the e in Mello to an a.

int StringLength(/* in */ const char str[]);
//Precondition: str is a null nterminated string
//postcondition: Return value==length of str
// (not counting '')
{ char *p;
int count =0;
p = str;
while (*p!='')
{
count++;
p++;
//Increments the address p by sizeof char
}
return count;
}

int * p1, p2 //Doesn’t declare two pointers. p1 is a pointer and p2 is an int.

int *p1 *p2 //Declares two pointers.

typedef int * inttype
inttype p1, p2 //Declares two pointers.

//A struct
patient
idnum: 1737
height: 65
weight: 137.

say patptr is a pointer to the struct named patient.
(*patptr).height //Two ways to access patients height.
patptr->height

csc201 20101110 Notes

Posted in csc201 by bnmng on 2010 11/10

Probably one more program due for rest of class.
Test Monday.
Reading for Wednesday: Read 14.1

The following items will probably be on the test.
Brute force search: Two versions.
If the list is unsorted, assuming it doesn’t find the sought value, than it will go through the whole list.
If the list is sorted, than even if it doesn’t find the value, it can stop looking when the value is exceeded.
(either way, if it does find it’s value, it can stop going through the list when it finds it).

Remember the five types of functions in a class:
Constructors
Transformers
Observers
Iterators
Destructors

By default, members of a class are private. Public functions have to be defined in a public section.

Inside the class, private and public functions and variables are available.
Outside the class only public functions and variables are available (and we rarely define public variables).

.h files have the specification and documentation of classes.
.cpp files have the implementation
the main brings them together

We have constructors that take arguments and default constructors that don’t take arguments.
We need the defaults for arrays. You cannot pass parameters to an array when creating it.

Understand the selection sort. Understand what happens in the inner loop.
There will likely be a question like this:
5 89 4 27 99 15 87 77 34
What will this look like after three passes of a selection sort?
Answer
Pass 1 (finds the 4, swaps it with the 5)
4 89 5 27 99 15 87 77 34
Pass 2 (finds the 5, swaps it with the 89)
4 5 89 27 99 15 87 77 34
Pass 3 (finds the 15, swaps it with the 89)
4 5 15 27 99 89 87 77 34

csc201 20101108 Notes

Posted in csc201 by bnmng on 2010 11/08

Program Due Monday the 15th.
Homework due Wednesday the 10th:
Chapter 13 Exam Prep 3, 6, 7. Warmup 1, 6, 7, 11

Test Monday the 15th. For Test: Make sure you understand brute force search (sequential search). Make sure you understand selection sort.

Sorting and Brute Force Searching (from Chapter 13):
A Selection Sort is an In Place Sort
Example
0 87
1 62
2 92
3 80
4 29
5 62

find the index of minumum. Start with Min Index of zero. Go through each number. If you find a number lower than then one in position zero, make the new mnin index the index of that number.
Swap the lowest number with the one in index zero.
Do the same for each iter of the outer loop, but start with a higher index.

In doing an insert to an ordered list, start at the high index. If the value of item with the highest index is lower than the new value, put the new value at the end. If the value of the item with the highest index is higher than the new value, copy the value of the item with the highest index to the new end. Then check the next lower item. Again, if it’s higher than the new value, copy it up. If not, put the new value into the spot above that one.

Test Topics :Selection Sort (what does the array look like after a certain # of passes)
Brute Force Search

csc201 20101027Notes

Posted in csc201 by bnmng on 2010 10/27

Homework Read 13.1 to 13.3

Today:
Program 3
Chapter 12
Abstract Data Types
Classes
Specifications
Implementations

Need constant or constant expression to indicate size of array.

const int SECTOR_SIZE = 512;
int Buffer [2*SECTOR_SIZE];

In c++ There is no range check on arrays. If you exceed the array’s limits, it will screw things up but you won’t necessarily get an erro.

Arrays are passed by reference. Do not use the ampersand. The ampersand is implied.

Row wise processing is better than column-wise processing due to caching.

Passing 2 dim arrays: Must have all but first array dimention in squares.

csc201 20101025 Notes

Posted in csc201 by bnmng on 2010 10/25

Homework
Chapter 11 Arrays
Exam Prep 7,11,14,15,17,21
Programming Warmup
1,7,8
Read 12 to page 606. Arrays of Structs, 2D arrays, Declarations, arrays as arguments, processing
Also see chapter 8 in Bronson for examples of run-time initialization.

Number of buildings example


2 dimensional arrays

compiler will not trap an out of bounds index.

example
Typedef char nametyhpe[21]
nanetype namelist[50]
namelist [5][16]

csc201 20101020 Notes

Posted in csc201 by bnmng on 2010 10/20

Homework: Read 11.2 to 11.8
Go over test 2
11.1 Arrays
Declarations
indexes

csc201 20101006 Notes

Posted in csc201 by bnmng on 2010 10/06

Homework Monday;
Lab Wed
Program due 18th;