Sheet 3. void SetPayRate(float rate); float CalcGrossPay(); void Validation(ifstream & in); //employee.h. //operator overloading. #include <fstream.

Similar documents
this Pointer, Constant Functions, Static Data Members, and Static Member Functions this Pointer (11.1) Example of this pointer

Object Oriented Programming CS250

Come and join us at WebLyceum

Notes on Chapter Three

vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW);

Review: C++ Basic Concepts. Dr. Yingwu Zhu

CS201 Latest Solved MCQs

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

BSM550 C Programming Language

CALIFORNIA STATE UNIVERSITY, SACRAMENTO College of Business Administration. MIS Information Systems II. C++ Solution to Homework 4

Intermediate Programming, Spring 2017*

Data Structures (INE2011)

For Teacher's Use Only Q No Total Q No Q No

Tutorial letter 202/2/2018

Object Oriented Programming with C++ (24)

From Pseudcode Algorithms directly to C++ programs

Class Example. student.h file: Declaration of the student template. #ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED

EAS 230 Fall 2002 Section B

Abstract Data Types (ADT) and C++ Classes

SHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) which generates a random number in the range of 0 to n-1. For example;

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs.

Programming Fundamentals II (C++ II) Final Exam June 17 th, Sun, 2007

Physics 6720 I/O Methods October 30, C++ and Unix I/O Streams

Classes: A Deeper Look. Systems Programming

CSCI 1370 APRIL 26, 2017

Object Oriented Programming CS250

Unit-V File operations

Fig. 7.1 Fig. 7.2 Fig. 7.3 Fig. 7.4 Fig. 7.5 Fig. 7.6 Fig. 7.7 Fig. 7.8 Fig. 7.9 Fig. 7.10

I Mid Semester May 2012 : Class XII : Computer Science Max Mark 50 : Time 2 Hrs. 1. a) What is macro in C++? Give example 2

After going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture:

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

Strings and Stream I/O

Chapter 5 Style Requirements

Files. In this lesson you will learn how to create and read files. There are two types of files that we will look at: text files and binary files.

Chapte t r r 9

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

Tackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance. 3.1 Introduction... 2

Come and join us at WebLyceum

Downloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

CSI33 Data Structures

Chapter 10 RECORDS (Structs )

Object Oriented Programming Using C++ UNIT-3 I/O Streams

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Inheritance Examples

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]

Chapter 9. Operator Overloading. Dr Ahmed Rafat

Inheritance and aggregation

9.2 Pointer Variables. Pointer Variables CS Pointer Variables. Pointer Variables. 9.1 Getting the Address of a. Variable

Object Oriented Programming COP3330 / CGS5409

CS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

Functions, Arrays & Structs

Computer Programming Class Members 9 th Lecture

C++ Structures Programming Workshop 2 (CSCI 1061U)

DELHI PUBLIC SCHOOL TAPI

G52CPP C++ Programming Lecture 17

Constructors.

C++ STREAMS; INHERITANCE AS

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV

Collected By Anonymous

IS 0020 Program Design and Software Tools

Programming. C++ Basics

2. It is possible for a structure variable to be a member of another structure variable.

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Grades. Notes (by question) Score Num Students Approx Grade A 90s 7 A 80s 20 B 70s 9 C 60s 9 C

Java Programming Lecture 7

struct Definition Structure Declaration (7.1) Chapter 7 - Introduction to Classes and Objects

ENGI 1020 Introduction to Computer Programming R E Z A S H A H I D I J U L Y 2 6,

Practice problem on defining and using Class types. Part 4.

AN OVERVIEW OF C++ 1

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

Constructors and Destructors. Chapter 6

Classes and Objects. Instructor: 小黑

Streams. Rupesh Nasre.

C ++ Programming for C Programmers

Unit 3. C++ Language II. Takayuki Dan Kimura. Unbounded Queue. Extension of Queue Data Type. Static Members. Base and Derived Classes (Inheritance)


Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

CS105 C++ Lecture 7. More on Classes, Inheritance

Zimmer/Porter CSCI130 Fall Lab 6 Selection. 1. Begin by copying the file from my directory into your account (name it lab6.

11/28/11. Structures. structs. struct Definition. Chapter 11. structs store a collection of data elements of different data types

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013

Constructors & Destructors

Chapter 3: Input/Output

CS201 Some Important Definitions

2 2

C++ 8. Constructors and Destructors

UEE1303(1070) S12: Object-Oriented Programming Operator Overloading and Function Overloading

IS 0020 Program Design and Software Tools

Searching Algorithms. Chapter 11

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks)

第三章习题答案 // include definition of class GradeBook from GradeBook.h #include "GradeBook.h"

Function Overloading

Study Material for Class XII. Data File Handling

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

Object Oriented Programming

Spring 2008 Data Structures (CS301) LAB

Transcription:

1 //employee.h #include <fstream.h> Sheet 3 #include <iostream.h> #include <string.h> #include <stdlib.h> const float PAYRATE_MIN = 0.0; const float PAYRATE_MAX = 50.0; const float HOURS_MIN = 0.0; const float HOURS_MAX = 60.0; class Employee public: //constructors Employee() Employee(char * eid); Employee(char * eid, char * name, float rate, float hours); ~Employee() //member methods char * GetId() ; char * GetLastName() ; float GetPayRate() const ; float GetHours() const; void SetHours(float hours); void SetPayRate(float rate); float CalcGrossPay(); void Validation(ifstream & in); //operator overloading friend ifstream & operator>> (ifstream & in, Employee & e ); friend ofstream & operator<< (ofstream & out, Employee & e); private: //private members char id[30] ; char lastname[30]; float payrate ; float hoursworked; ; //employee.cpp #include "employee.h" //implementation of constructor that initialize the private members Employee::Employee(char * eid, char * name, float rate, float hours) strcpy(id,eid); strcpy(lastname,name); payrate = rate; hoursworked = hours; Employee::Employee(char * eid)

2 strcpy(id,eid); strcpy(lastname,""); payrate = 0; hoursworked = 0; //methods that return the values of the student //get employee id char * Employee::GetId() return id; //get employee last name char * Employee::GetLastName() return lastname; //get employee pay rate float Employee::GetPayRate() const return payrate; //get employee worked hours float Employee::GetHours() const return hoursworked ; //two methods to set pay rate and hours void Employee::SetPayRate(float rate) if(rate >= PAYRATE_MIN && rate <= PAYRATE_MAX) payrate = rate; payrate = 0; void Employee::SetHours(float hours) if(hours >= HOURS_MIN && hours <= HOURS_MAX) hoursworked = hours; hoursworked = 0; float Employee::CalcGrossPay() return payrate * hoursworked ; void Employee::Validation(ifstream & in) int count; int j; int test = 0; //read number of records in>>count; ofstream outvalid("outputvalidation.txt");

3 char id[30]; char name[30]; char pay[30]; char hours[30]; while(hours[j]!='\0') if((int)hours[j] >=65) // A for(int i=0 ; i<count ; i++) test=0; //read each time one record in>>id>>name>>pay>>hours; //case one if invalid id while(id[j]!= '\0') if((int)id[j] >=65) // A outvalid<<"invalid Employee Id: "; //case two if invalid hours outvalid<<"invalid Hours Worked: "; //case three if invalid payrate while(pay[j]!='\0') if((int)pay[j] >=65) // A outvalid<<"invalid Pay Rate: ";

4 //case four if mising name while(name[j]!='\0') if((int)(name[j]) <65) outvalid<<"missing Last Name: "; //check if the rate or hours are not in the appropirate value if(rate >= PAYRATE_MIN && rate <= PAYRATE_MAX) e.payrate = rate; e.payrate = 0; if(hours >= HOURS_MIN && hours <= HOURS_MAX) return in; e.hoursworked = hours; e.hoursworked = 0; // overloading operator << to write the employee information into file ofstream & operator<< (ofstream & out, Employee & e) out<<"id= "<<e.id<<" "; out<<"last Name: "<<e.lastname<<" "; //operators overloading // overloading operator >> to read the employee information from file ifstream & operator>> (ifstream & in, Employee & e ) float rate, hours; in>>e.id>>e.lastname>>rate>>hours; "; out<<"pay Rate= "<<e.payrate<<" out<<"hours Worked= "<<e.hoursworked<<endl; //main.cpp return out; #include "employee.h"

5 void main() in>>employee2; Employee employee1; out<<employee2; Employee employee2("1000"); Employee employee3("1000", "Jonson", 30.5, 55.0); int employeesnumber; //Return GrossRate and PayRate formatted cout<<"1-"; cout<<"pay Rate for Jonsone: "; cout<<employee3.getpayrate(); cout<<"\n"; cout<<"2-write Records in output file done"; cout<<"\n\n\n"; //Validation Part and Write it in validation.txt employee2.validation(invalid); cout<<"3-validation Done"<<"\n\n\n"; cout<<"grossrate for Jonsone: "; cout<<employee3.calcgrosspay(); cout<<"\n\n\n"; //Read Records from Input File and Write them in Output File Organized //define input and output streams to read and write ifstream in("input.txt",ios::in); ofstream out("output.txt",ios::out); ifstream invalid("inputvalidation.txt",ios::in); //read number of employees in>>employeesnumber; //for loop to read each record and file i++) //write it in well formated in output for(int i=0 ; i<employeesnumber ;