Παλεπηζηήκην Παηξώλ ΟΝΣΟΚΕΝΣΡΙΚΟ ΠΡΟΓΡΑΜΜΑΣΙΜΟ ΙΙ (C++) Σάξειρ και Αθαίπεζη Δεδομένων. Σμήμα Μηχανικών Ηλεκηπονικών Τπολογιζηών και Πληποθοπικήρ
|
|
- Κῆρες Ζωγράφος
- 8 χρόνια πριν
- Προβολές:
Transcript
1 Παλεπηζηήκην Παηξώλ Σμήμα Μηχανικών Ηλεκηπονικών Τπολογιζηών και Πληποθοπικήρ ΟΝΣΟΚΕΝΣΡΙΚΟ ΠΡΟΓΡΑΜΜΑΣΙΜΟ ΙΙ (C++) Σάξειρ και Αθαίπεζη Δεδομένων 1
2 Τάμεηο Μέξνο ΙΙ 7.1 Ειζαγυγή 7.2 const Ανηικείμενα και const Σςναπηήζειρ 7.3 Σύνθεζη: Ανηικείμενα υρ μέλη ηάξηρ 7.4 friend Σςναπηήζειρ και ηάξειρ 7.5 Ο Δείκηηρ this 7.6 Δςναμική Διασείπιζη Μνήμηρ με ηοςρ ηελεζηέρ new και delete 7.7 static Μέλη ηάξηρ 7.8 Αθαίπεζη δεδομένυν και Απόκπςτη πληποθοπίαρ Παπάδειγμα: Array Abstract Data Type Παπάδειγμα: String Abstract Data Type 7.9 Εμπεπιέσοςζερ ηάξειρ και επαναλήπηερ 7.10 Proxy ηάξειρ 2
3 Δηζαγσγή Τάμεηο Αθαίξεζε Γεδνκέλσλ Αληηθεηκελνζηξαθήο πξνγξακκαηηζκόο Κιεξνλνκηθόηεηα θαη πνιπκνξθηζκόο 3
4 7.2 const (Σηαζεξά) Αληηθείκελα θαη Μέζνδνη Η αξρή ηεο ειάρηζηεο πξόζβαζεο Δπηηξέπνπκε πξόζβαζε γηα ηξνπνπνηήζεηο κόλν ζηα απαξαίηεηα αληηθείκελα const Οξίδεη αληηθείκελν πνπ δε ηξνπνπνηείηαη Γίλεη Compiler error Παξάδεηγκα const Time noon( 12, 0, 0 ); Γειώλεη const αληηθείκελν noon ηεο Time Αξρηθνπνηεί ζε 12 4
5 7.2 const (Σηαζεξά) Αληηθείκελα θαη Μέζνδνη const κέζνδνη Οη κέζνδνη αληηθεηκέλσλ const πξέπεη λα είλαη θαη απηέο const Γε κπνξεί λα ηξνπνπνηνύλ αληηθείκελα Οξίδνπκε σο const ζε Πξσηόηππν Μεηά ηε ιίζηα παξακέηξσλ Γειώζεηο Πξηλ ηελ αξρή ηνπ αξηζηεξνύ αγθίζηξνπ 5
6 1 // Fig. 7.1: time5.h 2 // Definition of class Time. 3 // Member functions defined in time5.cpp. 4 #ifndef TIME5_H 5 #define TIME5_H 6 7 class Time { 8 9 public: 10 Time( int = 0, int = 0, int = 0 ); // default constructor // set functions 13 void settime( int, int, int ); // set time 14 void sethour( int ); // set hour 15 void setminute( int ); // set minute 16 void setsecond( int ); // set second // get functions (normally declared const) 19 int gethour() const; // return hour 20 int getminute() const; // return minute 21 int getsecond() const; // return second // print functions (normally declared const) 24 void printuniversal() const; // print universal time 25 void printstandard(); // print standard time time5.h (1 of 2) Declare const get functions. Declare const function printuniversal. 6 Reproduced from the PowerPoints for C++ How to Program, 4/e by Deitel and Deitel Reproduced All rights by reserved.
7 26 27 private: 28 int hour; // 0-23 (24-hour clock format) 29 int minute; // int second; // }; // end class Time #endif time5.h (2 of 2) 7
8 1 // Fig. 7.2: time5.cpp 2 // Member-function definitions for class Time. 3 #include <iostream> 4 5 using std::cout; 6 7 #include <iomanip> 8 9 using std::setfill; 10 using std::setw; // include definition of class Time from time5.h 13 #include "time5.h" // constructor function to initialize private data; 16 // calls member function settime to set variables; 17 // default values are 0 (see class definition) 18 Time::Time( int hour, int minute, int second ) 19 { 20 settime( hour, minute, second ); } // end Time constructor 23 time5.cpp (1 of 4) 8
9 24 // set hour, minute and second values 25 void Time::setTime( int hour, int minute, int second ) 26 { 27 sethour( hour ); 28 setminute( minute ); 29 setsecond( second ); } // end function settime // set hour value 34 void Time::setHour( int h ) 35 { 36 hour = ( h >= 0 && h < 24 )? h : 0; } // end function sethour // set minute value 41 void Time::setMinute( int m ) 42 { 43 minute = ( m >= 0 && m < 60 )? m : 0; } // end function setminute 46 time5.cpp (2 of 4) 9
10 47 // set second value 48 void Time::setSecond( int s ) 49 { 50 second = ( s >= 0 && s < 60 )? s : 0; } // end function setsecond // return hour value 55 int Time::getHour() const 56 { 57 return hour; } // end function gethour // return minute value 62 int Time::getMinute() const 63 { 64 return minute; } // end function getminute 67 const functions do not modify objects. time5.cpp (3 of 4) 10
11 68 // return second value 69 int Time::getSecond() const 70 { 71 return second; } // end function getsecond // print Time in universal format 76 void Time::printUniversal() const 77 { 78 cout << setfill( '0' ) << setw( 2 ) << hour << ":" 79 << setw( 2 ) << minute << ":" 80 << setw( 2 ) << second; } // end function printuniversal // print Time in standard format 85 void Time::printStandard() // note lack of const declaration 86 { 87 cout << ( ( hour == 0 hour == 12 )? 12 : hour % 12 ) 88 << ":" << setfill( '0' ) << setw( 2 ) << minute 89 << ":" << setw( 2 ) << second 90 << ( hour < 12? " AM" : " PM" ); } // end function printstandard const functions do not modify objects. time5.cpp (4 of 4) 11
12 1 // Fig. 7.3: fig07_03.cpp 2 // Attempting to access a const object with 3 // non-const member functions. 4 5 // include Time class definition from time5.h 6 #include "time5.h" 7 8 int main() 9 { object. 10 Time wakeup( 6, 45, 0 ); // non-constant object 11 const Time noon( 12, 0, 0 ); // constant object 12 Note that non-const constructor can initialize const object. Declare noon a const fig07_03.cpp (1 of 2) 12
13 13 // OBJECT MEMBER FUNCTION 14 wakeup.sethour( 18 ); // non-const non-const noon.sethour( 12 ); // const non-const wakeup.gethour(); // non-const const noon.getminute(); // const const 21 noon.printuniversal(); // const const noon.printstandard(); // const non-const return 0; } // end main Attempting to invoke nonconst member function on const object results in compiler error. Attempting to invoke nonconst member function on const object results in d:\cpphtp4_examples\ch07\fig07_01\fig07_01.cpp(16) : error C2662: 'sethour' : cannot convert 'this' pointer from 'const class Time' to 'class Time &' Conversion loses qualifiers compiler error even if function does not modify object. d:\cpphtp4_examples\ch07\fig07_01\fig07_01.cpp(23) : error C2662: 'printstandard' : cannot convert 'this' pointer from 'const class Time' to 'class Time &' Conversion loses qualifiers fig07_03.cpp (2 of 2) fig07_03.cpp output (1 of 1) 13
14 7.2 const (Σηαζεξά) Αληηθείκελα θαη Μέζνδνη Αξρηθνπνίεζε αληηθεηκέλνπ Αξρηθνπνίεζε κε member initializer syntax Μπνξεί λα ρξεζηκνπνηεζεί Με όια ηα κέιε δεδνκέλσλ Πξέπεη λα ρξεζηκνπνηεζεί Για τα μέλη const Γηα όιεο ηηο αλαθνξέο κεηαβιεηώλ 14
15 1 // Fig. 7.4: fig07_04.cpp 2 // Using a member initializer to initialize a 3 // constant of a built-in data type. 4 #include <iostream> 5 6 using std::cout; 7 using std::endl; 8 9 class Increment { public: 12 Increment( int c = 0, int i = 1 ); // default constructor void addincrement() 15 { 16 count += increment; } // end function addincrement void print() const; // prints count and increment 21 fig07_04.cpp (1 of 3) 15
16 22 private: 23 int count; 24 const int increment; // const data member }; // end class Increment // constructor separated from Member parameter initializer data list member. syntax can 29 Increment::Increment( by int colon. c, int be used i ) Member for non-const initializer syntax data 30 : count( c ), // initializer for non-const member member 31 increment( i ) // required initializer must count. be used for for const const member data 32 { member increment. 33 // empty body } // end Increment constructor // print count and increment values 38 void Increment::print() const 39 { 40 cout << "count = " << count 41 << ", increment = " << increment << endl; } // end function print 44 Member initializer list Declare increment as const Member initializer consists of data member name (increment) followed by parentheses containing initial value (c). fig07_04.cpp (2 of 3) 16
17 45 int main() 46 { 47 Increment value( 10, 5 ); cout << "Before incrementing: "; 50 value.print(); for ( int j = 0; j < 3; j++ ) { 53 value.addincrement(); 54 cout << "After increment " << j + 1 << ": "; 55 value.print(); 56 } return 0; } // end main fig07_04.cpp (3 of 3) fig07_04.cpp output (1 of 1) 17 Before incrementing: count = 10, increment = 5 After increment 1: count = 15, increment = 5 After increment 2: count = 20, increment = 5 After increment 3: count = 25, increment = 5
18 1 // Fig. 7.5: fig07_05.cpp 2 // Attempting to initialize a constant of 3 // a built-in data type with an assignment. 4 #include <iostream> 5 6 using std::cout; 7 using std::endl; 8 9 class Increment { public: 12 Increment( int c = 0, int i = 1 ); // default constructor void addincrement() 15 { 16 count += increment; } // end function addincrement void print() const; // prints count and increment 21 fig07_05.cpp (1 of 3) 18
19 22 private: 23 int count; 24 const int increment; // const data member }; // end class Increment // constructor 29 Increment::Increment( int c, int i ) 30 { // Constant member 'increment' is not initialized 31 count = c; // allowed because results count in error. is not constant 32 increment = i; // ERROR: Cannot modify a const object } // end Increment constructor // print count and increment values 37 void Increment::print() const 38 { 39 cout << "count = " << count 40 << ", increment = " << increment << endl; } // end function print 43 Declare increment as const data member. Attempting to modify const data member increment fig07_05.cpp (2 of 3) 19
20 44 int main() 45 { 46 Increment value( 10, 5 ); cout << "Before incrementing: "; 49 value.print(); for ( int j = 0; j < 3; j++ ) { 52 value.addincrement(); 53 cout << "After increment " << j + 1 << ": "; 54 value.print(); 55 } return 0; } // end main Not using member initializer syntax to initialize const data member increment results in error. D:\cpphtp4_examples\ch07\Fig07_03\Fig07_03.cpp(30) : error C2758: 'increment' : must be initialized in constructor base/member initializer list D:\cpphtp4_examples\ch07\Fig07_03\Fig07_03.cpp(24) : see declaration of 'increment' D:\cpphtp4_examples\ch07\Fig07_03\Fig07_03.cpp(32) : error C2166: l-value specifies const object fig07_05.cpp (3 of 3) fig07_05.cpp output (1 of 1) Attempting to modify const data member increment results in error. 20
21 7.3 Σύλζεζε/ Composition: Αληηθείκελα σο κέιε ηάμεο Σύλζεζε/ Composition Μία ηάμε έρεη αληηθείκελα άιιεο ηάμεο σο κέιε Καηαζθεπή αληηθεηκέλσλ Τα κέιε αληηθείκελα δεκηνπξγνύληαη κε ηε ζεηξά πνπ δειώλνληαη Γελ αθνινπζείηε ε ζεηξά ηνπ constructor Γεκηνπξγνύληαη πξηλ από ηα αληηθείκελα ηεο ηάμεο πνπ ηα ρξεζηκνπνηεί 21
22 1 // Fig. 7.6: date1.h 2 // Date class definition. 3 // Member functions defined in date1.cpp 4 #ifndef DATE1_H 5 #define DATE1_H 6 7 class Date { 8 9 public: 10 Date( int = 1, int = 1, int = 1900 ); // default constructor 11 void print() const; // print date default in month/day/year copy constructor. format 12 ~Date(); // provided to confirm destruction order private: 15 int month; // 1-12 (January-December) 16 int day; // 1-31 based on month 17 int year; // any year // utility function to test proper day for month and year 20 int checkday( int ) const; }; // end class Date #endif Note no constructor with parameter of type Date. Recall compiler provides date1.h (1 of 1) 22
23 1 // Fig. 7.7: date1.cpp 2 // Member-function definitions for class Date. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 // include Date class definition from date1.h 9 #include "date1.h" // constructor confirms proper value for month; calls 12 // utility function checkday to confirm proper value for day 13 Date::Date( int mn, int dy, int yr ) 14 { 15 if ( mn > 0 && mn <= 12 ) // validate the month 16 month = mn; else { // invalid month set to 1 19 month = 1; 20 cout << "Month " << mn << " invalid. Set to month 1.\n"; 21 } year = yr; // should validate yr 24 day = checkday( dy ); // validate the day 25 date1.cpp (1 of 3) 23
24 26 // output Date object to show when its constructor is called 27 cout << "Date object constructor for date "; 28 print(); 29 cout << endl; } // end Date constructor // print Date object in form month/day/year 34 void Date::print() const operates. 35 { 36 cout << month << '/' << day << '/' << year; } // end function print // output Date object to show when its destructor is called 41 Date::~Date() destructors. 42 { 43 cout << "Date object destructor for date "; 44 print(); 45 cout << endl; } // end destructor ~Date 48 No arguments; each member function Output contains to show implicit timing of handle constructors. to object on which it Output to show timing of date1.cpp (2 of 3) 24
25 49 // utility function to confirm proper day value based on 50 // month and year; handles leap years, too 51 int Date::checkDay( int testday ) const 52 { 53 static const int dayspermonth[ 13 ] = 54 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // determine whether testday is valid for specified month 57 if ( testday > 0 && testday <= dayspermonth[ month ] ) 58 return testday; // February 29 check for leap year 61 if ( month == 2 && testday == 29 && 62 ( year % 400 == 0 63 ( year % 4 == 0 && year % 100!= 0 ) ) ) 64 return testday; cout << "Day " << testday << " invalid. Set to day 1.\n"; return 1; // leave object in consistent state if bad value } // end function checkday date1.cpp (3 of 3) 25
26 1 // Fig. 7.8: employee1.h 2 // Employee class definition. 3 // Member functions defined in employee1.cpp. 4 #ifndef EMPLOYEE1_H 5 #define EMPLOYEE1_H 6 7 // include Date class definition from date1.h 8 #include "date1.h" 9 10 class Employee { public: 13 Employee( 14 const char *, const char *, const Date &, const Date & ); void print() const; 17 ~Employee(); // provided to confirm destruction order private: 20 char firstname[ 25 ]; 21 char lastname[ 25 ]; 22 const Date birthdate; // composition: member object 23 const Date hiredate; // composition: member object }; // end class Employee employee1.h (1 of 2) Using composition; Employee object contains Date objects as data members. 26
27 26 27 #endif 27 employee1.h (2 of 2) 1 // Fig. 7.9: employee1.cpp 2 // Member-function definitions for class Employee. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include <cstring> // strcpy and strlen prototypes 9 10 #include "employee1.h" // Employee class definition 11 #include "date1.h" // Date class definition 12 employee1.cpp (1 of 3)
28 13 // constructor uses member initializer list to pass initializer 14 // values to constructors of member objects birthdate and 15 // hiredate [Note: This invokes the so-called "default copy 16 // constructor" which the C++ compiler provides implicitly.] 17 Employee::Employee( const char *first, const char *last, 18 const Date &dateofbirth, const Date &dateofhire ) 19 : birthdate( dateofbirth ), // initialize birthdate 20 hiredate( dateofhire ) // initialize hiredate 21 { 22 // copy first into firstname and be sure that it fits 23 int length = strlen( first ); 24 length = ( length < 25? length : 24 ); 25 strncpy( firstname, first, length ); 26 firstname[ length ] = '\0'; // copy last into lastname and be sure that it fits 29 length = strlen( last ); 30 length = ( length < 25? length : 24 ); 31 strncpy( lastname, last, length ); 32 lastname[ length ] = '\0'; // output Employee object to show when constructor is called 35 cout << "Employee object constructor: " 36 << firstname << ' ' << lastname << endl; 37 Member initializer syntax to initialize Date data members birthdate and hiredate; compiler uses default copy constructor. Output to show timing of constructors. employee1.cpp (2 of 3) 28
29 38 } // end Employee constructor // print Employee object 41 void Employee::print() const 42 { 43 cout << lastname << ", " << firstname << "\nhired: "; 44 hiredate.print(); 45 cout << " Birth date: "; 46 birthdate.print(); 47 cout << endl; } // end function print // output Employee object to show when its destructor is called 52 Employee::~Employee() destructors. 53 { 54 cout << "Employee object destructor: " 55 << lastname << ", " << firstname << endl; } // end destructor ~Employee Output to show timing of employee1.cpp (3 of 3) 29
30 1 // Fig. 7.10: fig07_10.cpp 2 // Demonstrating composition--an object with member objects. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include "employee1.h" // Employee class definition 9 10 int main() 11 { 12 Date birth( 7, 24, 1949 ); 13 Date hire( 3, 12, 1988 ); 14 Employee manager( "Bob", "Jones", birth, hire ); cout << '\n'; 17 manager.print(); cout << "\ntest Date constructor with invalid values:\n"; 20 Date lastdayoff( 14, 35, 1994 ); // invalid month and day 21 cout << endl; return 0; } // end main Create Date objects to pass to Employee constructor. fig07_10.cpp (1 of 1) 30
31 Date object constructor for date 7/24/1949 Date object constructor for date 3/12/1988 Employee object constructor: Bob Jones Jones, Bob Hired: 3/12/1988 Birth date: 7/24/1949 Test Date constructor with invalid values: Month 14 invalid. Set to month 1. Day 35 invalid. Set to day 1. Date object constructor for date 1/1/1994 Date object destructor for date 1/1/1994 Employee object destructor: Jones, Bob Date object destructor for date 3/12/1988 Date object destructor for date 7/24/1949 Date object destructor for date 3/12/1988 Date object destructor for date 7/24/1949 Note two additional Datefig07_10.cpp objects constructed; no output output (1 of 1) since default copy constructor used. Destructor for host object manager Destructor runs for before Employee s member destructors Destructor object for for member Employee s hiredate. objects member Destructor hiredate object for birthdate. and object birthdate. hire. Destructor for Date object birth. 31
32 7.4 friend Σπλαξηήζεηο θαη and friend Τάμεηο friend ζπλαξηήζεηο Οξίδνληαη εθηόο εκβέιεηαο ηεο ηάμεο Έρνπλ πξόζβαζε ζε non-public members Γήισζε friends Σπλάξηεζε Πξνεγείηαη ην keyword friend Όιεο νη ζπλαξηήζεηο ηεο ηάμεο classtwo σο friends ηεο ηάμεο classone Βάδνπκε ηε δήισζε ηεο κνξθήο friend class classtwo; ζηνλ νξηζκό ηεο classone 32
33 7.4 friend Σπλαξηήζεηο θαη and Ιδηόηεηεο friend Τάμεηο Μπνξεί λα δνζεί όρη λα αλαθιεζεί ηάμε B friend ηεο ηάμεο A Η ηάμε A πξέπεη λα δειώζεη ηελ ηάμε B σο friend Όρη ζπκκεηξηθή ηάμε B friend ηεο ηάμεο A ηάμε A όρη απαξαίηεηα friend ηεο ηάμεο B Όρη κεηαβαηηθή ηάμε A friend ηεο B ηάμε B friend ηεο C ηάμε A όρη απαξαίηεηα friend ηεο C 33
34 1 // Fig. 7.11: fig07_11.cpp 2 // Friends can access private members of a class. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 // Count class definition 9 class Count { 10 friend void setx( Count &, int ); // friend declaration public: // constructor 15 Count() 16 : x( 0 ) // initialize x to 0 17 { 18 // empty body } // end Count constructor 21 Precede function prototype with keyword friend. fig07_11.cpp (1 of 3) 34
35 22 // output x 23 void print() const 24 { 25 cout << x << endl; } // end function print private: 30 int x; // data member }; // end class Count // function setx can modify private data of Count 35 // because setx is declared Since setx as a friendof of Count 36 void setx( Count &c, int Count, val ) can access and 37 { modify private data 38 c.x = val; // legal: member setx x. is a friend of Count } // end function setx 41 Pass Count object since C- style, standalone function. fig07_11.cpp (2 of 3) 35
36 42 int main() 43 { 44 Count counter; // create Count object cout << "counter.x after instantiation: "; 47 counter.print(); setx( counter, 8 ); // set x with a friend cout << "counter.x after call to setx friend function: "; 52 counter.print(); return 0; } // end main Use friend function to access and modify private data member x. fig07_11.cpp (3 of 3) fig07_11.cpp output (1 of 1) 36 counter.x after instantiation: 0 counter.x after call to setx friend function: 8
37 1 // Fig. 7.12: fig07_12.cpp 2 // Non-friend/non-member functions cannot access 3 // private data of a class. 4 #include <iostream> 5 6 using std::cout; 7 using std::endl; 8 9 // Count class definition 10 // (note that there is no friendship declaration) 11 class Count { public: // constructor 16 Count() 17 : x( 0 ) // initialize x to 0 18 { 19 // empty body } // end Count constructor 22 fig07_12.cpp (1 of 3) 37
38 23 // output x 24 void print() const 25 { 26 cout << x << endl; } // end function print private: 31 int x; // data member }; // end class Count // function tries to modify private data of Count, Attempting to modify 36 // but cannot because function is not a friend of Count private data member from 37 void cannotsetx( Count &c, int val ) non-friend function results 38 { 39 c.x = val; // ERROR: cannot in error. access private member in Count } // end function cannotsetx 42 fig07_12.cpp (2 of 3) 38
39 43 int main() 44 { 45 Count counter; // create Count object cannotsetx( counter, 3 ); // cannotsetx is not a friend return 0; } // end main fig07_12.cpp (3 of 3) fig07_12.cpp output (1 of 1) 39 D:\cpphtp4_examples\ch07\Fig07_12\Fig07_12.cpp(39) : error C2248: 'x' : cannot access private member declared in class 'Count' D:\cpphtp4_examples\ch07\Fig07_12\Fig07_12.cpp(31) : see declaration of 'x' Attempting to modify private data member from non-friend function results in error.
40 this 7.5 Φξήζε ηνπ this Δπηηξέπεη ζην αληηθείκελν λα έρεη πξόζβαζε ζηε δηθή ηνπ δηεύζπλζε Ο ηύπνο ηνπ δείθηε this εμαξηάηαη από: Τύπν ηνπ αληηθεηκέλνπ Αλ ε ζπλάξηεζε έηλαη const Γηα ηηο non-const ζπλαξηήζεηο Employee this έρεη ηύπν Employee * const Constant δείθηε ζε non-const Employee αληηθείκελν Γηα ηηο const ζπλαξηήζεηο Employee this έρεη ηύπν const Employee * const Constant δείθηε ζε constant Employee αληηθείκελν 40
41 1 // Fig. 7.13: fig07_13.cpp 2 // Using the this pointer to refer to object members. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 class Test { 9 10 public: 11 Test( int = 0 ); // default constructor 12 void print() const; private: 15 int x; }; // end class Test // constructor 20 Test::Test( int value ) 21 : x( value ) // initialize x to value 22 { 23 // empty body } // end Test constructor fig07_13.cpp (1 of 3) 41
42 26 27 // print x using implicit and explicit this pointers; 28 // parentheses around *this required 29 void Test::print() const 30 { 31 // implicitly use this pointer to access member x 32 cout << " x = " << x; // explicitly use this pointer to access member x 35 cout << "\n this->x = " << this->x; // explicitly use dereferenced this pointer and 38 // the dot operator to access member x 39 cout << "\n(*this).x = " << ( *this ).x << endl; } // end function print int main() 44 { 45 Test testobject( 12 ); testobject.print(); return 0; 50 Implicitly use this pointer; only specify name of data member (x). Explicitly use this pointer with arrow operator. Explicitly use this pointer; dereference this pointer first, then use dot operator. fig07_13.cpp (2 of 3) 42
43 51 } // end main x = 12 this->x = 12 (*this).x = 12 fig07_13.cpp (3 of 3) 43 fig07_13.cpp output (1 of 1)
44 7.5 Φξήζε ηνπ this Σεηξηαθή θιήζε ζπλαξηήζεσλ Πνιιαπιέο ζπλαξηήζεηο θαινύληαη κε κία δήισζε Η ζπλάξηεζε επηζηξέθεη δείθηε αλαθνξάο ζην ίδην ην αληηθείκελν { return *this; } Οη ζπλαξηήζεηο πνπ δελ επηζηξέθνπλ αλαθνξέο πξέπεη λα θιεζνύλ ηειεπηαίεο 44
45 1 // Fig. 7.14: time6.h 2 // Cascading member function calls. 3 4 // Time class definition. 5 // Member functions defined in time6.cpp. 6 #ifndef TIME6_H 7 #define TIME6_H 8 9 class Time { public: 12 Time( int = 0, int = 0, int = 0 ); // default constructor // set functions 15 Time &settime( int, int, int ); // set hour, minute, second 16 Time &sethour( int ); // set hour 17 Time &setminute( int ); // set minute 18 Time &setsecond( int ); // set second // get functions (normally declared const) 21 int gethour() const; // return hour 22 int getminute() const; // return minute 23 int getsecond() const; // return second 24 Set functions return reference to Time object to enable cascaded member function calls. time6.h (1 of 2) 45
46 25 // print functions (normally declared const) 26 void printuniversal() const; // print universal time 27 void printstandard() const; // print standard time private: 30 int hour; // 0-23 (24-hour clock format) 31 int minute; // int second; // }; // end class Time #endif time6.h (2 of 2) 46
47 1 // Fig. 7.15: time6.cpp 2 // Member-function definitions for Time class. 3 #include <iostream> 4 5 using std::cout; 6 7 #include <iomanip> 8 9 using std::setfill; 10 using std::setw; #include "time6.h" // Time class definition // constructor function to initialize private data; 15 // calls member function settime to set variables; 16 // default values are 0 (see class definition) 17 Time::Time( int hr, int min, int sec ) 18 { 19 settime( hr, min, sec ); } // end Time constructor 22 time6.cpp (1 of 5) 47
48 23 // set values of hour, minute, and second 24 Time &Time::setTime( int h, int m, int s ) 25 { 26 sethour( h ); 27 setminute( m ); 28 setsecond( s ); return *this; // enables cascading } // end function settime // set hour value 35 Time &Time::setHour( int h ) 36 { 37 hour = ( h >= 0 && h < 24 )? h : 0; return *this; // enables cascading } // end function sethour 42 Return *this as reference to enable cascaded member function calls. Return *this as reference to enable cascaded member function calls. time6.cpp (2 of 5) 48
49 43 // set minute value 44 Time &Time::setMinute( int m ) 45 { 46 minute = ( m >= 0 && m < 60 )? m : 0; return *this; // enables cascading } // end function setminute // set second value 53 Time &Time::setSecond( int s ) 54 { 55 second = ( s >= 0 && s < 60 )? s : 0; return *this; // enables cascading } // end function setsecond // get hour value 62 int Time::getHour() const 63 { 64 return hour; } // end function gethour 67 Return *this as reference to enable cascaded member function calls. Return *this as reference to enable cascaded member function calls. time6.cpp (3 of 5) 49
50 68 // get minute value 69 int Time::getMinute() const 70 { 71 return minute; } // end function getminute // get second value 76 int Time::getSecond() const 77 { 78 return second; } // end function getsecond // print Time in universal format 83 void Time::printUniversal() const 84 { 85 cout << setfill( '0' ) << setw( 2 ) << hour << ":" 86 << setw( 2 ) << minute << ":" 87 << setw( 2 ) << second; } // end function printuniversal 90 time6.cpp (4 of 5) 50
51 91 // print Time in standard format 92 void Time::printStandard() const 93 { 94 cout << ( ( hour == 0 hour == 12 )? 12 : hour % 12 ) 95 << ":" << setfill( '0' ) << setw( 2 ) << minute 96 << ":" << setw( 2 ) << second 97 << ( hour < 12? " AM" : " PM" ); } // end function printstandard time6.cpp (5 of 5) 51
52 1 // Fig. 7.16: fig07_16.cpp 2 // Cascading member function calls with the this pointer. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include "time6.h" // Time class definition 9 10 int main() 11 { 12 Time t; // cascaded function calls 15 t.sethour( 18 ).setminute( 30 ).setsecond( 22 ); // output time in universal and standard formats 18 cout << "Universal time: "; 19 t.printuniversal(); cout << "\nstandard time: "; 22 t.printstandard(); cout << "\n\nnew standard time: "; 25 Cascade member function calls; recall dot operator associates from left to right. fig07_16.cpp (1 of 2) 52
53 26 // cascaded function calls 27 t.settime( 20, 20, 20 ).printstandard(); cout << endl; return 0; } // end main Universal time: 18:30:22 Standard time: 6:30:22 PM Function call to fig07_16.cpp printstandard must (2 of 2) appear last; printstandard does not fig07_16.cpp return reference to t. output (1 of 1) 53 New standard time: 8:20:20 PM
54 7.6 Γηαρείξηζε Γπλακηθήο Μλήκεο κε ρξήζε new θαη delete Γηαρείξηζε δπλακηθήο κλήκεο Διέγρεη ηε δηαλνκή κλήκεο Με ρξήζε ησλ ηειεζηώλ new θαη delete Include standard header <new> 54
55 7.6 Γηαρείξηζε Γπλακηθήο Μλήκεο κε ρξήζε new θαη Έζησ Time *timeptr; timeptr = new Time; Τελεστής new delete Γεκηνπξγεί αληηθείκελα θαηάιιεινπ κεγέζνπο γηα ηνλ ηύπν Time Γίλεη ιάζνο αλ δελ ππάξρεη ρώξνο ζηε κλήκε Δπηζηξέθεη δείθηε ζηνλ ζπγθεθξηκέλν ηύπν Με αξρηθνπνίεζε double *ptr = new double( ); Time *timeptr = new Time( 12, 0, 0 ); Γήισζε πίλαθα int *gradesarray = new int[ 10 ]; 55
56 7.6 Γηαρείξηζε Γπλακηθήο Μλήκεο κε ρξήζε new θαη delete Απειεπζεξώλεη ηε κλήκε θαη θαηαζηξέθεη ηα αληηθείκελα Έζησ delete timeptr; Τειεζηήο delete Καιή ην destructor Η κλήκε κπνξεί λα ρξεζηκνπνηεζεί κε άιια αληηθείκελα Deallocating arrays delete [] gradesarray; Απειεπζεξώλεη ην array ζην νπνίν δείρλεη ην gradesarray Αλ είλαη δείθηεο ζε array αληηθεηκέλσλ Καιείηε πξώηα ν destructor γηα θάζε αληηθείκελν ηνπ array Μεηά απειεπζεξώλεη ηε κλήκε 56
57 7.7 static ηάμεηο static ηάμεο κεηαβιεηή Γεδνκέλα δηαζέζηκα ζε όιε ηελ ηάμε Ιδηόηεηα ηεο ηάμεο, όρη ζπγθεθξηκέλνπ αληηθεηκέλνπ ηεο ηάμεο Απνδνηηθό όηαλ απιά έλα αληίγξαθν ηεο ηάμεο είλαη αξθεηό Μόλν ε κεηαβιεηή static πξέπεη λα ελεκεξώλεηαη Μπνξεί λα κνηάδεη κε global, αιιά έρεη εκβέιεηα ζηελ ηάμε Αξρηθνπνηείηαη κηα κόλν θνξά Υπάξρεη αθόκε θαη ρσξίο αληηθείκελν 57
58 7.7 static ηάμεηο Πξόζβαζε ζε κεηαβιεηέο ηάμεο static Πξνζβάζηκα κέζσ νπνηνπδήπνηε αληηθεηκέλνπ ηάμεο public static κεηαβιεηέο Μπνξνύλ λα πξνζπειαζηνύλ θαη κέζσ (::) Employee::count private static κεηαβιεηέο Όηαλ δελ ππάξρεη αληηθείκελν Μπνξεί λα ηα πξνζπειάζεη θαλείο κέζσ ζπλάξηεζεο public static 58
59 7.7 static ηάμεηο static ζπλαξηήζεηο Γε κπνξνύλ λα πξνζπειάζνπλ non-static δεδνκέλα ή ζπλαξηήζεηο Γελ ππάξρεη this γηα ηηο static ζπλαξηήζεηο static δεδνκέλα θαη ζπλαξηήζεηο ππάξρνπλ αλεμάξηεηα από ηα αληηθείκελα 59
60 1 // Fig. 7.17: employee2.h 2 // Employee class definition. 3 #ifndef EMPLOYEE2_H 4 #define EMPLOYEE2_H 5 6 class Employee { 7 8 public: 9 Employee( const char *, const char * ); // constructor 10 ~Employee(); // destructor 11 const char *getfirstname() const; // return first name 12 const char *getlastname() const; // return last name // static member function 15 static int getcount(); // return # objects instantiated private: 18 char *firstname; 19 char *lastname; // static data member 22 static int count; // number of objects instantiated }; // end class Employee 25 static member function can only access static data members and member functions. static data member is class-wide data. employee2.h (1 of 2) 60
61 26 #endif 61 1 // Fig. 7.18: employee2.cpp 2 // Member-function definitions for class Employee. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include <new> // C++ standard new operator 9 #include <cstring> // strcpy and strlen prototypes #include "employee2.h" // Employee class definition // define and initialize static data member 14 int Employee::count = 0; // define static member function that returns number of 17 // Employee objects instantiated 18 int Employee::getCount() 19 { 20 return count; } // end static function getcount Initialize static data member exactly once at file scope. static member function accesses static data member count. employee2.h (2 of 2) employee2.cpp (1 of 3)
62 23 24 // constructor dynamically allocates space for 25 // first and last name and uses strcpy to copy 26 // first and last names into the object 27 Employee::Employee( const char *first, const char *last ) 28 { 29 firstname = new char[ strlen( first ) + 1 ]; 30 strcpy( firstname, first ); lastname = new char[ strlen( last ) + 1 ]; 33 strcpy( lastname, last ); count; // increment static count of employees cout << "Employee constructor for " << firstname 38 << ' ' << lastname << " called." << endl; } // end Employee constructor // destructor deallocates dynamically allocated memory 43 Employee::~Employee() 44 { 45 cout << "~Employee() called for " << firstname 46 << ' ' << lastname << endl; 47 Use static data member to store total count of employees. employee2.cpp new operator dynamically (2 of 3) allocates space. 62
63 48 delete [] firstname; // recapture memory 49 delete [] lastname; // recapture memory count; // decrement static count of employees } // end destructor ~Employee // return first name of employees. 56 const char *Employee::getFirstName() const 57 { 58 // const before return type prevents client from modifying 59 // private data; client should copy returned string before 60 // destructor deletes storage to prevent undefined pointer 61 return firstname; } // end function getfirstname // return last name of employee 66 const char *Employee::getLastName() const 67 { 68 // const before return type prevents client from modifying 69 // private data; client should copy returned string before 70 // destructor deletes storage to prevent undefined pointer 71 return lastname; } // end function getlastname Use static Operator data member deleteto deallocates store total memory. count of employee2.cpp (3 of 3) 63
64 1 // Fig. 7.19: fig07_19.cpp 2 // Driver to test class Employee. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include <new> // C++ standard new operator 9 10 #include "employee2.h" // Employee class definition int main() 13 { 14 cout << "Number of employees before instantiation is " 15 << Employee::getCount() << endl; // use class name Employee *e1ptr = new Employee( "Susan", "Baker" ); 18 Employee *e2ptr = new Employee( "Robert", "Jones" ); cout << "Number of employees after of instantiation class. is " 21 << e1ptr->getcount(); 22 static member function can be invoked on any object fig07_19.cpp (1 of 2) new operator dynamically allocates space. 64
65 23 cout << "\n\nemployee 1: " 24 << e1ptr->getfirstname() 25 << " " << e1ptr->getlastname() 26 << "\nemployee 2: " 27 << e2ptr->getfirstname() 28 << " " << e2ptr->getlastname() << "\n\n"; delete e1ptr; // recapture memory 31 e1ptr = 0; // disconnect pointer from free-store space 32 delete e2ptr; // recapture memory 33 e2ptr = 0; // disconnect pointer from free-store space cout << "Number of employees after deletion is " memory. 36 << Employee::getCount() << endl; return 0; } // end main static member function invoked using binary scope Operator resolution delete deallocates operator (no existing class objects). fig07_19.cpp (2 of 2) 65
66 Number of employees before instantiation is 0 Employee constructor for Susan Baker called. Employee constructor for Robert Jones called. Number of employees after instantiation is 2 Employee 1: Susan Baker Employee 2: Robert Jones fig07_19.cpp output (1 of 1) 66 ~Employee() called for Susan Baker ~Employee() called for Robert Jones Number of employees after deletion is 0
67 7.8 Αθαίξεζε Γεδνκέλσλ θαη Απόθξπςε Πιεξνθνξίαο Απόθξπςε πιεξνθνξίαο Οη ηάμεηο θξύβνπλ ιεπηνκέξεηεο ηεο πινπνίεζεο από ηνπο πειάηεο Π.ρ. : δνκή δεδνκέλσλ ζηνίβαο Γεδνκέλα πξνζηίζεληαη (pushed) Γεδνκέλα αθαηξνύληαη (popped) Γνκή Last-in, first-out (LIFO) Ο πειάηεο ζέιεη κόλν κηα LIFO δνκή δεδνκέλσλ Γε ηνλ ελδηαθέξεη πσο πινπνηείηε ε ζηνίβα Αθαίξεζε δεδνκέλσλ Πεξηγξάθεη ηε ιεηηνπξγηθόηεηα ηεο ηάμεο αλεμάξηεηα από ηελ πινπνίεζε 67
68 7.8 Αθαίξεζε Γεδνκέλσλ θαη Απόθξπςε Πιεξνθνξίαο Abstract data types (ADTs) Πξνζεγγίζεηο/ κνληέια πξαγκαηηθώλ ελλνηώλ θαη ζπκπεξηθνξάο int, float είλαη κνληέια γηα αξηζκνύο Αλαπαξάζηαζε δεδνκέλσλ C++ επεθηάζεηο Οη Standard ηύπνη δεδνκέλσλ δε κπνξνύλ λα ηξνπνπνηεζνύλ αιιά κπνξνύλ λα δεκηνπξγεζνύλ λένη 68
69 7.8.1 Παξάδεηγκα: Πίλαθαο Abstract Data Type ADT πίλαθαο Μπνξεί λα πεξηιακβάλεη Έιεγρν πεδίνπ ηηκώλ ηνπ δείθηε Κάζε δπλαηό πεδίν ηηκώλ Αληί λα αξρίδεη πάληα από ην 0 Αλάζεζε Σύγθξηζε Δηζαγσγή θαη Δθηύπσζε Πίλαθεο πνπ γλσξίδνπλ ην κέγεζόο ηνπο Πίλαθεο πνπ επεθηείλνληαη δπλακηθά 69
70 7.8.2 Παξάδεηγκα: String Abstract Data Type Σπκβνινζεηξέο ζηε C++ Η C++ δελ έρεη ηύπν string Παξέρεη κεραληζκό γηα δεκηνπξγία θαη πινπνίεζε string abstract data type ANSI/ISO standard string 70
71 7.9 Δκπεξηέρνπζεο ηάμεηο θαη Δπαλαιήπηεο Container classes (collection classes) Έρνπλ ζρεδηαζηεί λα έρνπλ ζπιινγέο από αληηθείκελα Κνηλέο ππεξεζίεο Δηζαγσγή, δηαγξαθή, αλαδήηεζε, ηαμηλόκεζε Παξαδείγκαηα Πίλαθεο, ζηνίβεο, νπξέο, δέλδξα, δηαζπλδεδεκέλεο ιίζηεο Δπαλαιήπηεο (iterators) Δπηζηξέθνπλ ην επόκελν ζηνηρείν κηαο ζπιινγήο Ή ελεξγνύλ πάλσ ζην επόκελν ζηνηρείν Μπνξεί λα ππάξρνπλ πνιινί επαλαιήπηεο Ωο έλα βηβιίν κε πνιινύο ζειηδνδείθηεο Κάζε επαλαιήπηεο έρεη ηε δηθή ηνπ «ζέζε» 71
72 7.10 Τάμεηο Proxy Proxy class Κξύβνπλ ηελ πινπνίεζε κηαο άιιεο ηάμεο Γλσξίδεη κόλν ηα public interface ηεο ηάμεο πνπ θξύβεη Forward class δήισζε Φξεζηκνπνηείηαη όηαλ ε δήισζε ηεο ηάμεο ρξεζηκνπνηεί δείθηε ζε άιιε ηάμε Γελ απαηηείηαη header file Γειώλεη ηελ ηάμε πξηλ ηελ αλαθνξά Μνξθή: class classtoload; 72
73 1 // Fig. 7.20: implementation.h 2 // Header file for class Implementation 3 4 class Implementation { 5 6 public: 7 8 // constructor 9 Implementation( int v ) 10 : value( v ) // initialize value with v 11 { 12 // empty body } // end Implementation constructor // set value to v 17 void setvalue( int v ) 18 { 19 value = v; // should validate v } // end function setvalue 22 public member function. implementation.h (1 of 2) 73
74 23 // return value 24 int getvalue() const 25 { 26 return value; } // end function getvalue public member function. implementation.h (2 of 2) private: 31 int value; }; // end class Implementation
75 1 // Fig. 7.21: interface.h 2 // Header file for interface.cpp 3 4 class Implementation; // forward class declaration 5 6 class Interface { 7 8 public: 9 Interface( int ); 10 void setvalue( int ); // same public interface as 11 int getvalue() const; // class Implementation 12 ~Interface(); private: // requires previous forward declaration (line 4) 17 Implementation *ptr; }; // end class Interface Provide same public interface as class Implementation; recall setvalue and getvalue only public member functions. Pointer to Implementation object requires forward class declaration. interface.h (1 of 1) 75
76 1 // Fig. 7.22: interface.cpp 2 // Definition of class Interface 3 #include "interface.h" // Interface class definition 4 #include "implementation.h" // Implementation class definition 5 6 // constructor underlying 7 Interface::Interface( int v ) Implementation object. 8 : ptr ( new Implementation( v ) ) // initialize ptr 9 { 10 // empty body } // end Interface constructor // call Implementation's setvalue function 15 void Interface::setValue( int v ) 16 { 17 ptr->setvalue( v ); } // end function setvalue 20 Maintain pointer to Proxy class Interface includes header file for class Implementation. Invoke corresponding function on underlying Implementation object. interface.cpp (1 of 2) 76
77 21 // call Implementation's getvalue function 22 int Interface::getValue() const 23 { 24 return ptr->getvalue(); } // end function getvalue // destructor 29 Interface::~Interface() 30 { 31 delete ptr; } // end destructor ~Interface Invoke corresponding function on underlying Implementation object. Deallocate underlying Implementation object. interface.cpp (2 of 2) 77
78 1 // Fig. 7.23: fig07_23.cpp 2 // Hiding a class s private data with a proxy class. 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 #include "interface.h" // Interface class definition 9 10 int main() 11 { 12 Interface i( 5 ); cout << "Interface contains: " << i.getvalue() 15 << " before setvalue" << endl; i.setvalue( 10 ); cout << "Interface contains: " << i.getvalue() 20 << " after setvalue" << endl; return 0; } // end main Only include proxy class header file. Create object of proxy class Interface; note no mention of Implementation class. fig07_23.cpp (1 of 1) fig07_23.cpp output (1 of 1) Invoke member functions via proxy class object. 78 Interface contains: 5 before setvalue Interface contains: 10 after setvalue
7.1 Εισαγωγή 7.2 const Αντικείµενα και const Συναρτήσεις 7.3 Σύνθεση: Αντικείµενα ως µέλη τάξης 7.4 friend Συναρτήσεις και τάξεις 7.
Πανεπιστήµιο Πατρών Τµήµα Μηχανικών Ηλεκτρονικών Υπολογιστών και Πληροφορικής ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΙΙ (C++) Τάξεις και Αφαίρεση εδοµένων 1 Τάξεις Μέρος ΙΙ 7.1 Εισαγωγή 7.2 const Αντικείµενα και
17TimeThis.h function returns reference pointer to same object { return *this; }
Προαπαιτούµενη Κάθε οµάδα θα πρέπει να εµπλουτίσει το ίδιο πρόγραµµα, που έκανε την προηγούµενη φορά, προσθέτοντας στην κλάση του έναν ή περισσότερους υπερφορτωµένους τελεστές (όπως , ++, +,-,+=..)
Constructors and Destructors in C++
Constructors and Destructors in C++ Σύνθεζη Πνιύ ζπρλά ζηε C++ κία θιάζε κπνξεί λα πεξηέρεη ζαλ κέιεδεδνκέλα αληηθείκελα άιισλ θιάζεσλ. Πνηα είλαη ε ζεηξά κε ηελ νπνία δεκηνπξγνύληαη θαη θαηαζηξέθνληαη
Outline 6.1 Εισαγωγή 6.2 Ορισµός δοµών - Structure 6.3 Προσπέλαση µελών δοµής - structure 6.4 Υλοποίηση τύπου Time µε struct από το χρήστη 6.
Πανεπιστήµιο Πατρών Τµήµα Μηχανικών Ηλεκτρονικών Υπολογιστών και Πληροφορικής ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΙΙ (C++) Τάξεις και Αφαίρεση εδοµένων 1 6.1 Εισαγωγή 6.2 Ορισµός δοµών - Structure 6.3 Προσπέλαση
Προγραμματισμός Ι. Κλάσεις και Αντικείμενα. Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο
Προγραμματισμός Ι Κλάσεις και Αντικείμενα Δημήτρης Μιχαήλ Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο Κλάσεις Η γενική μορφή μιας κλάσης είναι η εξής: class class-name { private data and
Παλεπηζηήκην Παηξώλ ΟΝΣΟΚΕΝΣΡΙΚΟ ΠΡΟΓΡΑΜΜΑΣΙΜΟ ΙΙ (C++) Σάξειρ και Αθαίπεζη Δεδομένων. Σμήμα Μηχανικών Ηλεκηπονικών Τπολογιζηών και Πληποθοπικήρ
Παλεπηζηήκην Παηξώλ Σμήμα Μηχανικών Ηλεκηπονικών Τπολογιζηών και Πληποθοπικήρ ΟΝΣΟΚΕΝΣΡΙΚΟ ΠΡΟΓΡΑΜΜΑΣΙΜΟ ΙΙ (C++) Σάξειρ και Αθαίπεζη Δεδομένων 1 6.1 Εηζαγωγή 6.2 Οξηζκόο δνκώλ - Structure 6.3 Πξνζπέιαζε
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 3/4/2017 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr Γιατί έλεγχος πρόσβασης? Προστασία ιδιωτικής πληροφορίας
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 30/5/2016 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr Συλλογή απορριμμάτων Συλλογή απορριμμάτων (Garbage
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 23/4/2018 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr Υπερφόρτωση μεθόδων Υπερφόρτωση μεθόδων Πολλαπλές
Οντοκεντρικός Προγραμματισμός
Οντοκεντρικός Προγραμματισμός Ενότητα 6: C++ ΚΛΑΣΕΙΣ, ΚΛΗΡΟΝΟΜΙΚΟΤΗΤΑ, ΠΟΛΥΜΟΡΦΙΣΜΟΣ Κλάσεις ΔΙΔΑΣΚΟΝΤΕΣ: Ιωάννης Χατζηλυγερούδης, Χρήστος Μακρής Πολυτεχνική Σχολή Τμήμα Μηχανικών Η/Υ & Πληροφορικής Τάξεις
Προαπαιτούμενες Ασκήσεις 5 ου Εργαστηρίου. Dose stoixeio (integer) : 25 Found stoixeio in position 7 Dose stoixeio (integer) :94 Value not found
Α. Πρώτη προαπαιτούµενη Κάθε οµάδα θα πρέπει να δηµιουργήσει τον ζητούµενο παρακάτω πίνακα και α. να εµφανίσει τα στοιχεία του, β. να τυπώσει τον µέσο όρο των στοιχείων του, γ. να ταξινοµήσει τα στοιχεία
Απαντήσεις θέματος 2. Παξαθάησ αθνινπζεί αλαιπηηθή επίιπζε ησλ εξσηεκάησλ.
Απαντήσεις θέματος 2 Απηά πνπ έπξεπε λα γξάςεηε (δελ ρξεηαδόηαλ δηθαηνιόγεζε εθηόο από ην Γ) Α return a*b; Β 0:acegf2, 1: acegf23, 2: acegf234, 3:acegf2345, 4:acegf23456, 5:acegf234567, 6:acegf2345678,
ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΣΧΟΛΗ ΘΕΤΙΚΩΝ ΕΠΙΣΤΗΜΩΝ ΤΜΗΜΑ ΜΑΘΗΜΑΤΙΚΩΝ ΙΠΛΩΜΑΤΙΚΗ ΕΡΓΑΣΙΑ
ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΣΧΟΛΗ ΘΕΤΙΚΩΝ ΕΠΙΣΤΗΜΩΝ ΤΜΗΜΑ ΜΑΘΗΜΑΤΙΚΩΝ ΙΠΛΩΜΑΤΙΚΗ ΕΡΓΑΣΙΑ ηµιουργία και χειρισµός LIFO λιστών µεταβλητού µήκους µε στοιχεία ακεραίους αριθµούς. Γενίκευση για χειρισµό λιστών πραγµατικών
ΕΙΣΑΓΩΓΗ ΣΤΟN ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ
ΕΙΣΑΓΩΓΗ ΣΤΟN ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ Εμβέλεια Μεταβλητών Εμβέλεια = το τμήμα του προγράμματος στο οποίο έχει ισχύ ή είναι ορατή η μεταβλητή.
Lab 1: C/C++ Pointers and time.h. Panayiotis Charalambous 1
Lab 1: C/C++ Pointers and time.h Panayiotis Charalambous 1 Send email to totis@cs.ucy.ac.cy Subject: EPL231-Registration Body: Surname Firstname ID Group A or B? Panayiotis Charalambous 2 Code Guidelines:
Lab 1: C/C++ Pointers and time.h. Panayiotis Charalambous 1
Lab 1: C/C++ Pointers and time.h Panayiotis Charalambous 1 Send email to totis@cs.ucy.ac.cy Subject: EPL231-Registration Body: Surname Firstname ID Group A or B? Panayiotis Charalambous 2 Code Guidelines:
Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο
Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων Εξάμηνο 7 ο Procedures and Functions Stored procedures and functions are named blocks of code that enable you to group and organize a series of SQL and PL/SQL
Δυναμική μνήμη με πίνακες και λίστες
Δυναμική μνήμη με πίνακες και λίστες Ατζέντα ονομάτων Οι πίνακες βοηθάνε στην εύκολη προσπέλαση, στην σειριοποίηση των δεδομένων για αποθήκευση ή μετάδοση. Απαιτούν ωστόσο είτε προκαταβολική δέσμευση μνήμης
10. Αντικειμενοστραφής Προγραμματισμός (Object Oriented Programming - OOP)
10. Αντικειμενοστραφής Προγραμματισμός (Object Oriented Programming - OOP) Χειμερινό εξάμηνο 2016 Πέτρος Κωμοδρόμος komodromos@ucy.ac.cy http://www.eng.ucy.ac.cy/petros 1 Θέματα Έλεγχος πρόσβασης στα μέλη
The Simply Typed Lambda Calculus
Type Inference Instead of writing type annotations, can we use an algorithm to infer what the type annotations should be? That depends on the type system. For simple type systems the answer is yes, and
ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ - ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΕΠΛ 133: ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΕΦΗΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΕΡΓΑΣΤΗΡΙΟ 3 Javadoc Tutorial
ΕΡΓΑΣΤΗΡΙΟ 3 Javadoc Tutorial Introduction Το Javadoc είναι ένα εργαλείο που παράγει αρχεία html (παρόμοιο με τις σελίδες στη διεύθυνση http://docs.oracle.com/javase/8/docs/api/index.html) από τα σχόλια
HY150a Φροντιστήριο 3 24/11/2017
HY150a Φροντιστήριο 3 24/11/2017 1 Assignment 3 Overview Το πρόγραμμα ζητείται να διαβάζει μια λίστα δεδομένων που περιγράφει τα διαθέσιμα τμήματα μνήμης (blocks) ενός ΗΥ. Το πρόγραμμα ζητείται να μεταφορτώνει
Βάσεις Δεδομέμωμ. Εξγαζηήξην V. Τκήκα Πιεξνθνξηθήο ΑΠΘ 2015-2016
Βάσεις Δεδομέμωμ Εξγαζηήξην V Τκήκα Πιεξνθνξηθήο ΑΠΘ 2015-2016 2 Σκοπός του 5 ου εργαστηρίου Σθνπόο απηνύ ηνπ εξγαζηεξίνπ είλαη: ε κειέηε ζύλζεησλ εξσηεκάησλ ζύλδεζεο ζε δύν ή πεξηζζόηεξεο ζρέζεηο ε κειέηε
EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 5: Component Adaptation Environment (COPE)
EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 5: Component Adaptation Environment (COPE) Performing Static Analysis 1 Class Name: The fully qualified name of the specific class Type: The type of the class
Προγραμματισμός Ι. Πίνακες, Δείκτες, Αναφορές και Δυναμική Μνήμη. Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο
Προγραμματισμός Ι Πίνακες, Δείκτες, Αναφορές και Δυναμική Μνήμη Δημήτρης Μιχαήλ Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο Πίνακες Αντικειμένων Όπως στην C μπορούμε να έχουμε πίνακες από
Συναρτήσεις στη C++ Οι µεταβλητές χαρακτηρίζονται από διάφορες ιδιότητες. Για ποιο διάστηµα η µεταβλητή υπάρχει στη µνήµη
Συναρτήσεις στη C++ 1 ΠΕΡΙΕΧΟΜΕΝΑ Εισαγωγή Συστατικά προγράµµατος στη C++ Μαθηµατικές Συναρτήσεις (Math Library) Συναρτήσεις Header Files Γεννήτρια τυχαίων αριθµών Χαρακτηριστικά Μεταβλητών Storage Classes
Φροντιςτήριο. Linked-List
Φροντιςτήριο Linked-List 1 Linked List Μια linked list είναι μια ακολουθία από ςυνδεδεμένουσ κόμβουσ Κάθε κόμβοσ περιέχει τουλάχιςτον Μια πληροφορία (ή ένα struct) Δείκτη ςτον επόμενο κόμβο τησ λίςτασ
ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ
ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ Ενότητα 12: Συνοπτική Παρουσίαση Ανάπτυξης Κώδικα με το Matlab Σαμαράς Νικόλαος Άδειες Χρήσης Το παρόν εκπαιδευτικό υλικό υπόκειται σε άδειες χρήσης Creative Commons.
ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007
Οδηγίες: Να απαντηθούν όλες οι ερωτήσεις. Όλοι οι αριθμοί που αναφέρονται σε όλα τα ερωτήματα μικρότεροι του 10000 εκτός αν ορίζεται διαφορετικά στη διατύπωση του προβλήματος. Αν κάπου κάνετε κάποιες υποθέσεις
ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006
ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/26 Οδηγίες: Να απαντηθούν όλες οι ερωτήσεις. Ολοι οι αριθμοί που αναφέρονται σε όλα τα ερωτήματα μικρότεροι το 1 εκτός αν ορίζεται διαφορετικά στη διατύπωση
department listing department name αχχουντσ ϕανε βαλικτ δδσϕηασδδη σδηφγ ασκϕηλκ τεχηνιχαλ αλαν ϕουν διξ τεχηνιχαλ ϕοην µαριανι
She selects the option. Jenny starts with the al listing. This has employees listed within She drills down through the employee. The inferred ER sttricture relates this to the redcords in the databasee
Οντοκεντρικός Προγραμματισμός
Οντοκεντρικός Προγραμματισμός Ενότητα 5: H ΓΛΩΣΣΑ C++ Συναρτήσεις - Μεταβλητές ΔΙΔΑΣΚΟΝΤΕΣ: Iωάννης Χατζηλυγερούδης, Χρήστος Μακρής Πολυτεχνική Σχολή Τμήμα Μηχανικών Η/Υ & Πληροφορικής Συναρτήσεις / Μεταβλητές
iii. iv. γηα ηελ νπνία ηζρύνπλ: f (1) 2 θαη
ΔΠΑΝΑΛΗΠΣΙΚΑ ΘΔΜΑΣΑ ΣΟ ΓΙΑΦΟΡΙΚΟ ΛΟΓΙΜΟ Μάρτιος 0 ΘΔΜΑ Να ππνινγίζεηε ηα όξηα: i ii lim 0 0 lim iii iv lim e 0 lim e 0 ΘΔΜΑ Γίλεηαη ε άξηηα ζπλάξηεζε '( ) ( ) γηα θάζε 0 * : R R γηα ηελ νπνία ηζρύνπλ:
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 16/4/2018 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr Τύποι της Java Primitives vs References Οι πρωταρχικοί
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 24/4/2017 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr Υπερφόρτωση μεθόδων Υπερφόρτωση μεθόδων Πολλαπλές
Εντολές εισόδου - εξόδου. Εισαγωγή στη C++
Εντολές εισόδου - εξόδου Εισαγωγή στη C++ Το πρώτο πρόγραμμα //my first program #include using namespace std; int main(){ cout
Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής
Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής Να γραφεί πρόγραμμα το οποίο δέχεται ως είσοδο μια ακολουθία S από n (n 40) ακέραιους αριθμούς και επιστρέφει ως έξοδο δύο ακολουθίες από θετικούς ακέραιους
2 Composition. Invertible Mappings
Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan Composition. Invertible Mappings In this section we discuss two procedures for creating new mappings from old ones, namely,
Πανεπιστήµιο Πατρών ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΙΙ (C++) είκτες και Συµβολοσειρές (Pointers. & Strings)
Πανεπιστήµιο Πατρών 1 Τµήµα Μηχανικών Ηλεκτρονικών Υπολογιστών και Πληροφορικής ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΙΙ (C++) είκτες και Συµβολοσειρές (Pointers & Strings) Περιεχόµενα 2 Εισαγωγή ήλωση και αρχικοποίηση
ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007
Οδηγίες: Να απαντηθούν όλες οι ερωτήσεις. Αν κάπου κάνετε κάποιες υποθέσεις να αναφερθούν στη σχετική ερώτηση. Όλα τα αρχεία που αναφέρονται στα προβλήματα βρίσκονται στον ίδιο φάκελο με το εκτελέσιμο
(C) 2010 Pearson Education, Inc. All rights reserved.
Connectionless transmission with datagrams. Connection-oriented transmission is like the telephone system You dial and are given a connection to the telephone of fthe person with whom you wish to communicate.
ΑΛΛΑΓΗ ΟΝΟΜΑΣΟ ΚΑΙ ΟΜΑΔΑ ΕΡΓΑΙΑ, ΚΟΙΝΟΥΡΗΣΟΙ ΦΑΚΕΛΟΙ ΚΑΙ ΕΚΣΤΠΩΣΕ ΣΑ WINDOWS XP
ΑΛΛΑΓΗ ΟΝΟΜΑΣΟ ΚΑΙ ΟΜΑΔΑ ΕΡΓΑΙΑ, ΚΟΙΝΟΥΡΗΣΟΙ ΦΑΚΕΛΟΙ ΚΑΙ ΕΚΣΤΠΩΣΕ ΣΑ WINDOWS XP ηότοι εργαζηηρίοσ ην πιαίζην ηνπ ζπγθεθξηκέλνπ εξγαζηεξίνπ ζα παξνπζηαζηνύλ βαζηθέο ιεηηνπξγίεο ησλ Windows XP πνπ ζρεηίδνληαη
Προγραμματισμός Υπολογιστών με C++
Προγραμματισμός Υπολογιστών με C++ ( 2012-13 ) 11η διάλεξη Ίων Ανδρουτσόπουλος http://www.aueb.gr/users/ion/ 1 Τι θα ακούσετε σήμερα Υπερφόρτωση του τελεστή εκχώρησης. Στατικές μεταβλητές, στατικές σταθερές
8. Μέθοδοι (Methods)
8. Μέθοδοι (Methods) Χειμερινό εξάμηνο 2012 Πέτρος Κωμοδρόμος komodromos@ucy.ac.cy http://www.eng.ucy.ac.cy/petros 1 Θέματα Μέθοδοι που παρέχονται από τη τάξη Math του Java API Χρήση στατικών μεθόδων και
TOOLBOOK (μάθημα 2) Δεκηνπξγία βηβιίνπ θαη ζειίδσλ ΠΡΟΑΡΜΟΓΗ: ΒΑΛΚΑΝΙΩΣΗ ΔΗΜ. ΕΚΠΑΙΔΕΤΣΙΚΟ ΠΕ19 1 TOOLBOOK ΜΑΘΗΜΑ 2
TOOLBOOK (μάθημα 2) Δεκηνπξγία βηβιίνπ θαη ζειίδσλ ΕΚΠΑΙΔΕΤΣΙΚΟ ΠΕ19 1 Δημιουργία σελίδων και βιβλίων Έλα θαηλνύξην βηβιίν πεξηέρεη κία άδεηα ζειίδα κε έλα άδεην background. Δελ κπνξνύκε λα μερσξίζνπκε
ΕΡΓΑΣΤΗΡΙΟ 1 - ΣΗΜΕΙΩΣΕΙΣ
ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΕΣΣΑΛΙΑΣ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΑΚΑΔΗΜΑΪΚΟ ΕΤΟΣ 2017-2018 ΧΕΙΜΕΡΙΝΟ ΕΞΑΜΗΝΟ ΜΑΘΗΜΑ: ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ Εισαγωγή ΕΡΓΑΣΤΗΡΙΟ 1 - ΣΗΜΕΙΩΣΕΙΣ Ένα πρόγραμμα σε C περιλαμβάνει μια ή περισσότερες συναρτήσεις
EE512: Error Control Coding
EE512: Error Control Coding Solution for Assignment on Finite Fields February 16, 2007 1. (a) Addition and Multiplication tables for GF (5) and GF (7) are shown in Tables 1 and 2. + 0 1 2 3 4 0 0 1 2 3
B-Δέλδξα. Τα B-δέλδξα ρξεζηκνπνηνύληαη γηα ηε αλαπαξάζηαζε πνιύ κεγάισλ ιεμηθώλ πνπ είλαη απνζεθεπκέλα ζην δίζθν.
B-Δέλδξα Τα B-δέλδξα ρξεζηκνπνηνύληαη γηα ηε αλαπαξάζηαζε πνιύ κεγάισλ ιεμηθώλ πνπ είλαη απνζεθεπκέλα ζην δίζθν. Δέλδξα AVL n = 2 30 = 10 9 (πεξίπνπ). 30
ΗΥ-150 Πξνγξακκατησκόο Ταμηλόκεσε θαη Αλαδήτεσε
ΗΥ-150 Πξνγξακκατησκόο Ταμηλόκεσε θαη Αλαδήτεσε To πξόβιεκα ηεο Αλαδήηεζεο Γνζέληνο δεδνκέλσλ, ι.ρ. ζε Πίλαθα (P) Χάρλσ λα βξσ θάπνην ζπγθεθξηκέλν ζηνηρείν (key) Αλ ν πίλαθαο δελ είλαη ηαμηλνκεκέλνο Γξακκηθή
Math 6 SL Probability Distributions Practice Test Mark Scheme
Math 6 SL Probability Distributions Practice Test Mark Scheme. (a) Note: Award A for vertical line to right of mean, A for shading to right of their vertical line. AA N (b) evidence of recognizing symmetry
Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Dynamic types, Lambda calculus machines Apr 21 22, 2016 1 Dynamic types and contracts (a) To make sure you understand the
ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ & ΑΛΓΟΡΙΘΜΟΙ ΕΡΓΑΣΤΗΡΙΟ
ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ & ΑΛΓΟΡΙΘΜΟΙ ΕΡΓΑΣΤΗΡΙΟ Κωδικός Θ: ΤΠ3001, Κωδικός Ε: ΤΠ3101 (ΜΕΥ/Υ) Ώρες (Θ - Ε): 4-2 Προαπαιτούμενα: Δρ. ΒΙΔΑΚΗΣ ΝΙΚΟΣ ΕΡΓΑΣΤΗΡΙΟ 6 Στοίβα (Stack) Stack Introduction Stack is one of the
Section 8.3 Trigonometric Equations
99 Section 8. Trigonometric Equations Objective 1: Solve Equations Involving One Trigonometric Function. In this section and the next, we will exple how to solving equations involving trigonometric functions.
Παράδειγµα χρήσης πίνακα
24 Strings Παράδειγµα χρήσης πίνακα Πίνακες χαρακτήρων Όλα τα strings τερµατίζουν µε το null χαρακτήρα ('\0') Παραδείγµατα char string1[] = "hello"; Το Null θα προστεθεί στο τέλος Η µεταβλητή string1 έχει
Συµβολοσειρές - Strings
Συµβολοσειρές - Strings 1 Συµβολοσειρέςστην C/C++ 2 Χαρακτήρες 'a', 'z', '0', Χαρακτήρες σαν int 'z' επίσης αναπαριστά την ακεραία τιµή του χαρακτήρα z Strings-Συµβολοσειρές Σειρές από χαρακτήρες σαν µια
3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β
3.4 SUM AND DIFFERENCE FORMULAS Page Theorem cos(αβ cos α cos β -sin α cos(α-β cos α cos β sin α NOTE: cos(αβ cos α cos β cos(α-β cos α -cos β Proof of cos(α-β cos α cos β sin α Let s use a unit circle
derivation of the Laplacian from rectangular to spherical coordinates
derivation of the Laplacian from rectangular to spherical coordinates swapnizzle 03-03- :5:43 We begin by recognizing the familiar conversion from rectangular to spherical coordinates (note that φ is used
Ανάλυση άσκησης. Employee. SalariedEmployee CommissionEmployee HourlyEmployee. BasePlusCommissionEmployee
Μία εταιρεία πληρώνει τους εργαζόμενους της σε εβδομαδιαία βάση. Οι αποδοχές των εργαζόμενων υπολογίζονται με τέσσερις διαφορετικούς τρόπους : Α) Μισθωτοί (SalariedEmployee), πληρώνονται με σταθερό ποσό
FOSSCOMM 2013 6ο Συνέδριο Κοινοτήτων Ανοιχτού Λογισμικού Σάββατο 20 Απριλίου 2013. Ομάδα Σχολής Ικάρων Εργαστήριο Arduino
FOSSCOMM 2013 6ο Συνέδριο Κοινοτήτων Ανοιχτού Λογισμικού Σάββατο 20 Απριλίου 2013 Ομάδα Σχολής Ικάρων Εργαστήριο Arduino Arduino Workshop LAB 1 : Παιχνίδι με έναν αισθητήρα φωτός Τι θα χρειαστούμε: 1 LED
ΣΤΟΙΧΕΙΑ ΤΗΣ ΓΛΩΣΣΑΣ C++ Constructors, Destructors, Pointers IO Streams, File Streams
ΣΤΟΙΧΕΙΑ ΤΗΣ ΓΛΩΣΣΑΣ C++ Constructors, Destructors, Pointers IO Streams, File Streams CONSTRUCTORS DESTRUCTORS Η κλάση mystring class mystring private: char s[100]; public: char *GetString(); void SetString(char
ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006
Οδηγίες: Να απαντηθούν όλες οι ερωτήσεις. Ολοι οι αριθμοί που αναφέρονται σε όλα τα ερωτήματα είναι μικρότεροι το 1000 εκτός αν ορίζεται διαφορετικά στη διατύπωση του προβλήματος. Διάρκεια: 3,5 ώρες Καλή
Υπερφόρτωση τελεστών (operator(
Υπερφόρτωση τελεστών (operator( overloading) Η υπερφόρτωση τελεστών είναι ένα από τα πιο ενδιαφέροντα χαρακτηριστικά του αντικειμενοστραφούς προγραμματισμού. Αναφέρεται στην πρόσθετη χρήση των συνηθισμένων
5. Ανασκόπηση αντικειμενοστραφούς προγραμματισμού
5. Ανασκόπηση αντικειμενοστραφούς προγραμματισμού Χειμερινό εξάμηνο 2013 Πέτρος Κωμοδρόμος komodromos@ucy.ac.cy http://www.eng.ucy.ac.cy/petros 1 Θέματα Αντικειμενοστραφής προγραμματισμός Τάξεις (classes)
Τίτλος Μαθήματος: Ηλεκτρονικοί Υπολογιστές IΙΙ. Διδάσκων: Επίκουρος Καθηγητής Αθανάσιος Σταυρακούδης
Τίτλος Μαθήματος: Ηλεκτρονικοί Υπολογιστές IΙΙ Ενότητα: Πράξεις με αρχεία Διδάσκων: Επίκουρος Καθηγητής Αθανάσιος Σταυρακούδης Τμήμα: Οικονομικών Επιστημών Ανάγνωση και εγγραφή αρχείων με χρήση ρεύματος
Προγραμματισμός Ι. Εισαγωγή στην C++ Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο
Προγραμματισμός Ι Εισαγωγή στην C++ Δημήτρης Μιχαήλ Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο Η γλώσσα C++ Σχεδιάστηκε το 1979 από τον Bjarne Stroustrup στα Bell Laboratories Βασίζεται
HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:
HOMEWORK 4 Problem a For the fast loading case, we want to derive the relationship between P zz and λ z. We know that the nominal stress is expressed as: P zz = ψ λ z where λ z = λ λ z. Therefore, applying
ΗΥ-150. Προγραμματισμός
ΗΥ-150 Προγραμματισμός Δείκτες (Pointers) Προγραμματισμός Δείκτες Τι είναι: τύπος μεταβλητών (όπως integer) Τι αποθηκεύουν: την διεύθυνση στη μνήμη άλλων μεταβλητών Τι χρειάζονται: Κυρίως, για δυναμική
DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.
DESIGN OF MACHINERY SOLUTION MANUAL -7-1! PROBLEM -7 Statement: Design a double-dwell cam to move a follower from to 25 6, dwell for 12, fall 25 and dwell for the remader The total cycle must take 4 sec
CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS
CHAPTER 5 SOLVING EQUATIONS BY ITERATIVE METHODS EXERCISE 104 Page 8 1. Find the positive root of the equation x + 3x 5 = 0, correct to 3 significant figures, using the method of bisection. Let f(x) =
Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο
Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων Εξάμηνο 7 ο Oracle SQL Developer An Oracle Database stores and organizes information. Oracle SQL Developer is a tool for accessing and maintaining the data
Αντικειμενοστρεφής Προγραμματισμός
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων Αντικειμενοστρεφής Προγραμματισμός 14/5/2018 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr INTERFACES Μελέτη περίπτωσης: δημιουργία και χρήση
SOAP API. https://bulksmsn.gr. Table of Contents
SOAP API https://bulksmsn.gr Table of Contents Send SMS...2 Query SMS...3 Multiple Query SMS...4 Credits...5 Save Contact...5 Delete Contact...7 Delete Message...8 Email: sales@bulksmsn.gr, Τηλ: 211 850
Τίτλος Μαθήματος: Ηλεκτρονικοί Υπολογιστές IΙΙ. Διδάσκων: Επίκουρος Καθηγητής Αθανάσιος Σταυρακούδης
Τίτλος Μαθήματος: Ηλεκτρονικοί Υπολογιστές IΙΙ Ενότητα: Εισαγωγή στη C++ Διδάσκων: Επίκουρος Καθηγητής Αθανάσιος Σταυρακούδης Τμήμα: Οικονομικών Επιστημών Αριθμοί κινητής υποδιαστολής (float) στη C++ (1)
Δομές Δεδομένων - Εργαστήριο 2. Λίστες
Λίστες Λίστες (Lists) : Συλλογή δεδομένων σε δυναμικά δεσμευμένους κόμβους. Κάθε κόμβος περιέχει συνδέσεις προς άλλους κόμβους. Προσπέλαση -στού κόμβου διατρέχοντας όλους τους προηγούμενους. Πολλές παραλλαγές
Assalamu `alaikum wr. wb.
LUMP SUM Assalamu `alaikum wr. wb. LUMP SUM Wassalamu alaikum wr. wb. Assalamu `alaikum wr. wb. LUMP SUM Wassalamu alaikum wr. wb. LUMP SUM Lump sum lump sum lump sum. lump sum fixed price lump sum lump
x x x x tan(2 x) x 2 2x x 1
ΘΕΡΙΝΟ ΣΜΗΜΑ ΜΑΘΗΜΑΣΙΚΑ Ι ΕΠΑΝΑΛΗΠΣΙΚΕ ΑΚΗΕΙ ΜΕΡΟ Ι 1. Να γίλνπλ νη γξαθηθέο παξαζηάζεηο ησλ παξαθάησ ζπλαξηήζεσλ. t ( i) e ( ii) ln( ) ( iii). Να βξεζεί ην Π.Ο., ν ηύπνο ηεο αλίζηξνθεο θαη ην Π.Τ. ησλ
ΓΗΑΓΩΝΗΣΜΑ ΣΤΑ ΜΑΘΖΜΑΤΗΚΑ. Ύλη: Μιγαδικοί-Σσναρηήζεις-Παράγωγοι Θεη.-Τετν. Καη Εήηημα 1 ο :
ΓΗΑΓΩΝΗΣΜΑ ΣΤΑ ΜΑΘΖΜΑΤΗΚΑ Ον/μο:.. Γ Λσκείοσ Ύλη: Μιγαδικοί-Σσναρηήζεις-Παράγωγοι Θεη.-Τετν. Καη. 11-1-11 Εήηημα 1 ο : Α. Γηα ηελ ζπλάξηεζε f, λα βξείηε ην δηάζηεκα ζην νπνίν είλαη παξαγσγίζηκε θαζώο θαη
Άμεσοι Αλγόριθμοι: Προσπέλαση Λίστας (list access)
Έρνπκε απνζεθεύζεη κηα ζπιινγή αξρείσλ ζε κηα ζπλδεδεκέλε ιίζηα, όπνπ θάζε αξρείν έρεη κηα εηηθέηα ηαπηνπνίεζεο. Μηα εθαξκνγή παξάγεη κηα αθνινπζία από αηηήκαηα πξόζβαζεο ζηα αξρεία ηεο ιίζηαο. Γηα λα
Γλώσσα Προγραμματισμού C++ Εισαγωγή - Μια πρώτη ματιά
Γλώσσα Προγραμματισμού C++ Εισαγωγή - Μια πρώτη ματιά Βασικά χαρακτηριστικά αναπτύχθηκε ως επέκταση της C το 1979 υπερσύνολο της C γλώσσα γενικού σκοπού, γρήγορη, Αντικειμενοστραφής προγραμματισμός (Object
12. ΑΛΦΑΡΙΘΜΗΤΙΚΑ. υο είδη αλφαριθµητικών Τα αλφαριθµητικά της C πίνακες τύπου char Ta αντικείµενα της κλάσης string
12. ΑΛΦΑΡΙΘΜΗΤΙΚΑ υο είδη αλφαριθµητικών Τα αλφαριθµητικά της C πίνακες τύπου char Ta αντικείµενα της κλάσης string Aλφαριθµητικά της C int main() const int max=80; char str[max); //κάθε char δεσµεύει
242 - Ειζαγωγή ζηους Η/Υ
1 242 - Ειζαγωγή ζηους Η/Υ Τμήμα Μαθημαηικών, Πανεπιζηήμιο Ιωαννίνων Ακαδημαϊκό Έηος 2015-2016 Άρτια Α.Μ. (0-2-4-6-8) 2 Πίνακες 1. Αλάζεζε ηηκήο 2. Επηινγή 3. Αλαθύθιωζε 4. Πίλαθεο 5. Τπραίνη αξηζκνί 6.
Προγραμματισμός Υπολογιστών με C++ Φύλλο Διαγωνίσματος Ακαδημαϊκό εξάμηνο: Χειμερινό
Προγραμματισμός Υπολογιστών με C++ Φύλλο Διαγωνίσματος Ακαδημαϊκό εξάμηνο: Χειμερινό 2013-14 Διδάσκων: Γεώργιος Παπαϊωάννου Μονογραφή επιτηρητή: Στοιχεία Φοιτητή (συμπληρώνεται από το φοιτητή) Όνομα: Αίθουσα/αμφιθέατρο:
ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡ/ΣΜΟΣ C++
Υπερφόρτωση, keywords CONST, STATIC, FRIEND ΟΝΤΟΚΕΝΤΡΙΚΟΣ ΠΡΟΓΡ/ΣΜΟΣ C++ Μ. Ρήγκου (rigou@ceid.upatras.gr) Τι θα συζητήσουμε σήμερα Υπερφόρτωση Συναρτήσεων Τελεστών CONST αντικείμενα, μεταβλητές και συναρτήσεις
Reminders: linear functions
Reminders: linear functions Let U and V be vector spaces over the same field F. Definition A function f : U V is linear if for every u 1, u 2 U, f (u 1 + u 2 ) = f (u 1 ) + f (u 2 ), and for every u U
Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)
Phys460.nb 81 ψ n (t) is still the (same) eigenstate of H But for tdependent H. The answer is NO. 5.5.5. Solution for the tdependent Schrodinger s equation If we assume that at time t 0, the electron starts
Κευάλαιο 8 Μονοπωλιακή Συμπεριφορά- Πολλαπλή Τιμολόγηση
Κευάλαιο 8 Μονοπωλιακή Συμπεριφορά- Πολλαπλή Τιμολόγηση Πώς πρέπει να τιμολογεί ένα μονοπώλιο; Μέρξη ζηηγκήο ην κνλνπώιην έρεη ζεσξεζεί ζαλ κηα επηρείξεζε ε νπνία πσιεί ην πξντόλ ηεο ζε θάζε πειάηε ζηελ
VBA ΣΤΟ WORD. 1. Συχνά, όταν ήθελα να δώσω ένα φυλλάδιο εργασίας με ασκήσεις στους μαθητές έκανα το εξής: Version 25-7-2015 ΗΜΙΤΕΛΗΣ!!!!
VBA ΣΤΟ WORD Version 25-7-2015 ΗΜΙΤΕΛΗΣ!!!! Μου παρουσιάστηκαν δύο θέματα. 1. Συχνά, όταν ήθελα να δώσω ένα φυλλάδιο εργασίας με ασκήσεις στους μαθητές έκανα το εξής: Εγραφα σε ένα αρχείο του Word τις
The challenges of non-stable predicates
The challenges of non-stable predicates Consider a non-stable predicate Φ encoding, say, a safety property. We want to determine whether Φ holds for our program. The challenges of non-stable predicates
Οντοκεντρικός Προγραμματισμός
Οντοκεντρικός Προγραμματισμός Ενότητα 6: C++ ΚΛΑΣΕΙΣ, ΚΛΗΡΟΝΟΜΙΚΟΤΗΤΑ, ΠΟΛΥΜΟΡΦΙΣΜΟΣ Πολυμορφισμός ΔΙΔΑΣΚΟΝΤΕΣ:Ιωάννης Χατζηλυγερούδης, Χρήστος Μακρής Πολυτεχνική Σχολή Τμήμα Μηχανικών Η/Υ & Πληροφορικής
b. Use the parametrization from (a) to compute the area of S a as S a ds. Be sure to substitute for ds!
MTH U341 urface Integrals, tokes theorem, the divergence theorem To be turned in Wed., Dec. 1. 1. Let be the sphere of radius a, x 2 + y 2 + z 2 a 2. a. Use spherical coordinates (with ρ a) to parametrize.
Section 9.2 Polar Equations and Graphs
180 Section 9. Polar Equations and Graphs In this section, we will be graphing polar equations on a polar grid. In the first few examples, we will write the polar equation in rectangular form to help identify
Δομές Δεδομένων & Αλγόριθμοι
Ουρές Ουρές Περίληψη Η ΟυράΑΔΤ Υλοποίηση με κυκλικό πίνακα Αυξανόμενη Ουρά βασισμένη σε πίνακα Interface ουράς στην C++ Η Ουρά ADT Η ΑΔΤ Ουρά αποθηκεύει αυθαίρετα αντικείμενα Οι εισαγωγές και διαγραφές
C.S. 430 Assignment 6, Sample Solutions
C.S. 430 Assignment 6, Sample Solutions Paul Liu November 15, 2007 Note that these are sample solutions only; in many cases there were many acceptable answers. 1 Reynolds Problem 10.1 1.1 Normal-order
Η Γλώσσα Προγραµµατισµού C++ (The C++ Programming Language)
Η Γλώσσα Προγραµµατισµού C++ (The C++ Programming Language) ηµήτριος Κατσαρός, Ph.D. Χειµώνας 2005 ιάλεξη 5η Ιστοσελίδα του µαθήµατος http://skyblue.csd.auth.gr/~dimitris/courses/cpp_fall05.htm Θα τοποθετούνται
Απνηειέζκαηα Εξσηεκαηνινγίνπ 2o ηεηξάκελν 2011-12
Απνηειέζκαηα Εξσηεκαηνινγίνπ 2o ηεηξάκελν 11-12 Project 6: Ταμίδη κε ηε Μεραλή ηνπ Φξόλνπ Υπεύζπλνη Καζεγεηέο: Ε. Μπηιαλάθε Φ. Αλησλάηνο Δρώηηζη 3: Πνηα από ηα παξαθάησ ΜΜΕ ηεξαξρείηε από πιεπξάο ζεκαζίαο;
Approximation of distance between locations on earth given by latitude and longitude
Approximation of distance between locations on earth given by latitude and longitude Jan Behrens 2012-12-31 In this paper we shall provide a method to approximate distances between two points on earth
ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ Α.Π.Θ. ΕΡΓΑΣΤΗΡΙΟ C++ ΕΞΑΜΗΝΟ Γ Ακαδηµαϊκό Έτος
ΠΑΡΑ ΕΙΓΜΑ δυναµικής δέσµευσης και αποδέσµευσης µνήµης στη C++ µέσω των new και delete. // create.cpp #include using namespace std; class values public: values() : value1(0), value2(0) count++;
Δηζαγωγή ζηε γιώζζα C Παξνπζίαζε 3 ε : Δίζνδνο/ Έμνδνο - Σπλαξηήζεηο - Pointers
Δηζαγωγή ζηε γιώζζα C Παξνπζίαζε 3 ε : Δίζνδνο/ Έμνδνο - Σπλαξηήζεηο - Pointers κυ θαη Χεθηαθόο Έιεγρνο Σρνιή Μεραλνιόγωλ Μεραληθώλ ΔΜΠ Δξγαζηήξην Απηνκάηνπ Διέγρνπ Δίζνδνο/ Έμνδνο Βαζηθό output Σπλάξηεζε
Αζκήζεις ζτ.βιβλίοσ ζελίδας 13 14
.1.10 ζκήζεις ζτ.βιβλίοσ ζελίδας 13 14 Ερωηήζεις Καηανόηζης 1. ύν δηαθνξεηηθέο επζείεο κπνξεί λα έρνπλ θαλέλα θνηλό ζεκείν Έλα θνηλό ζεκείν i ύν θνηλά ζεκεία iλ) Άπεηξα θνηλά ζεκεία ηηηνινγήζηε ηελ απάληεζε
Οντοκεντρικός Προγραμματισμός
Οντοκεντρικός Προγραμματισμός Ενότητα 5: H ΓΛΩΣΣΑ C++ Εισαγωγή στην C++ ΔΙΔΑΣΚΟΝΤΕΣ:Iωάννης Χατζηλυγερούδης, Χρήστος Μακρής Πολυτεχνική Σχολή Τμήμα Μηχανικών Η/Υ & Πληροφορικής H Γλώσσα C++ ΙΣΤΟΡΙΑ 1967: