« Home « Chủ đề lập trình website

Chủ đề : lập trình website


Có 180+ tài liệu thuộc chủ đề "lập trình website"

A Complete Guide to Programming in C++ part 57

tailieu.vn

The class hierarchy representing a supermarket chain’s checkout system comprises the base class Product and the derived classes PrepackedFood and FreshFood .Your job is to test various cast techniques for this class (see also Exercise 3 in Chapter 23).. Define a global function isLowerCode() that determines which one of two products has the lower barcode and returns a reference to...

A Complete Guide to Programming in C++ part 58

tailieu.vn

Dynamically created objects in a class hierarchy are normally handled by a base class pointer. What does this mean for objects in derived classes? The destructor of the derived class is called first and then the destructor of the base class executed.. If you use a base class pointer to manage an object, the appropriate virtual methods of the derived...

A Complete Guide to Programming in C++ part 59

tailieu.vn

#include "car.h". bool insert(const string&. tp, bool sr, long n, const string&. long n, const string&. #include "city.h". bool CityCar::insert(const string&. carExpress.insert("A-class", true Mercedes");. <<. carExpress.insert(a, t, n, prod);. cout <<. void getPassCar(string&. n, string&. Product(long b = 0L, const string&. #include "product.h". Coworker.h: Defining the abstract class Coworker.. Coworker( const string&. const string&. void setName( const string&. The virtual...

A Complete Guide to Programming in C++ part 60

tailieu.vn

If a class comprises pure virtual methods, you cannot create objects of this class type.. The compiler will issue an error message here, as the Coworker class contains the pure virtual method income. When a class is derived from an abstract class, it inherits all the methods the base class contains, particularly the pure virtual methods. If all of these...

A Complete Guide to Programming in C++ part 61

tailieu.vn

BaseEl( Cell* suc = NULL, const string&. void setName(const string&. const string&. s const string&. void setRem(const string&. List.h : Defines the class InhomList. #include "cell.h". Cell* getPrev(const string&. Cell* getPos( const string&. void insertAfter(const string&. s,const string&. void insert(const string&. n, const string&. void erase(const string&. List.cpp : The methods of class InhomList. #include "List.h". Cell *pEl = src.first;....

A Complete Guide to Programming in C++ part 62

tailieu.vn

A class can contain not just one but several different base classes. In this case the class is derived from multiple base classes in a process known as multiple inheritance.. 䊐 The Multiply-Derived Class MotorHome. The opposite page shows the inheritance and definition schemes for the new class. An object of the MotorHome class contains both the members of Car...

A Complete Guide to Programming in C++ part 63

tailieu.vn

Inheritance of public base classes is used.The MotorHome class contains a new data member used to store one value of the CATEGORY type. Change the definition of the PassCar class in the car.h header file to make Car a virtual base class of the PassCar class.. car.h : Definition of base class Car and. car.cpp. motorHome.h : Definition of the...

A Complete Guide to Programming in C++ part 64

tailieu.vn

One of the programmer’s most important tasks is to predict and handle errors. You can judge a program’s quality by the way it uses error-handling techniques to counteract any potential error, although this is by no means easy to achieve.. 䊐 Traditional Error Handling. EXCEPTION HANDLING. Using the throw statement. C++ introduces a new approach to error handling. Exception handling...

A Complete Guide to Programming in C++ part 65

tailieu.vn

䊐 Exception Class Members. When an exception is thrown, the exception object type determines which exception handler will be executed. For this reason, an exception class does not need to have any members.. However, an exception class can contain data members and methods—just like any other class. This makes sense, as locally defined non-static objects are destroyed when an exception...

A Complete Guide to Programming in C++ part 66

tailieu.vn

if( cnt + v.cnt >. max) expand( cnt + v.cnt);. int count = v.cnt. cnt + v.cnt) expand(cnt + v.cnt);. Shift up from arrPtr[i+v.cnt. cnt = cnt + v.cnt;. #include "floatArr.h". cout <<. setw(8) <<. v <<endl;. <<. v[i] <<. cerr <<. "Error in reading.\n". err.getBadIndex() <<. setw(5) <<. w <<. Fraction operator. Fraction&. operator+=(const Fraction&. numerator = a.numerator *...

A Complete Guide to Programming in C++ part 67

tailieu.vn

If you need access to specific infor- mation in such a file, you have to walk through the file from top to tail, and new records are always appended at the end of the file.. To be able to do this, you need to change the current file position explicitly, that is, you need to point the get / put...

A Complete Guide to Programming in C++ part 68

tailieu.vn

This gives rise to the fact that objects in polymorphic class hierarchies contain virtual methods. You must write both the type and the data members of the object to a file.. 䊐 Storing Objects of the Account Hierarchy. The implementation of the read() and write() methods was discussed earlier in Chapter 18, “Fundamentals of File Input and Output,” and is...

A Complete Guide to Programming in C++ part 69

tailieu.vn

A hash file is required for speed of access to customer data.The concept of hash files is explained on the opposite page.To keep things simple, each record in the hash file contains only a customer id and a name.The customer id is the key used by the hash function opposite to compute the address of the record. It is also...

A Complete Guide to Programming in C++ part 70

tailieu.vn

index.seekg(0L);. cout <<. endl <<. <<. if( !entry.read(index)) break;. entry.display();. if( !index.eof()). index.clear();. long key;. int size = entry.recordSize. index.seekg(0L, ios::end);. end = index.tellg. entry.read_at(index, mid*size);. key = entry.getKey();. entry.read_at(index, begin * size);. entry.getKey. index.seekg(0, ios::end);. long nr = index.tellg. if(!entry.read_at(index, nr)) throw ReadError(name);. entry.write_at(index, nr + size);. entry.setKey(k). entry.setPos(n. Insert entry.write_at(index, nr + size);. if(!entry.read_at(index, pos)) throw ReadError(name);. long...

A Complete Guide to Programming in C++ part 71

tailieu.vn

kde.setNr(10L). kde.setName("Peter");. kde.setNr(17L). kde.setName("Alexa");. kde.setNr(21L). kde.setNr(15L). kde.setName("Jeany");. This chapter describes advanced uses of pointers.These include pointers to pointers, functions with a variable number of arguments, and pointers to functions.. accSort.cpp: Sorts an array of pointers to accounts. according to the account numbers. #include "account.h". Pointer to the last. pointer in the array.. POINTER TO POINTERS. It is thus possible to...

A Complete Guide to Programming in C++ part 72

tailieu.vn

䊐 Using Pointers to Functions. In C++ the name of a function is a constant pointer to that function. It addresses the machine code for the function. the array name is also a constant pointer to the first array element.. You can save them in an array to form a jump table. A pointer to a function can also be...

A Complete Guide to Programming in C++ part 73

tailieu.vn

cout <<. <<. "\n is being compared.\n\n". size <<. random numbers to be generated.\n";. Random numbers cout <<. "\nSorting starts! Please wait.\n";. time2 - time1 <<. seconds.\n";. seconds.\n". setw(12) <<. matrix.h : Represents dynamic matrices. mat = new Row*[lines];. new Row(cols);. Matrix( const Matrix&. Matrix&. operator=( const Matrix&. const Matrix&. matrix.cpp : Defines methods of class Matrix. #include "matrix.h". mat...

A Complete Guide to Programming in C++ part 74

tailieu.vn

The shift operators <<. and >>. shift the bit pattern of their left operand a certain number of bit positions. In the case of a left shift, 0 bits are padded. x = x <<. In the case of a right shift, 0 bits are padded from the left if the left operand is an unsigned type or has a...

A Complete Guide to Programming in C++ part 75

tailieu.vn

cout <<. <<. Shifting by one bit position.\n";. "\nThe bit pattern of x <<. setw(2) <<. count <<. putbits( x <<. Return, if bit position is invalid mask1 = (1 <<. Shift 1 to position bitnr1 mask2 = (1 <<. C++ allows you to define templates—parameterized families of related functions or classes:. a class template specifies a class definition using...

A Complete Guide to Programming in C++ part 76

tailieu.vn

You can also define templates with multiple parameters like the following class template, Example: template <class U, class V>. Example: template<class T, int n>. The major advantage is that the number of array elements is already known when an object of the template class is instantiated. This simplifies the definition of the stack template. The following expression would thus be...