Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout << "We have a quiz or a test!"; else.

Slides:



Advertisements
Similar presentations
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Advertisements

Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
/3024/ SUN MON TUE WED THU FRI SAT JANUARY 2011 February 2011 SMTWTFS
The great fast food survey 2012 Get ready to record your data!
Structure TDate struct TDate { int year, month, day; }; // Define a new data type.
CS 1430: Programming in C++.
1 dimensional static Array Int[] a = new int[4]; A[0]A[1]A[2]A[3] Int[] b= new int[1]; B[0] Array is a list of variables having same name and same data.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
Enumeration Types Managing Ordered Sets. Enumeration types are designed to increase the readability of programs Used to define a set of named constants.
5 Day Forecast Mon Tues Wed Thu Fri.
Enumerated Data Types Data type created by programmer
…your name….
GANTT CHARTS Example Example Example Example text Tasks Example 1
Mon – 2Tue – 3Wed – 4Thu - 5Fri - 6Sat - 7Sun - 8 Mon – 9Tue – 10Wed – 11Thu - 12Fri – 13Sat – 14Sun -15 Mon – 16Tue – 17Wed – 18Thu - 19Fri – 20Sat –
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER

CS 1430: Programming in C++.
به نام خداوند خورشید و ماه
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};
MON TUE WED THU
1   1.テキストの入れ替え テキストを自由に入れ替えることができます。 フチなし全面印刷がおすすめです。 印刷のポイント.
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
Logo Calendar – January 2012 TO DO LIST 01/04/2012 Example TO DO LIST
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Primary Longman Elect 6B Chapter 5 Adverbs.

ANNUAL CALENDAR HOLIDAYS JANUARY FEBRUARY MARCH APRIL MAY JUNE
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
Free PPT Diagrams : ALLPPT.com
Free PPT Diagrams : ALLPPT.com
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Jan Sun Mon Tue Wed Thu Fri Sat
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
2008 Calendar.
S M T W F S M T W F
January MON TUE WED THU FRI SAT SUN
Sun Mon Tue Wed Thu Fri Sat
1 - January - Sun Mon The Wed Thu Fri Sat
2 0 X X s c h e d u l e 1 MON TUE WED THU JANUARY 20XX FRI SAT SUN MEMO.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Calendar
Calendar – 2010 (October, November & December)
Calendar.
Calendar – 2010 (July, August & September )
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Sun Mon Tue Wed Thu Fri Sat
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
January MON TUE WED THU FRI SAT SUN
A3 1.1c To Multiply & Divide Positive & Negative Numbers
S M T W F S M T W F
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
June 2017 Seahawk Cross Country SUMMER RUNNING Sun Mon Tue Wed Thu Fri
Sun Mon Tue Wed Thu Fri Sat
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
WEB PAGES: Tables Welcome Back !.
June 2019 Seahawk Cross Country SUMMER RUNNING Sun Mon Tue Wed Thu Fri
1 January 2018 Sun Mon Tue Wed Thu Fri Sat
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Structures Chapter 4.
2008 Calendar.
S M T W F S M T W F
S M T W F S M T W F
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Presentation transcript:

Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout << "We have a quiz or a test!"; else if (today == THU) cout << “We have a Lab!"; else if (today == SAT) cout << “Party!"; else cout << “What to do?”; 1

Enumeration Data Type and const int enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) … const int SUN = 0; const int MON = 1; const int TUE = 2; const int WED = 3; const int THU = 4; const int FRI = 5; const int SAT = 6; int today; today = 10; 2

Enumeration Data Type Operations on enum type assignment comparison Function return value Function parameters: & No Input/Output! 3

Using enum Type in C++ Classes enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType { private: string id; string firstName, lastName; float gpa; Status standing; public:... }; 4

Method Read of Class StudentType void Read() { cin >> id >> firstName >> lastName >> gpa; int credits; cin >> credits; if (credits <= 30) standing = FRESHMAN; else if (credits <= 60) standing = SOPHOMORE; else if (credits <= 90) standing = JUNIOR; else standing = SENIOR; return; } 5

Private Method Status GetStanding() { int credits; cin >> credits; if (credits <= 30) return FRESHMAN; else if (credits <= 60) return = SOPHOMORE; else if (credits <= 90) return = JUNIOR; else return = SENIOR; } 6

Method Read of Class StudentType void Read() { cin >> id >> firstName >> lastName >> gpa; standing = GetStanding(); return; } 7

Method Write of Class StudentType void Write() { cout << endl << setw(25) << id << endl << setw(25) << firstName << endl << setw(25) << lastName << endl << setw(25) << gpa; if (standing == FRESHMAN) cout << endl << setw(25) << “FRESHMAN”; else if (standing == SOPHOMORE) cout << endl << setw(25) << “SOPHOMORE”; else if (standing == JUNIOR) cout << endl << setw(25) << “JUNIOR”; else cout << endl << setw(25) << “SENIOR”; return; } 8

Private Method Void DisplayStanding() { if (standing == FRESHMAN) cout << endl << setw(25) << “FRESHMAN”; else if (standing == SOPHOMORE) cout << endl << setw(25) << “SOPHOMORE”; else if (standing == JUNIOR) cout << endl << setw(25) << “JUNIOR”; else cout << endl << setw(25) << “SENIOR”; return; } 9

Method Write of Class StudentType void Write() { cout << endl << setw(25) << id << endl << setw(25) << firstName << endl << setw(25) << lastName << endl << setw(25) << gpa; DisplayStanding(); return; } 10

enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType { private: string id, firstName, lastName; float gpa; Status standing; Status GetStanding() void DisplayStanding() public: StudentType() StudentType(string sid, string first, string last, float sgpa) StudentType(const StudentType& s) void Read() void Write() bool Equals(const StudentType& s) // if (s1.Equals(s2))... }; 11

Class SectionType const int MAX_SIZE = 26; enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType {... }; class SectionType { private: int numStudents; StudentType students[MAX_SIZE]; public: void Read()... }; 12

Class SectionType const int MAX_SIZE = 26; enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType class SectionType { private: int numStudents; StudentType students[MAX_SIZE]; public: void Read() { cin >> numStudents; for (int i = 0; i < numStudents; i ++) students[i].Read(); }... }; 13

Class SectionType class SectionType { private: int numStudents; StudentType students[MAX_SIZE]; public: SectionType() { numStudents = 0; } void Read() { Student s(cin); while ( cin ) { students[numStudents] = s; numStudents ++; s = Student(cin); } }... }; 14

Class SectionType class SectionType { private: int numStudents; StudentType students[MAX_SIZE]; public: void Read() { Student s(cin); while ( cin ) { students[numStudents ++] = s; // same as // students[numStudents] = s; // numStudents ++; s = Student(cin); } }... }; 15

const int MAX_SIZE = 26; enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType class SectionType int main() { SectionType CS143_S2; CS143_S2.Read(); // Find the freshman student with the highest GPA among // all freshman students in CS143_S2 } 16

// // The function finds and returns the index of a Freshman // student who has the highest GPA among all Freshman // students in a section, assuming there is at least one // Freshman student in the section. // Parameter: ( in ) // int IndexOfMaxFreshmanGPA(const SectionType& sec) { int index; // Not 0! float maxGPA = 0.0; for (int i = 0; i < sec.numStudents; i ++) if (sec.students[i].standing == FRESHMAN && sec.students[i].gpa > maxGPA) { index = i; maxGPA = sec.students[i].gpa; } return index; } 17

const int MAX_SIZE = 26; enum Status {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR}; class StudentType class SectionType int IndexOfMaxFreshmanGPA(const SectionType& sec); int main() { SectionType CS143_S2; CS143_S2.Read(); // Find the freshman student with the highest GPA among // all freshman students in CS143_S2 int index = IndexOfMaxFreshmanGPA(CS143_S2); cout << “The Freshman student with highest GPA ” << “ among all freshman students in Section 2 of CS143 ” ?... } 18

Class SectionType class SectionType { private: int numStudents; StudentType students[MAX_SIZE]; public: Student StudentWithMaxGPAByStatus(Status s) { int index; float maxGPA = 0.0; for (int i = 0; i < numStudents; i ++) if (students[i].standing == s && students[i].gpa > maxGPA) { index = i; maxGPA = students[i].gpa; } return students[index]; } }; 19

int main() { SectionType CS143_S2; CS143_S2.Read(); // Find the freshman student with the highest GPA among // all freshman students in CS143_S2 Student s = CS143_S2. StudentWithMaxGPAByStatus(FRESHMAN); cout << “The Freshman student with highest GPA among all ” << “freshman students in Section 2 of CS143 is ”; s.Write() // Find the sophomore student with the highest GPA among // all sophomore students in CS143_S2 Student s = CS143_S2. StudentWithMaxGPAByStatus(SOPHOMORE); cout << “The sophomore student with highest GPA among all ” << “sophomore students in Section 2 of CS143 is ”; s.Write()... } 20

Schedule Program 6 Required to work in Teams of two students Sign up by 3 pm, Monday, May 2 Update Program 5 Using enum types. 21