ECS 40 Spring 2015 Discussion Notes
ECS 40 Spring 2015 Discussion Notes ECS 40
Popular in Software and Object Orient Programming
Popular in ComputerScienence
This 11 page Study Guide was uploaded by Annalisa Yoakum on Saturday September 26, 2015. The Study Guide belongs to ECS 40 at University of California - Davis taught by Sean Davis in Spring 2015. Since its upload, it has received 26 views. For similar materials see Software and Object Orient Programming in ComputerScienence at University of California - Davis.
Reviews for ECS 40 Spring 2015 Discussion Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/26/15
ECS 40 DISCUSSION NOTES 3 April 2015 STRUCTS typedef struct student char name10 int age double gpa char gender name of struct to reference back typedef struct student Student also known as typedef struct student Student Student s1 Student s10 student sss Declaration struct student s1 s2 s3 struct student is the TYPE s1 s2 s3 are VARIABLES like int car struct student slO array of student so for each num in array it Will have these attributes struct stundet ss pointer DYNAMIC ALLOCATION include ltstdlibhgt Use malloc in C so ptr casttype malloc memorysize Remember to free at the end to prevent memory leaks If you want to resize do malloc free and call again int grade grade int malloc 4 sizeofint free grade Student ss ss Student malloc i sizeofStudent i is the number of students freess Access this by ssname ss gtname ssl ss 1 If there are two numbers in the struct allocate memory space for both typedef struct Twonum Twonum malloc 2 sizeof 2 memory blocks for each MAKEFILE 2 stages compilation and linking source file ccp gt object fileo gt bin exe o o obj An object file contains a machine code table of functions provided and their location within the machine code table of functions needed and the location of the calls in the machine code A makefile is a plaintext Helps to organize compiling and linking to implement the build system Called by make It allows to separate compilations and describes the dependencies structure Makefile example all hello optional line this is the executable to make hello maino factorialo helloo g maino factorialo helloo o hello maino maincpp g c maincpp factorialo factorialcpp g c factorialcpp helloo hellocpp g c hellocpp clean rm maino factorialo helloo hello Three ways to call makefile make make f myMakefile myMakefile is the new creative name for the makefile make clean 24 April 2015 typedef struct int zipCode char name City void CreateCityCity city int zip const char cityName int getZipCodeconst City city int main City city CreateCityampcity 95616 Davis cout ltlt getZipCodeampcity return 0 Practice CHECK PIAZZA Rewrite City and the two functions as a class definition with two public methods that would appear in cityh Provide the robust implementation code for the standard constructor for City Provide V V CITYH class City int zipCode char name public constructors City default constructor Cityint char standard constructor CityCity c copy constructor City destructor void CreateCityCity city int zip const char cityName int getZipCodeconst City city public private by default the variables inside the class are private need to use one of these protected CITYCPP include cityh CityCity zipCodeO nameNULL Use initializer list instead of this V but you can do this zipcodeO name NULL CityCityint zipcode char name zipCodezipCode zipcode zipCode name new charstrlenname 1 name strcpy name name City Cityconst City c this gtzipCode c gtzipCode name new charstrlenc gtname strcpy name c gtname City City destroy object delete name delete name is the space was an array void CityCreateCityCity city int zip const char cityName do something sets the zip and name int City getZipCode do something retums the zipCode of the city void main City yourCity956l6 Davis City myCityyourCity delete yourCity yourCity City anotherCity for int i O i lt 10 i City neWCity anotherCity gtgetZipcode neWCity anotherCity myCity 1 May 2015 Overloading Operator for struct temp i cityArrayi class temp i cityArray i overloaded shadow copy 7 deep copy 2 City amp Cityoperatorconst City amprhs if amprhs this return this return this int a b Want this to happen void assignint ampa int b a b return class a int val void assignint b Vdb a assignb class Person int age string name void assign int inAge string inName age inAge name inName Example int a int b 3 int c 2 a b 0 cout ltlt a ltlt b ltlt c endl The output would be 2 3 2 8 May 2015 Linked List Quiz Write a ListNode class that Will hold Person as its data and is used in a class named List Include a constructor and destructor for the Person class ListNode Person person ListNode next friend class List friend function public ListNodeconst Person p ListNode n constructor ListNode ListNodeListNode const Person p ListNode n person new Person p next n or you can put nextn after the parameters ListNode ListNode delete person class List ListNode head public Isist List void insert Person p void deletePerson p int findPerson p return 1 found return 0 not found void destroy bool isEmpty check to see if the list is empty return head NULL printAll 2 Write a printAll method for the List class that relies on an overload ltlt method for Person to print the contents of the list void List printAll ListNode ptr head for ptr head ptr ptr ptr gtnext cout ltlt ptr gtperson Assuming that the Person class has a public getName method write an insert method for the List class that keeps the list sorted by the names of the Persons void Listinsert const Person p ListNode ptr prev NULL ListNode cur new ListNode p NULL for ptr head ptr ampamp strcmpptr gtperson getName p gtperson gtgetName lt O ptr ptr gtnext prev ptr if prev NULL head cur cur gtnext ptr else prev gtnext cur cur gtnext ptr 15 May 2015 Type of Inheritance Private Protected Public Private Protected Private Protected Protected Public Private Protected Public AAA Access Control for Members The type of inheritance defines the access level for the members of derived class that are inherited from the base class
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'