Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Exposure C++ Chapter XVI C++ Data Structures, the Record.
Array. Convert Numbers in Different Base Systems Generate values to a series of numbers in different base systems: Base is between 2 and 9; Maximum number.
Lesson 11 Structured Data CS1 Lesson John Cole1.
1. List Static List: no adding or deleting Dynamic List: can add or delete items from the list Both static and dynamic lists: linear search, update item.
XII CBSE Previous Year Question Paper QUESTION NO 1 (C) 2 Marks.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
1 Lecture 32 Handling Selected Topics Again!! Structs and Arrays of Structs Special Lectures.
Arrays.
Chapter 11: Structured Data. Slide Introduction An array makes it possible to access a list or table of data of the same data type by using a single.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11. The Struct Data Type.
Edited from Powerpoint Slides provided by Thomson Learning
Programmer Defined Structures (Records)
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
Review Binary Numbers Bit : 0 or 1 Byte: 8 bites 256 different values 2 8 KB : 1024 bytes 2 10 bytes MB : 1024 * 1024 bytes 2 10 * 2 10 (2 20 ) bytes GB.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Structure TDate struct TDate { int year, month, day; }; // Define a new data type.
Selection Sorting S[] : array of int or float Size: number of elements of s[] Pseudocode for i = 0 to size - 2 find the index of a smallest element between.
Class Constructors class Student { private: string id, firstName, lastName; float gpa; public: Student() Student(string sID) Student(string first, string.
CS 132 Spring 2008 Chapter 2 Object-Oriented Design (OOD) and C++ Ideas: * Inheritance (and protected members of a class) ** Operator overloading Pointer.
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
Class Student class Student { private: string id; string firstName, lastName; float gpa; public: void Read() void Write() string getGPA() void setGPA(
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
CS 1430: Programming in C++.
Data Types Storage Size Domain of all possible values Operations 1.
CS 1430: Programming in C++ 1. Class StudentList class StudentList { private: int numStudents; Student students[MAX_SIZE]; int find(const Student& s)
Multiple Items in one Data Object Arrays are a way to store more than one piece of data in a data object, provided that all the data is of the same type.
11 Introduction to Object Oriented Programming (Continued) Cats.
The Basics of Arrays Problem: How can the rancher easily catalog all of his cattle?
Class Method Read class Student { private: string id; string firstName, lastName; float gpa; public: // Will the method change any data members? // Yes!
CS 1430: Programming in C++ 1. Test 2 Friday Functions Arrays For Loops Understand Concepts and Rules Memorize Concepts and Rules Apply Concepts and Rules.
Lecture 20 Polymorphism. Introduction General meaning ; the ability to take on different forms. Programming language term: –Allows an entity to take a.
CPS120 Introduction to Computer Science Exam Review Lecture 18.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
Chapter Structured Data 11. Combining Data into Structures 11.2.
Lecture 2 Arrays. Topics 1 Arrays hold Multiple Values 2 Accessing Array Elements 3 Inputting and Displaying Array Contents 4 Array Initialization 5 Using.
Java - KFT1 Task 4 RegiStudent Diagrams
Java - KFT1 Task 4 RegiStudent Diagrams IT Java Course Mentors : - Pubali Banerjee, PhD - Cynthia Lang, PE, MSChE Western Governors University IT Java.
Topic 4 Data Structures Program Development and Design Using C++, Third Edition.
Nested Structures struct TDate { int year, month, day; }; struct StudentType { string id, firstName, lastName; float gpa; TDate DOB; }; struct SectionType.
1 C++ Classes and Data Structures Course link…..
COMPUTER 2430 Object Oriented Programming and Data Structures I
Structs versus Classes
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
A solution to a list of records
CS 1430: Programming in C++.
CS 1430: Programming in C++.
Student Data Score First Name Last Name ID GPA DOB Phone ...
CS 1430: Programming in C++.
CS 1430: Programming in C++.
CS 1430: Programming in C++.
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};
Strings A collection of characters taken as a set:
Counting Loops.
CS 1430: Programming in C++.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
CS148 Introduction to Programming II
CS 1430: Programming in C++.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Structure (i.e. struct) An structure creates a user defined data type
Presentation transcript:

Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1

Store Student Data in Variables // For one student at a time float score, GPA; string firstName, lastName, ID; … 2

Store Students Data in Parallel Arrays const int MAX_SIZE = 30; // To keep data for all students float scores[MAX_SIZE], GPA[MAX_SIZE]; string firstName[MAX_SIZE], lastName[MAX_SIZE], ID[MAX_SIZE]; 3

C++ Structure struct Student { string id; string firstName, lastName; float gpa; }; // Student is a data type! 4

Structure Variables int numStudents; float score; Student s1, s2; // Student is a data type! 5

Accessing Members of a Structure Variable Student s1; // Input data into struct cout << "Enter ID: "; cin >> s1.id; cout << "Enter first name: "; cin >> s1.firstName; // Output student data cout << setw(9) << s1.id << setw(25) << s1.firstName; Using the dot notation! 6

C++ Class class Student { string id; string firstName, lastName; float gpa; }; // Student is a class (data type)! // By default, all fields are private. 7

C++ Class class Student { private: string id; string firstName, lastName; float gpa; public:... }; Create public functions (methods) to access private fields. 8

Class Methods class Student { private: string id; string firstName, lastName; float gpa; public: // Make sure the order is correct. void Read() { cin >> id >> firstName >> lastName >> gpa; } }; 9

Class Methods class Student { private: string id; string firstName, lastName; float gpa; public: void Read() void Print() { cout << endl; cout << setw(9) << id << setw(20) << firstName << setw(20) << lastName << setw(5) << gpa; } }; 10

Calling Class Methods Student s1; // Input data into object s1 s1.Read(); // Output data of object s1 s1.Print(); Using the dot notation! 11

Syntax and Style class Student { private: string id; string firstName, lastName; float gpa; public: void Read()... }; // class, private, public: key word // Student: Identifier, your choice // Fields : Declaring variables // Braces // Semicolon after } // Read, Print: class methods (function inside class) // Indentation 12

Semantics class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa; }... }; Student is a new data type! It has data fields and methods (functions) on the data. 13

Semantics class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa; }... }; Data fields have class scope and can be accessed from any class methods! 14

C++ Classes cin >> base; while ( !cin.eof() && (base 9) ) { // display message cin.ignore(MAX_LINE_SIZE, ‘\n’); cin >> base: } 15

More Class Methods class Student { private:... public:... string getFirst() { return firstName; } void setFirstName( string name ) { firstName = name; } }; 16

More Class Methods class Student { private:... public:... string getGPA() { return gpa; } void setGPA( float value ) { gpa = value; } void updateGPA( float amount ) { gpa += amount; } }; 17

Calling Class Methods Student s1, s2; // Input data s1.Read(); s2.Read(); // Output data s1.Print(); s2.Print(); 18

// Comparing two students if ( s1.getGPA() > s2.getGPA() ) cout << “\nFirst student has higher GPA."; else if ( s1.getGPA() < s2.getGPA() ) cout << “\nSecond student has higher GPA."; else cout << “\nThe two student have the same GPA."; 19 Calling Class Methods

// Updating students data s1.setGPA( 2.9 ); s1.updateGPA( 0.5 ); if ( s1.getGPA() > s2.getGPA() ) cout << “\nFirst student has higher GPA."; else if ( s1.getGPA() < s2.getGPA() ) cout << “\nSecond student has higher GPA."; else cout << “\nThe two student have the same GPA."; 20 Calling Class Methods

class Student {... } int main() { Student s1, s2; s1.Read(); s2.Read(); s1.Print(); s2.Print(); // Comparing GPA of s1 and s2 s1.updateGPA( 0.5 ); // Comparing GPA of s1 and s2 return 0; } 21

// // Comment Block // // Includes // constants class Student {... } // Function prototypes int main() {... return 0; } // Function definitions 22

Schedule Quiz5-5: Due today Quiz7-1: Due Wednesday Wednesday: Test2 Review Thursday: Lab 8 Friday Test 2: 60 points Notes Program 4 Due Wednesday, April 6 Grace Friday, April 8 23

Quiz5-6 Now 24