SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Grading and policy
Course outline and references
Object oriented concept revision
String manipulation revision.
Dr. Hussien M. Sharaf 2
Assignments and Projects: 22%
Mid-Term Exam: 8%
Lab: 10%
Final Exam: 60%
Dr. Hussien M. Sharaf 3
1. Introduction to file management and OO Revision.
2. File organization and fundamental file/streams
processing operations(opening, reading, writing,
seeking).
3. Reading/writing fields of a single record.
4. List different methods for field organization.
5. Reading/writing records: using fixed length and
variable length.
6. Reading/writing records: delimiters and simple
Index. Buffering of records.
Mid-Term exam (Lec 1- 5)
Dr. Hussien M. Sharaf 4
7. Linear/sequential and binary searching on files.
8. Reclaiming space in files (as a result for deletes
and updates).
9. Key sorting and simple indexing.
10. Record operations with existence of Indexing.
11. Composite Indexing (primary and secondary
indexes).
12. Multilevel indexing and introduction to B trees.
13. Using Hashing to locate records.
Dr. Hussien M. Sharaf 5
Main Text book is
Michael J. Folk, Bill Zoellick, Greg
Riccardi; File Structures: An
Object-oriented Approach
with C++; Pearson Education
These are other text books
1. Steve Teale; C++ IOStreams
handbook; Addison-Wesley,
1993
2. D. S. Malik; Data Structures
Using C++; Cengage
Learning, Jul 31, 2009
Dr. Hussien M. Sharaf 6
A class is a data
structure that holds
data and functions.
It can be seen as a
container of related
variables and
functions.
int x=500;
char c=‘A’;
string g;
void incrementX(int x);function
variables
Dr. Hussien M. Sharaf 8
An object is an instantiation of a class.
Class format:
class class_name {
access_specifier_1:
member1;
access_specifier_2:
member2;
...
} object_names;
Where:
class_name: is a valid identifier for the class.
access_specifier: is one of the following three
keywords: private, public or protected.
members: can be data or function declarations.
object_names: is an optional list of names for
objects of this class.
Variable definition
int x;
Class definition
class class_name;
Dr. Hussien M. Sharaf 9
Now let’s make a simple class for a rectangle.
class Crectangle
{
public:
int area ();
int width, height;
};
Crectangle class contains two data members (width,
and height), and one public member function area
that calculates area.
Dr. Hussien M. Sharaf 10
int height;
int width;
int area();
Crectangle
Access specifiers modify the access rights that the
members following them acquire.
Private members: are accessible only from within
other members of the same class.
Public members: are accessible from anywhere where
the object is visible.
If none of the two words exist before any member of the
class, then the default is private.
Dr. Hussien M. Sharaf 11
The following
figure shows the
scope of each
data member in
different classes.
Whole program
class cl1{
private x;
public y;
};
private x;
public y;
int main() {
…..
}
class cl2{
private a;
public b;
};
private a;
public b;
Dr. Hussien M. Sharaf 12
A. Data members are variables declared inside the
class definition.
B. Methods:
1. Constructors initialize data members if needed.
2. set function stores the entered parameter into the
corresponding data member.
3. get function returns the value of each data member, so
each data member should have a get function that
returns its value.
Dr. Hussien M. Sharaf 13
Data members
Constructor
Get: within the class
(like: area ())
Or
Set: outside it (like:
set_values (int,int))
#include <iostream>
using namespace std;
class CRectangle {
int width, height;
public:
CRectangle(){width=1;}
int area () {return (x*y);}
void set_values (int,int);
};
void CRectangle::set_values
(int a, int b) {
width = a;
height = b;
}
Dr. Hussien M. Sharaf 14
#include <iostream>
using namespace std;
class CRectangle {
//Declaration section
public:
int width, height;
//Definition section
int area ()
{return (width * height);}
void set_values (int,int);
};
void CRectangle::set_values
(int a, int b) {
width = a;
height = b;
}
Output:
rectangle’s area is: 20
int main () {
CRectangle rect;
rect.width = 4;
rect.height = 5;
//OR
rect.set_values(4,5);
cout << “rectangle’s area is: "
<< rect.area();
return 0;
}
Dr. Hussien M. Sharaf 15
Constructor is a special member function that
must be defined with the same name as the
class.
Constructor is used to initialize data members of
the class.
Constructor only executed when a new object of
the class is created.
Constructors cannot return values.
Constructors are declared public.
Dr. Hussien M. Sharaf 16
Default constructor is a constructor with no
parameters.
It can be either:
- Implicit: the compiler provides a default constructor, if
no constructor has defined.
It does not initialize the class’s data members, so they
contain garbage data.
- or Explicit: you define a constructor that takes no
arguments, but from inside its body you have to
initialize the data members of the class.
Dr. Hussien M. Sharaf 17
#include <iostream>
using namespace std;
class CRectangle {
int width, height;
public:
//Constructor without arguments
CRectangle (){width=1;height=0;};
//Constructor with arguments
CRectangle (int,int);
int area () {return (width*height);}
};
Dr. Hussien M. Sharaf 18
CRectangle:: CRectangle(int a,
int b)
{
width = a;
height = b;
}
int main () {
CRectangle rect_a(3,4);
CRectangle rect_b();
rect_b.width=90;
rect_b.height =80;
cout << “rect_a width/height are: "
<< rect_a.width<<“/”<< rect_a.height<<endl;
cout << “rect_b width/height are: "
<< rect_b.width<<“/”<< rect_b. height<<endl;
cout << “rect_a area is: " << rect_a.area() <<endl;
cout << “rect_b area is: " << rect_b.area() <<endl;
system("Pause");
return 0; }
Dr. Hussien M. Sharaf 19
You already use overloaded operators
string s1( “Happy Term" );
cout<< “I wish you “<<s1;
We need to write code to tell the compiler how to
deal with any new class that we build.
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write
from/to files.
Dr. Hussien M. Sharaf 20
When overloading operators << and >> it is
better to use ostream and istream which are the
parents of ofstream and ifstream
Dr. Hussien M. Sharaf 21
ostream istream
iostream
fstream
ofstream
cout
ifstream
cin
http://www.cplusplus.com/reference/iostream/
#include <iostream>
using namespace std;
class CRectangle {
int width, height;
public:
//Constructor without arguments
CRectangle (){width=1;height=0;};
//Constructor with arguments
CRectangle (int,int);
int area () {return (width*height);}
//overload the in and out operators
friend istream& operator >> (istream &
stream, CRectangle & p);
friend ostream& operator<<(ostream &
stream, CRectangle & p);
};
Dr. Hussien M. Sharaf 23
CRectangle::CRectangle(int a,
int b) {width = a;
height = b;}
istream & operator >> (istream &
stream, CRectangle & p)
{stream>>p.width;
stream.get(); // skip a char
OR stream.ignore(); //skip a char
stream>>p.height;
return stream;}
ostream & operator<<(ostream &
stream, CRectangle & p)
{stream<< p.width<<“,”
<< p.height<<endl;
return stream;}
int main () {
CRectangle rect_a(3,4);
CRectangle rect_b;
rect_b.width=90;
rect_b.height =80;
cout << “rect_a is: " << rect_a <<endl;
cout << “rect_b is: " << rect_b<<endl;
cout << “rect_a area is: " << rect_a.area() <<endl;
cout << “rect_b area is: " << rect_b.area() <<endl;
system("Pause");
return 0; }
Dr. Hussien M. Sharaf 24
Dr. Hussien M. Sharaf 25
Below are some functions that are used to do
different operations on strings.
insert substringAppend(+)length replacefind
String
Manipulation
Dr. Hussien M. Sharaf 26
Returns the length of the string.
Example:
string email = "d@h.com";
cout<<"Email length: "<<email.length()<<endl;
Output:
Email length: 7
Dr. Hussien M. Sharaf 27
Concatenates two chars/strings.
We can use operator “+” to perform the append
operation directly.
Example:
string myname = "Ahmed Yehia";
string job = ", Computer Engineer";
string mystr = myname + job;
// Or
mystr = myname.append(job);
cout<< mystr <<endl;
Output:
Ahmed Yehia, Computer Engineer
Dr. Hussien M. Sharaf 28
Inserts some additional content at a specific
location within the string content.
It takes two inputs:
1. Position from where to insert.
2. String to insert.
Example:
string myname = "Ahmed Yehia";
myname.insert(6, "M ");
cout<< "My name is: " <<myname <<endl;
Output:
My name is: Ahmed M Yehia
Dr. Hussien M. Sharaf 29
Searches the string for some specified content
It takes two inputs (can take only the first):
1. The content to be matched.
2. Position from where to start search.
It returns the position of the first occurrence in the
string.
Example:
string myname = "Ahmed Yehia";
int pos1 = myname.find("e");
int pos2 = myname.find("e", 4);
cout<< "first occurrence of e: " <<pos1<<endl;
cout<< "second occurrence of e: " <<pos2<<endl;
Output:
first occurrence of e: 3
second occurrence of e: 7
Dr. Hussien M. Sharaf 30
substr results in a subset of the full string.
It takes two inputs:
1. Position from where to start cutting the string.
2. Count of letters to extract.
Example:
string email = "d@h.com";
string domain = email.substr(2,email.length() -1);
cout<<"Domain is: "<<domain<<endl;
Output:
Domain is: h.com
Dr. Hussien M. Sharaf 31
Replaces a section of the current string by some other
specified content.
It takes three inputs:
1. Position from where to replace.
2. Count of letters to replace.
3. The replacement string.
Example:
string fname = "Ahmed Yehia";
fname.replace(6,5, "Ali");
cout<< "My friend’s name is: " <<fname <<endl;
Output:
My friend’s name is: Ahmed Ali
Dr. Hussien M. Sharaf 32
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string myname = "Hussien";
//append
myname.append("Sharaf");
//insert
myname.insert(7, " M ");
cout<< "My name is: "
<<myname <<endl;
//length
cout<< "My full name length is: "
<<myname.length() <<endl;
//find
int spos1 = myname.find("s");
int spos2 = myname.find("s", spos1+1);
cout<< "positions of s in " << myname <<
" are at: " << spos1<< ", " <<spos2 <<endl;
//substr
int space_pos = myname.find(' ');
string firstName =
myname.substr(0,space_pos);
cout<<"My first name is: "
<<firstName<<endl;
//replace
firstName.replace(4,2,"ei");
cout<<"My first name can be written as:
"<<firstName<<endl;
system ("pause");
return 0;
}
Dr. Hussien M. Sharaf 33
Dr. Hussien M. Sharaf 34
Run Example 1.3 using VS2008 or VS2010
Send the source code project (after zipping it) to my
email:
n.abdelhameed@fci-cu.edu.eg
With subject: “FO – Assignment#1.3”
Run Example 1.4 using VS2008 or VS2010
Send the source code project (after zipping it) to my
email:
n.abdelhameed@fci-cu.edu.eg
With subject: “FO – Assignment#1.4”
Dr. Hussien M. Sharaf 35
Next week is the deadline.
No excuses.
Don’t wait until last day.
I can help you to the highest limit within the next
3 days.
Dr. Hussien M. Sharaf 36
1. Delete the debug folder.
2. Compress the solution folder using
winrar.
3. Rename the compressed file as follows:
StudentName_ID_A1.rar
StudentName_ID_A2.rar
4. Email to: n.abdelhameed@fci-cu.edu.eg
5. Follow your marks at:
http://tinyurl.com/p6qwdme
Dr. Hussien M. Sharaf 37
CS215 Lec 1   introduction

Mais conteúdo relacionado

Mais procurados

Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programmingSajid Hasan
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
Array in c programming
Array in c programmingArray in c programming
Array in c programmingMazharul Islam
 
Xml query language and navigation
Xml query language and navigationXml query language and navigation
Xml query language and navigationRaghu nath
 
Java - Arrays Concepts
Java - Arrays ConceptsJava - Arrays Concepts
Java - Arrays ConceptsVicter Paul
 
Array in c programming
Array in c programmingArray in c programming
Array in c programmingManojkumar C
 
Array in c language
Array in c languageArray in c language
Array in c languageumesh patil
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loopsCtOlaf
 

Mais procurados (20)

Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array in c++
Array in c++Array in c++
Array in c++
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Xml query language and navigation
Xml query language and navigationXml query language and navigation
Xml query language and navigation
 
Structure in C
Structure in CStructure in C
Structure in C
 
4.arrays
4.arrays4.arrays
4.arrays
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
 
Java - Arrays Concepts
Java - Arrays ConceptsJava - Arrays Concepts
Java - Arrays Concepts
 
Array in C
Array in CArray in C
Array in C
 
Array C programming
Array C programmingArray C programming
Array C programming
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Control statements
Control statementsControl statements
Control statements
 
Array in c
Array in cArray in c
Array in c
 
Array in-c
Array in-cArray in-c
Array in-c
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops
 
Array in c#
Array in c#Array in c#
Array in c#
 

Destaque

Destaque (20)

CS215 - Lec 10 b trees and hashing
CS215 - Lec 10   b trees and hashingCS215 - Lec 10   b trees and hashing
CS215 - Lec 10 b trees and hashing
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 - Lec 9 indexing and reclaiming space in files
CS215 - Lec 9  indexing and reclaiming space in filesCS215 - Lec 9  indexing and reclaiming space in files
CS215 - Lec 9 indexing and reclaiming space in files
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 
CS215 - Lec 3 single record operations
CS215 - Lec 3  single record operationsCS215 - Lec 3  single record operations
CS215 - Lec 3 single record operations
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
Lec4
Lec4Lec4
Lec4
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Infos2014
Infos2014Infos2014
Infos2014
 

Semelhante a CS215 Lec 1 introduction

Semelhante a CS215 Lec 1 introduction (20)

Bc0037
Bc0037Bc0037
Bc0037
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Java execise
Java execiseJava execise
Java execise
 
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
 
Object and class
Object and classObject and class
Object and class
 
Inheritance
Inheritance Inheritance
Inheritance
 
C# program structure
C# program structureC# program structure
C# program structure
 
Core java oop
Core java oopCore java oop
Core java oop
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 
Java 2 chapter 10 - basic oop in java
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in java
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear
 
Jscript part2
Jscript part2Jscript part2
Jscript part2
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
 

Mais de Arab Open University and Cairo University (13)

Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 
CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 

Último

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

CS215 Lec 1 introduction

  • 1.
  • 2. Grading and policy Course outline and references Object oriented concept revision String manipulation revision. Dr. Hussien M. Sharaf 2
  • 3. Assignments and Projects: 22% Mid-Term Exam: 8% Lab: 10% Final Exam: 60% Dr. Hussien M. Sharaf 3
  • 4. 1. Introduction to file management and OO Revision. 2. File organization and fundamental file/streams processing operations(opening, reading, writing, seeking). 3. Reading/writing fields of a single record. 4. List different methods for field organization. 5. Reading/writing records: using fixed length and variable length. 6. Reading/writing records: delimiters and simple Index. Buffering of records. Mid-Term exam (Lec 1- 5) Dr. Hussien M. Sharaf 4
  • 5. 7. Linear/sequential and binary searching on files. 8. Reclaiming space in files (as a result for deletes and updates). 9. Key sorting and simple indexing. 10. Record operations with existence of Indexing. 11. Composite Indexing (primary and secondary indexes). 12. Multilevel indexing and introduction to B trees. 13. Using Hashing to locate records. Dr. Hussien M. Sharaf 5
  • 6. Main Text book is Michael J. Folk, Bill Zoellick, Greg Riccardi; File Structures: An Object-oriented Approach with C++; Pearson Education These are other text books 1. Steve Teale; C++ IOStreams handbook; Addison-Wesley, 1993 2. D. S. Malik; Data Structures Using C++; Cengage Learning, Jul 31, 2009 Dr. Hussien M. Sharaf 6
  • 7.
  • 8. A class is a data structure that holds data and functions. It can be seen as a container of related variables and functions. int x=500; char c=‘A’; string g; void incrementX(int x);function variables Dr. Hussien M. Sharaf 8
  • 9. An object is an instantiation of a class. Class format: class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names; Where: class_name: is a valid identifier for the class. access_specifier: is one of the following three keywords: private, public or protected. members: can be data or function declarations. object_names: is an optional list of names for objects of this class. Variable definition int x; Class definition class class_name; Dr. Hussien M. Sharaf 9
  • 10. Now let’s make a simple class for a rectangle. class Crectangle { public: int area (); int width, height; }; Crectangle class contains two data members (width, and height), and one public member function area that calculates area. Dr. Hussien M. Sharaf 10 int height; int width; int area(); Crectangle
  • 11. Access specifiers modify the access rights that the members following them acquire. Private members: are accessible only from within other members of the same class. Public members: are accessible from anywhere where the object is visible. If none of the two words exist before any member of the class, then the default is private. Dr. Hussien M. Sharaf 11
  • 12. The following figure shows the scope of each data member in different classes. Whole program class cl1{ private x; public y; }; private x; public y; int main() { ….. } class cl2{ private a; public b; }; private a; public b; Dr. Hussien M. Sharaf 12
  • 13. A. Data members are variables declared inside the class definition. B. Methods: 1. Constructors initialize data members if needed. 2. set function stores the entered parameter into the corresponding data member. 3. get function returns the value of each data member, so each data member should have a get function that returns its value. Dr. Hussien M. Sharaf 13
  • 14. Data members Constructor Get: within the class (like: area ()) Or Set: outside it (like: set_values (int,int)) #include <iostream> using namespace std; class CRectangle { int width, height; public: CRectangle(){width=1;} int area () {return (x*y);} void set_values (int,int); }; void CRectangle::set_values (int a, int b) { width = a; height = b; } Dr. Hussien M. Sharaf 14
  • 15. #include <iostream> using namespace std; class CRectangle { //Declaration section public: int width, height; //Definition section int area () {return (width * height);} void set_values (int,int); }; void CRectangle::set_values (int a, int b) { width = a; height = b; } Output: rectangle’s area is: 20 int main () { CRectangle rect; rect.width = 4; rect.height = 5; //OR rect.set_values(4,5); cout << “rectangle’s area is: " << rect.area(); return 0; } Dr. Hussien M. Sharaf 15
  • 16. Constructor is a special member function that must be defined with the same name as the class. Constructor is used to initialize data members of the class. Constructor only executed when a new object of the class is created. Constructors cannot return values. Constructors are declared public. Dr. Hussien M. Sharaf 16
  • 17. Default constructor is a constructor with no parameters. It can be either: - Implicit: the compiler provides a default constructor, if no constructor has defined. It does not initialize the class’s data members, so they contain garbage data. - or Explicit: you define a constructor that takes no arguments, but from inside its body you have to initialize the data members of the class. Dr. Hussien M. Sharaf 17
  • 18. #include <iostream> using namespace std; class CRectangle { int width, height; public: //Constructor without arguments CRectangle (){width=1;height=0;}; //Constructor with arguments CRectangle (int,int); int area () {return (width*height);} }; Dr. Hussien M. Sharaf 18 CRectangle:: CRectangle(int a, int b) { width = a; height = b; }
  • 19. int main () { CRectangle rect_a(3,4); CRectangle rect_b(); rect_b.width=90; rect_b.height =80; cout << “rect_a width/height are: " << rect_a.width<<“/”<< rect_a.height<<endl; cout << “rect_b width/height are: " << rect_b.width<<“/”<< rect_b. height<<endl; cout << “rect_a area is: " << rect_a.area() <<endl; cout << “rect_b area is: " << rect_b.area() <<endl; system("Pause"); return 0; } Dr. Hussien M. Sharaf 19
  • 20. You already use overloaded operators string s1( “Happy Term" ); cout<< “I wish you “<<s1; We need to write code to tell the compiler how to deal with any new class that we build. ofstream: Stream class to write on files ifstream: Stream class to read from files fstream: Stream class to both read and write from/to files. Dr. Hussien M. Sharaf 20
  • 21. When overloading operators << and >> it is better to use ostream and istream which are the parents of ofstream and ifstream Dr. Hussien M. Sharaf 21 ostream istream iostream fstream ofstream cout ifstream cin
  • 23. #include <iostream> using namespace std; class CRectangle { int width, height; public: //Constructor without arguments CRectangle (){width=1;height=0;}; //Constructor with arguments CRectangle (int,int); int area () {return (width*height);} //overload the in and out operators friend istream& operator >> (istream & stream, CRectangle & p); friend ostream& operator<<(ostream & stream, CRectangle & p); }; Dr. Hussien M. Sharaf 23 CRectangle::CRectangle(int a, int b) {width = a; height = b;} istream & operator >> (istream & stream, CRectangle & p) {stream>>p.width; stream.get(); // skip a char OR stream.ignore(); //skip a char stream>>p.height; return stream;} ostream & operator<<(ostream & stream, CRectangle & p) {stream<< p.width<<“,” << p.height<<endl; return stream;}
  • 24. int main () { CRectangle rect_a(3,4); CRectangle rect_b; rect_b.width=90; rect_b.height =80; cout << “rect_a is: " << rect_a <<endl; cout << “rect_b is: " << rect_b<<endl; cout << “rect_a area is: " << rect_a.area() <<endl; cout << “rect_b area is: " << rect_b.area() <<endl; system("Pause"); return 0; } Dr. Hussien M. Sharaf 24
  • 25. Dr. Hussien M. Sharaf 25
  • 26. Below are some functions that are used to do different operations on strings. insert substringAppend(+)length replacefind String Manipulation Dr. Hussien M. Sharaf 26
  • 27. Returns the length of the string. Example: string email = "d@h.com"; cout<<"Email length: "<<email.length()<<endl; Output: Email length: 7 Dr. Hussien M. Sharaf 27
  • 28. Concatenates two chars/strings. We can use operator “+” to perform the append operation directly. Example: string myname = "Ahmed Yehia"; string job = ", Computer Engineer"; string mystr = myname + job; // Or mystr = myname.append(job); cout<< mystr <<endl; Output: Ahmed Yehia, Computer Engineer Dr. Hussien M. Sharaf 28
  • 29. Inserts some additional content at a specific location within the string content. It takes two inputs: 1. Position from where to insert. 2. String to insert. Example: string myname = "Ahmed Yehia"; myname.insert(6, "M "); cout<< "My name is: " <<myname <<endl; Output: My name is: Ahmed M Yehia Dr. Hussien M. Sharaf 29
  • 30. Searches the string for some specified content It takes two inputs (can take only the first): 1. The content to be matched. 2. Position from where to start search. It returns the position of the first occurrence in the string. Example: string myname = "Ahmed Yehia"; int pos1 = myname.find("e"); int pos2 = myname.find("e", 4); cout<< "first occurrence of e: " <<pos1<<endl; cout<< "second occurrence of e: " <<pos2<<endl; Output: first occurrence of e: 3 second occurrence of e: 7 Dr. Hussien M. Sharaf 30
  • 31. substr results in a subset of the full string. It takes two inputs: 1. Position from where to start cutting the string. 2. Count of letters to extract. Example: string email = "d@h.com"; string domain = email.substr(2,email.length() -1); cout<<"Domain is: "<<domain<<endl; Output: Domain is: h.com Dr. Hussien M. Sharaf 31
  • 32. Replaces a section of the current string by some other specified content. It takes three inputs: 1. Position from where to replace. 2. Count of letters to replace. 3. The replacement string. Example: string fname = "Ahmed Yehia"; fname.replace(6,5, "Ali"); cout<< "My friend’s name is: " <<fname <<endl; Output: My friend’s name is: Ahmed Ali Dr. Hussien M. Sharaf 32
  • 33. #include <iostream> #include <string> using namespace std; int main () { string myname = "Hussien"; //append myname.append("Sharaf"); //insert myname.insert(7, " M "); cout<< "My name is: " <<myname <<endl; //length cout<< "My full name length is: " <<myname.length() <<endl; //find int spos1 = myname.find("s"); int spos2 = myname.find("s", spos1+1); cout<< "positions of s in " << myname << " are at: " << spos1<< ", " <<spos2 <<endl; //substr int space_pos = myname.find(' '); string firstName = myname.substr(0,space_pos); cout<<"My first name is: " <<firstName<<endl; //replace firstName.replace(4,2,"ei"); cout<<"My first name can be written as: "<<firstName<<endl; system ("pause"); return 0; } Dr. Hussien M. Sharaf 33
  • 34. Dr. Hussien M. Sharaf 34
  • 35. Run Example 1.3 using VS2008 or VS2010 Send the source code project (after zipping it) to my email: n.abdelhameed@fci-cu.edu.eg With subject: “FO – Assignment#1.3” Run Example 1.4 using VS2008 or VS2010 Send the source code project (after zipping it) to my email: n.abdelhameed@fci-cu.edu.eg With subject: “FO – Assignment#1.4” Dr. Hussien M. Sharaf 35
  • 36. Next week is the deadline. No excuses. Don’t wait until last day. I can help you to the highest limit within the next 3 days. Dr. Hussien M. Sharaf 36
  • 37. 1. Delete the debug folder. 2. Compress the solution folder using winrar. 3. Rename the compressed file as follows: StudentName_ID_A1.rar StudentName_ID_A2.rar 4. Email to: n.abdelhameed@fci-cu.edu.eg 5. Follow your marks at: http://tinyurl.com/p6qwdme Dr. Hussien M. Sharaf 37