100% found this document useful (2 votes)
9 views

Object Oriented Programming with C 2 e Second Edition Sahay instant download

The document provides information about various editions and resources related to Object-Oriented Programming (OOP) with C++, including a second edition by Sourav Sahay. It discusses the significance of OOP, its advantages over procedure-oriented programming, and outlines the book's structure, which covers fundamental and advanced C++ concepts. Additionally, it highlights new features in the second edition, such as new chapters and expanded content on data structures and exception handling.

Uploaded by

launaygies
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
9 views

Object Oriented Programming with C 2 e Second Edition Sahay instant download

The document provides information about various editions and resources related to Object-Oriented Programming (OOP) with C++, including a second edition by Sourav Sahay. It discusses the significance of OOP, its advantages over procedure-oriented programming, and outlines the book's structure, which covers fundamental and advanced C++ concepts. Additionally, it highlights new features in the second edition, such as new chapters and expanded content on data structures and exception handling.

Uploaded by

launaygies
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Object Oriented Programming with C 2 e Second

Edition Sahay pdf download

https://ebookgate.com/product/object-oriented-programming-
with-c-2-e-second-edition-sahay/

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Object oriented programming in C 7th print. with


corrections Edition Lafore

https://ebookgate.com/product/object-oriented-programming-in-c-7th-
print-with-corrections-edition-lafore/

ebookgate.com

Object oriented programming with ABAP Objects 1st Edition


James Wood

https://ebookgate.com/product/object-oriented-programming-with-abap-
objects-1st-edition-james-wood/

ebookgate.com

Beginning C 3 0 an introduction to object oriented


programming 1st Edition Jack Purdum

https://ebookgate.com/product/beginning-c-3-0-an-introduction-to-
object-oriented-programming-1st-edition-jack-purdum/

ebookgate.com

Object oriented Analysis And Design Understanding System


Development With UML 2 0 First Edition Mike O'Docherty

https://ebookgate.com/product/object-oriented-analysis-and-design-
understanding-system-development-with-uml-2-0-first-edition-mike-
odocherty/
ebookgate.com
Object Oriented Oracle Wenny Rahayu

https://ebookgate.com/product/object-oriented-oracle-wenny-rahayu/

ebookgate.com

ActionScript 3 0 design patterns object oriented


programming techniques 1st ed Edition William Sanders

https://ebookgate.com/product/actionscript-3-0-design-patterns-object-
oriented-programming-techniques-1st-ed-edition-william-sanders/

ebookgate.com

Programming ArcObjects with VBA a task oriented approach


Chang

https://ebookgate.com/product/programming-arcobjects-with-vba-a-task-
oriented-approach-chang/

ebookgate.com

Programming in Objective C 2. print. with corr., Nachdr.


Edition Kochan

https://ebookgate.com/product/programming-in-objective-c-2-print-with-
corr-nachdr-edition-kochan/

ebookgate.com

The principles of object oriented JavaScript Zakas

https://ebookgate.com/product/the-principles-of-object-oriented-
javascript-zakas/

ebookgate.com
Object Oriented
Programming with
C++
SECOND EDITION

Sourav Sahay
Lead Consultant
Capgemini
Detroit, Michigan

1
3
Oxford University Press is a department of the University of Oxford.
It furthers the University’s objective of excellence in research, scholarship,
and education by publishing worldwide. Oxford is a registered trade mark of
Oxford University Press in the UK and in certain other countries.

Published in India by
Oxford University Press
YMCA Library Building, 1 Jai Singh Road, New Delhi 110001, India

© Oxford University Press 2006, 2012

The moral rights of the author/s have been asserted.

First Edition Published in 2006


Second Edition Published in 2012

All rights reserved. No part of this publication may be reproduced, stored in


a retrieval system, or transmitted, in any form or by any means, without the
prior permission in writing of Oxford University Press, or as expressly permitted
by law, by licence, or under terms agreed with the appropriate reprographics
rights organization. Enquiries concerning reproduction outside the scope of the
above should be sent to the Rights Department, Oxford University Press, at the
address above.

You must not circulate this work in any other form


and you must impose this same condition on any acquirer.

ISBN-13: 978-0-19-806530-2
ISBN-10: 0-19-806530-2

Typeset in Times New Roman


by Recto Graphics, Delhi 110096
Printed in India by Adage Printers (P) Ltd., Noida 201301 U.P.
Preface to the First Edition

C++ made its advent in the early 1980s and enabled programmers to write their programs
the object-oriented way. For this reason, the language quickly gained popularity and became
a programming language of choice. Despite the development of a number of competing
object-oriented languages including Java, C++ has successfully maintained its position of
popularity.
C++ starts where C stops. C++ is a superset of C. All the language features of C language
appear in C++ with little or no modi¿cation. Over and above such features, C++ provides a
number of extra features, which provide the language its object-oriented character.

About the Book

The continued popularity of C++ has led to considerable literature. Innumerable books, journals,
magazines, and articles have been written on C++. So, why another book on C++?
The aim of the book is to thoroughly explain all aspects of the language constructs provided
by C++. While doing full justice to the commonly explained topics of C++, the book does
not neglect the advanced and new concepts of C++ that are not widely taught.
This book is a power-packed instruction guide for Object-Oriented Programming and C++.
The purpose of this book is two-fold:
x To clarify the fundamentals of the Object-Oriented Programming System
x To provide an in-depth treatment of each feature and language construct of C++
This book emphasizes the Object-Oriented Programming System—its bene¿ts and its
superiority over the conventional Procedure-Oriented Programming System.
This book starts directly with C++ since the common features of C and C++ are anyway
covered in books on C language. Each feature of C++ is covered from the practical point of
view. Instead of brief introductions, this book gives an in-depth explanation of the rationale
and proper use of each object-oriented feature of C++.
To help the readers assimilate the large volume of knowledge contained in this book, an
adequate number of example programs, well-designed diagrams, and analogies with the real
world have been given. Some program examples given in this book are abstract in nature to
help readers focus on the concept being discussed.
Preface to the First Edition vii

Acknowledgements
First, I thank my parents for teaching me a number of valuable lessons of life including the
value of hardwork and the value of good education (neither of which I have learnt yet!). I also
thank my wife Madhvi for her patience, her encouragement, and also for having tolerated my
long periods of silence and temper tantrums! Thanks (rather apologies) to my little daughters,
Surabhi and Sakshi, who tolerated Papa’s frequent refusals to take them on outings.
I thank Dr David Mulvaney and Dr Sekharjit Datta of the University of Loughborough for
their valuable guidance, encouragement, and inspiration. My teachers always encouraged me
to think big and to think independently. My sincerest gratitude to each one of them.
The editorial team of Oxford University Press deserves my heartfelt thanks for their
guidance and for their timely reminders about the deadlines I would have de¿nitely missed
otherwise!
Feedback about the book is most welcome. Readers are requested and encouraged to send
their feedback to the author’s mail id sourav1903@yahoo.com.

Sourav Sahay
Preface to the Second Edition

The object-oriented programming system (OOPS) enables a programmer to model real-world


objects. It allows the programmer to add characteristics like data security, data encapsulation,
etc.
In the procedure-oriented programming system, procedures are dissociated from data and
are not a part of it. Instead, they receive structure variables, or their addresses, and then work
upon them. The code design is centered around procedures. While this may sound obvious,
this programming pattern has its drawbacks, a major one being that the data is not secure. It
can be manipulated by any procedure.
It is the lack of data security of the procedure-oriented programming system that led to
OOPS, in which, with the help of a new programming construct and new keywords, associated
functions of the data structure can be given exclusive rights to work upon its variables.
There is another characteristic of real-world objects—a guaranteed initialization of data.
Programming languages that implement OOPS enable library programmers to incorporate this
characteristic of real-world objects into structure variables. Library programmers can ensure
a guaranteed initialization of data members of structure variables to the desired values. For
this, application programmers do not need to write code explicitly.
OOPS further supports the following concepts:
x Inheritance This feature allows a class to inherit the data and function members of an
existing class.
x Data abstraction Data abstraction is a virtue by which an object hides its internal
operations from the rest of the program.
x Modularity This feature supports dividing a program into small segments and implement
those segments using different functions.
x Polymorphism Through polymorphism, functions with different set of formal arguments
can have the same name.
The ¿rst edition had covered the fundamentals of the object oriented programming system
in depth. These explanations in the ¿rst edition hold true for any programming language that
supports OOPS. This second edition enhances coverage, as listed below.

New to this Edition


x New chapter on data structures containing new and original algorithms, especially an
elegant and simple recursive algorithm for inserting nodes into trees. The explanations
are elaborate and full of diagrams.
x New sections on explicit constructors, command line arguments, and re-throwing
exceptions.
iv Preface to the Second Edition

x Expanded glossary.
x Accompanying CD contains all the program codes given in the text.

Key Features
x Simple and concise language eases the understanding of complex concepts that have
made C++ powerful but enigmatic.
x Plenty of solved examples with complete program listings and test cases to reinforce
learning.
x Review questions and program writing exercises at the end of each chapter to provide
additional practice.
x Self-tests at the end of the book to prepare the students for examinations.

Organization of the Book


A brief knowledge of C language is a prerequisite for this book. The readers need to know
how programs are written in C, data types, decision-making and looping constructs, operators,
functions, header ¿les, pointers, and structures.
Chapter 1 contains an explanation of the procedure-oriented programming system, the
role played by structures in this system, its drawbacks and how these drawbacks led to the
creation of OOPS. The meaning and method of modelling real-world objects by the object-
oriented programming system have been clearly explained. The chapter includes a study of
the non-object-oriented features of C++.
Chapter 2 is devoted to the study of objects and classes. It gives a thorough explanation
of the class construct of C++. Superiority of the class construct of C++ over the structure
construct of C language is explained. A description of the various types and features of member
functions and member data is included. Other concepts included are namespaces, arrays of
objects, arrays in objects, and nested classes.
Chapter 3 deals with dynamic memory management. It explains the use of the new and the
delete operators. It also explains the method of specifying our own new handler for handling
out-of-memory conditions.
Chapter 4 explains constructors and destructors. It discusses their importance, their features,
and the method of de¿ning them.
Chapter 5 is devoted to inheritance. Concepts like base class, derived class, base class
pointer, and derived class pointer are covered. The protected keyword and the implications
of deriving by different access speci¿ers are explained. This chapter describes various types
of inheritance.
Chapter 6 gives a detailed explanation of one of the most striking features of C++—
dynamic polymorphism. This chapter describes the virtual functions and how it enables C++
programmers to extend class libraries. The importance of pure virtual functions and clone
functions is also explained.
Chapter 7 describes the standard C++ library for handling streams. It explains the two
types of input and output—text mode and binary mode. Input and output from disk ¿les are
explained. The chapter also describes the use of error-handling routines of the standard C++
stream library and manipulators.
Chapter 8 is devoted to operator overloading, type conversion, new style casts, and RTTI.
This chapter explains the various intricacies and the proper use of operator overloading.
This chapter also explains how a C++ programmer can implement conventional style type
Preface to the Second Edition v

conversions. New style casts for implementing type conversions are explained next. This
chapter ends with a treatment of run time type information (RTTI).
Chapter 9 explains and illustrates the most important data structures—linked lists and trees.
It includes full-Àedged programs that can be used to create various data structures.
Chapter 10 contains a detailed description of templates. The importance of function
templates and class templates and their utilization in code reuse is explained. This chapter
also provides an overview of the Standard Template Library (STL) of C++.
Chapter 11 explains the concept of exception handling. It begins with a section on
conventional methods and their drawbacks. This is followed by an explanation of the try-catch-
throw mechanism provided by C++ and its superiority over the conventional methods.
The appendices in the book include a case study, comparison of C++ with C, comparison
of C++ with Java, an overview of object-oriented analysis and design, and self tests.

Acknowledgements
The blessings of my parents continue to give me the courage I need to overcome the obstacles
that are associated with dif¿cult ventures like writing books. Every achievement of my life,
including this book, is because of the valuable education they gave me early in my life. Thanks
to my wife Madhvi against whose wishes I decided to spend most of the weekends over the
last 2 years on my laptop writing this edition. My daughters Surabhi and Sakshi continue to
inspire and motivate me.
Thanks to Professor Shanmuka Swamy, Assistant Professor in the Sridevi Institute of
Engineering and Technology, Tumkur, for pointing out a couple of printing mistakes in the
¿rst edition. These have been corrected.
The editorial staff members of the Oxford University Press deserve a special mention for
its support and prompt responses.
Please continue to send your valuable feedback and questions to my e-mail id
sourav1903@yahoo.com.
Sourav Sahay
Brief Contents

Preface to the Second Edition iii

Preface to the First Edition vi

Detailed Contents xi

1. Introduction to C++ 1
2. Classes and Objects 31
3. Dynamic Memory Management 78
4. Constructors and Destructors 92
5. Inheritance 117
6. Virtual Functions and Dynamic Polymorphism 153
7. Stream and File Handling 172
8. Operator Overloading, Type Conversion, New Style Casts, and RTTI 211
9. Data Structures 283
10. Templates 372
11. Exception Handling 393

Appendix A: Case Study—A Word Query System 417


Appendix B: Comparison of C++ with C 425
Appendix C: Comparison of C++ with Java 427
Appendix D: Object-Oriented Analysis and Design 437
Appendix E: Glossary 449
Appendix F: Self Tests 454

Bibliography 460

Index 461
Detailed Contents

Preface to the Second Edition iii


Preface to the First Edition vi
Brief Contents ix

1. Introduction to C++ 1
1.1 A Review of Structures 1
1.1.1 The Need for Structures 1
1.1.2 Creating a New Data Type Using Structures 4
1.1.3 Using Structures in Application Programs 5
1.2 Procedure-Oriented Programming Systems 5
1.3 Object-Oriented Programming Systems 7
1.4 Comparison of C++ with C 8
1.5 Console Input/Output in C++ 9
1.5.1 Console Output 9
1.5.2 Console Input 12
1.6 Variables in C++ 13
1.7 Reference Variables in C++ 14
1.8 Function Prototyping 19
1.9 Function Overloading 21
1.10 Default Values for Formal Arguments of Functions 23
1.11 Inline Functions 25

2. Classes and Objects 31


2.1 Introduction to Classes and Objects 31
2.1.1 Private and Public Members 33
2.1.2 Objects 36
2.1.3 Scope Resolution Operator 37
2.1.4 Creating Libraries Using the Scope Resolution Operator 38
2.1.5 Using Classes in Application Programs 39
2.1.6 this Pointer 40
2.1.7 Data Abstraction 45
2.1.8 Explicit Address Manipulation 47
2.1.9 Arrow Operator 47
2.1.10 Calling One Member Function from Another 48
xii Detailed Contents

2.2 Member Functions and Member Data 49


2.2.1 Overloaded Member Functions 49
2.2.2 Default Values for Formal Arguments of Member Functions 51
2.2.3 Inline Member Functions 52
2.2.4 Constant Member Functions 52
2.2.5 Mutable Data Members 54
2.2.6 Friends 54
2.2.7 Static Members 59
2.3 Objects and Functions 65
2.4 Objects and Arrays 66
2.4.1 Arrays of Objects 67
2.4.2 Arrays Inside Objects 67
2.5 Namespaces 68
2.6 Nested Inner Classes 71

3. Dynamic Memory Management 78


3.1 Introduction 78
3.2 Dynamic Memory Allocation 79
3.3 Dynamic Memory Deallocation 84
3.4 set_new_handler() function 88

4. Constructors and Destructors 92


4.1 Constructors 92
4.1.1 Zero-argument Constructor 94
4.1.2 Parameterized Constructors 97
4.1.3 Explicit Constructors 103
4.1.4 Copy Constructor 105
4.2 Destructors 109
4.3 Philosophy of OOPS 112

5. Inheritance 117
5.1 Introduction 117
5.1.1 Effects of Inheritance 118
5.1.2 Bene¿ts of Inheritance 120
5.1.3 Inheritance in Actual Practice 120
5.1.4 Base Class and Derived Class Objects 121
5.1.5 Accessing Members of the Base Class in the Derived Class 121
5.2 Base Class and Derived Class Pointers 122
5.3 Function Overriding 127
5.4 Base Class Initialization 129
5.5 Protected Access Speci¿er 132
5.6 Deriving by Different Access Speci¿ers 133
5.6.1 Deriving by the Public Access Speci¿er 133
5.6.2 Deriving by the Protected Access Speci¿er 135
5.6.3 Deriving by the Private Access Speci¿er 136
5.7 Different Kinds of Inheritance 139
5.7.1 Multiple Inheritance 139
5.7.2 Ambiguities in Multiple Inheritance 141
Detailed Contents xiii

5.7.3 Multi-level Inheritance 145


5.7.4 Hierarchical Inheritance 147
5.7.5 Hybrid Inheritance 148
5.8 Order of Invocation of Constructors and Destructors 149

6. Virtual Functions and Dynamic Polymorphism 153


6.1 Need for Virtual Functions 153
6.2 Virtual Functions 156
6.3 Mechanism of Virtual Functions 160
6.4 Pure Virtual Functions 162
6.5 Virtual Destructors and Virtual Constructors 167
6.5.1 Virtual Destructors 167
6.5.2 Virtual Constructors 168

7. Stream and File Handling 172


7.1 Streams 172
7.2 Class Hierarchy for Handling Streams 172
7.3 Text and Binary Input/Output 174
7.3.1 Data Storage in Memory 174
7.3.2 Input/Output of Character Data 175
7.3.3 Input/Output of Numeric Data 175
7.3.4 Note on Opening Disk Files for I/O 176
7.4 Text Versus Binary Files 176
7.5 Text Output/Input 177
7.5.1 Text Output 177
7.5.2 Text Input 181
7.6 Binary Output/Input 185
7.6.1 Binary Output—write() Function 185
7.6.2 Binary Input—read() Function 189
7.7 Opening and Closing Files 193
7.7.1 open() Function 193
7.7.2 close() Function 194
7.8 Files as Objects of the fstream Class 194
7.9 File Pointers 194
7.9.1 seekp() Function 195
7.9.2 tellp() Function 196
7.9.3 seekg() Function 196
7.9.4 tellg() Function 196
7.10 Random Access to Files 197
7.11 Object Input/Output Through Member Functions 197
7.12 Error Handling 199
7.12.1 eof() Function 199
7.12.2 fail() Function 199
7.12.3 bad() Function 200
7.12.4 clear() Function 200
7.13 Manipulators 201
7.13.1 Pre-de¿ned Manipulators 201
xiv Detailed Contents

7.13.2 User-de¿ned Manipulators 203


7.14 Command Line Arguments 204

8. Operator Overloading, Type Conversion, New Style Casts, and RTTI 211
8.1 Operator Overloading 211
8.1.1 Overloading Operators—The Syntax 212
8.1.2 Compiler Interpretation of Operator-Overloading Functions 214
8.1.3 Overview of Overloading Unary and Binary Operators 216
8.1.4 Operator Overloading 216
8.1.5 Rules for Operator Overloading 219
8.2 Overloading Various Operators 221
8.2.1 Overloading Increment and Decrement Operators
(Pre¿x and Post¿x) 221
8.2.2 Overloading Unary Minus and Unary Plus Operator 224
8.2.3 Overloading Arithmetic Operators 225
8.2.4 Overloading Relational Operators 230
8.2.5 Overloading Assignment Operator 234
8.2.6 Overloading Insertion and Extraction Operators 240
8.2.7 Overloading new and delete Operators 244
8.2.8 Overloading Subscript Operator 261
8.2.9 Overloading Pointer-to-member (->) Operator (Smart Pointer) 265
8.3 Type Conversion 267
8.3.1 Basic Type to Class Type 267
8.3.2 Class Type to Basic Type 268
8.3.3 Class Type to Class Type 269
8.4 New Style Casts and the typeid Operator 271
8.4.1 dynamic_cast Operator 271
8.4.2 static_cast Operator 275
8.4.3 reinterpret_cast Operator 276
8.4.4 const_cast Operator 276
8.4.5 typeid Operator 277

9. Data Structures 283


9.1 Introduction 283
9.2 Linked Lists 284
9.3 Stacks 336
9.4 Queues 340
9.5 Trees 343
9.5.1 Binary Trees 344
9.5.2 Binary Search Trees 347

10. Templates 372


10.1 Introduction 372
10.2 Function Templates 373
10.3 Class Templates 378
10.3.1 Nested Class Templates 382
10.4 Standard Template Library 382
10.4.1 list Class 383
Detailed Contents xv

10.4.2 vector Class 386


10.4.3 pair Class 387
10.4.4 map Class 387
10.4.5 set Class 389
10.4.6 multimap Class 389
10.4.7 multiset Class 390

11. Exception Handling 393


11.1 Introduction 393
11.2 C-Style Handling of Error-generating Code 394
11.2.1 Terminate the Program 394
11.2.2 Check the Parameters before Function Call 395
11.2.3 Return a Value Representing an Error 396
11.3 C++-Style Solution—the try/throw/catch Construct 397
11.3.1 It is Necessary to Catch Exceptions 400
11.3.2 Unwinding of the Stack 401
11.3.3 Need to Throw Class Objects 404
11.3.4 Accessing the Thrown Object in the Catch Block 406
11.3.5 Throwing Parameterized Objects of a Nested Exception Class 408
11.3.6 Catching Uncaught Exceptions 409
11.3.7 Re-throwing Exceptions 410
11.4 Limitation of Exception Handling 414

Appendix A: Case Study—A Word Query System 417


Problem Statement 417
A Sample Run 417
The Source Code 418
Explanation of the Code 420

Appendix B: Comparison of C++ with C 425


Non-object-oriented Features Provided in C++ that are Absent in C
Language 425
Object-oriented Features Provided in C++ to make it Comply with the
Requirements of the Object-Oriented Programming System 426

Appendix C: Comparison of C++ with Java 427


C.1 Similarities between C++ and Java 427
C.2 Differences between C++ and Java 428

Appendix D: Object-Oriented Analysis and Design 437


D.1 Introduction 437
Why Build Models? 437
Overview of OOAD 437
D.2 Object-Oriented Model 438
Object Model 438
Dynamic Model 442
Functional Model 444
D.3 Analysis 446
xvi Detailed Contents

Overview of Analysis 446


Object Modelling 446
Dynamic Modelling 446
Functional Modelling 447
D.4 System Design 447
Breaking the System into Sub-systems 447
Layers 447
Partitions 447
D.5 Object Design 448
Overview of Object Design 448
D.6 Implementation 448

Appendix E: Glossary 449

Appendix F: Self Tests 454


Test 1 454
Test 2 456
Test 3 458

Bibliography 460

Index 461
1 Introduction to C++

O This chapter introduces the reader to the fundamentals of object-oriented programming systems
(OOPS).
V The chapter begins with an overview of structures, the reasons for their inclusion as a
E language construct in C language, and their role in procedure-oriented programming systems.
Use of structures for creating new data types is described. Also, the drawbacks of structures
R and the development of OOPS are elucidated.
The middle section of the chapter explains OOPS, supplemented with suitable examples
V and analogies to help in understanding this tricky subject.
I The concluding section of the chapter includes a study of a number of new features that are
implemented by C++ compilers but do not fall under the category of object-oriented features.
E (Language constructs of C++ that implement object-oriented features are dealt with in the
W next chapter.)

1.1 A Review of Structures


In order to understand procedure-oriented programming systems, let us ¿rst recapitulate our
understanding of structures in C. Let us review their necessity and use in creating new data
types.

1.1.1 The Need for Structures


There are cases where the value of one variable depends upon that of another variable.
Take the example of date. A date can be programmatically represented in C by three
different integer variables taken together. Say,
int d,m,y; //three integers for representing dates

Here ‘d’, ‘m’, and ‘y’ represent the day of the month, the month, and the year, respectively.
Observe carefully. Although these three variables are not grouped together in the code, they
actually belong to the same group. The value of one variable may inÀuence the value of the
other two. In order to understand this clearly, consider a function next_day() that accepts
the addresses of the three integers that represent a date and changes their values to represent
the next day. The prototype of this function will be
void next_day(int *,int *,int *); //function to calculate
//the next day
2 Object-Oriented Programming with C++

Suppose,
d=1;
m=1;
y=2002; //1st January, 2002

Now, if we write
next_day(&d,&m,&y);

‘d’ will become 2, ‘m’ will remain 1, and ‘y’ will remain 2002.
But if
d=28;
m=2;
y=1999; //28th February, 1999

and we call the function as


next_day(&d,&m,&y);

‘d’ will become 1, ‘m’ will become 3, and ‘y’ will remain 1999.
Again, if
d=31;
m=12;
y=1999; //31st December, 1999

and we call the function as


next_day(&d,&m,&y);

‘d’ will become 1, ‘m’ will become 1, and ‘y’ will become 2000.
As you can see, ‘d’, ‘m’, and ‘y’ actually belong to the same group. A change in the value
of one may change the value of the other two. But there is no language construct that actually
places them in the same group. Thus, members of the wrong group may be accidentally sent
to the function (Listing 1.1)!

Listing 1.1 Problem in passing groups of programmatically independent but logically


dependent variable
d1=28; m1=2; y1=1999; //28th February, 1999
d2=19; m2=3; y2=1999; //19th March, 1999
next_day(&d1,&m1,&y1); //OK
next_day(&d1,&m2,&y2); //What? Incorrect set passed!

As can be observed in Listing 1.1, there is nothing in the language itself that prevents the
wrong set of variables from being sent to the function. Moreover, integer-type variables that
are not meant to represent dates might also be sent to the function!
Let us try arrays to solve the problem. Suppose the next_day() function accepts an array
as a parameter. Its prototype will be
void next_day(int *);

Let us declare date as an array of three integers.


int date[3];
date[0]=28;
date[1]=2;
date[2]=1999; //28th February, 1999
Introduction to C++ 3

Now, let us call the function as follows:


next_day(date);

The values of ‘date[0]’, ‘date[1]’, and ‘date[2]’ will be correctly set to 1, 3, and 1999,
respectively. Although this method seems to work, it certainly appears unconvincing. After
all any integer array can be passed to the function, even if it does not necessarily represent
a date. There is no data type of date itself. Moreover, this solution of arrays will not work if
the variables are not of the same type. The solution to this problem is to create a data type
called date itself using structures
struct date //a structure to represent dates
{
int d, m, y;
};

Now, the next_day() function will accept the address of a variable of the structure date
as a parameter. Accordingly, its prototype will be as follows:
void next_day(struct date *);

Let us now call it as shown in Listing 1.2.

Listing 1.2 The need for structures

struct date d1;


d1.d=28;
d1.m=2;
d1.y=1999;
next_day(&d1);

‘d1.d’, ‘d1.m’, and ‘d1.y’ will be correctly set to 1, 3, and 1999, respectively. Since the
function takes the address of an entire structure variable as a parameter at a time, there is no
chance of variables of the different groups being sent to the function.
Structure is a programming construct in C that allows us to put together variables that
should be together.
Library programmers use structures to create new data types. Application programs and
other library programs use these new data types by declaring variables of this data type.
struct date d1;

They call the associated functions by passing these variables or their addresses to them.
d1.d=31;
d1.m=12;
d1.y=2003;
next_day(&d1);

Finally, they use the resultant value of the passed variable further as per requirements.
printf(“The next day is: %d/%d/%d\n”, d1.d, d1.m, d1.y);

Output
The next day is: 01/01/2004
4 Object-Oriented Programming with C++

1.1.2 Creating a New Data Type Using Structures


Creation of a new data type using structures is loosely a three-step process that is executed
by the library programmer.
Step 1: Put the structure de¿nition and the prototypes of the associated functions in a header
¿le, as shown in Listing 1.3.
Listing 1.3 Header file containing definition of a structure variable and prototypes of its
associated functions
/*Beginning of date.h*/
/*This file contains the structure definition and
prototypes of its associated functions*/
struct date
{
int d,m,y;
};
void next_day(struct date *); //get the next date
void get_sys_date(struct date *); //get the current
//system date
/*
Prototypes of other useful and relevant functions to
work upon variables of the date structure
*/
/*End of date.h*/

Step 2: As shown in Listing 1.4, put the de¿nition of the associated functions in a source
code and create a library.

Listing 1.4 Defining the associated functions of a structure

/*Beginning of date.c*/
/*This file contains the definitions of the associated
functions*/
#include “date.h”
void next_day(struct date * p)
{
//calculate the date that immediately follows the one
//represented by *p and set it to *p.
}
void get_sys_date(struct date * p)
{
//determine the current system date and set it to *p
}
/*
Definitions of other useful and relevant functions to work upon variables
of the date structure
*/
/*End of date.c*/

Step 3: Provide the header ¿le and the library, in whatever media, to other programmers who
want to use this new data type.
Creation of a structure and creation of its associated functions are two separate steps that
together constitute one complete process.
Introduction to C++ 5

1.1.3 Using Structures in Application Programs


The steps to use this new data type are as follows:
Step 1: Include the header ¿le provided by the library programmer in the source code.
/*Beginning of dateUser.c*/
#include“date.h”
void main( )
{
. . . .
. . . .
}
/*End of dateUser.c*/

Step 2: Declare variables of the new data type in the source code.
/*Beginning of dateUser.c*/
#include“date.h”
void main( )
{
struct date d;
. . . .
. . . .
}
/*End of dateUser.c*/

Step 3: As shown in Listing 1.5, embed calls to the associated functions by passing these
variables in the source code.

Listing 1.5 Using a structure in an application program

/*Beginning of dateUser.c*/
#include“date.h”
void main()
{
struct date d;
d.d=28;
d.m=2;
d.y=1999;
next_day(&d);
. . . .
. . . .
}
/*End of dateUser.c*/

Step 4: Compile the source code to get the object ¿le.


Step 5: Link the object ¿le with the library provided by the library programmer to get the
executable or another library.

1.2 Procedure-Oriented Programming Systems


In light of the previous discussion, let us understand the procedure-oriented programming
system. The foregoing pattern of programming divides the code into functions. Data (contained
in structure variables) is passed from one function to another to be read from or written into.
The focus is on procedures. This programming pattern is, therefore, a feature of the procedure-
oriented programming system.
6 Object-Oriented Programming with C++

In the procedure-oriented programming system, procedures are dissociated from data and
are not a part of it. Instead, they receive structure variables or their addresses and work upon
them. The code design is centered around procedures. While this may sound obvious, this
programming pattern has its drawbacks.
The drawback with this programming pattern is that the data is not secure. It can be
manipulated by any procedure. Associated functions that were designed by the library
programmer do not have the exclusive rights to work upon the data. They are not a part of
the structure de¿nition itself. Let us see why this is a problem.
Suppose the library programmer has de¿ned a structure and its associated functions as
described above. Further, in order to perfect his/her creation, he/she has rigorously tested
the associated functions by calling them from small test applications. Despite his/her best
efforts, he/she cannot be sure that an application that uses the structure will be bug free. The
application program might modify the structure variables, not by the associated function he/
she has created, but by some code inadvertently written in the application program itself.
Compilers that implement the procedure-oriented programming system do not prevent
unauthorized functions from accessing/manipulating structure variables.
Now, let us look at the situation from the application programmer’s point of view. Consider
an application of around 25,000 lines (quite common in the real programming world), in
which variables of this structure have been used quite extensively. During testing, it is found
that the date being represented by one of these variables has become 29th February 1999!
The faulty piece of code that is causing this bug can be anywhere in the program. Therefore,
debugging will involve a visual inspection of the entire code (of 25000 lines!) and will not
be limited to the associated functions only.
The situation becomes especially grave if the execution of the code that is likely to corrupt
the data is conditional. For example,
if(<some condition>)
d.m++; //d is a variable of date structure… d.m may
//become 13!

The condition under which the bug-infested code executes may not arise during testing.
While distributing his/her application, the application programmer cannot be sure that it would
run successfully. Moreover, every new piece of code that accesses structure variables will
have to be visually inspected and tested again to ensure that it does not corrupt the members
of the structure. After all, compilers that implement procedure-oriented programming systems
do not prevent unauthorized functions from accessing/manipulating structure variables.
Let us think of a compiler that enables the library programmer to assign exclusive rights to
the associated functions for accessing the data members of the corresponding structure. If this
happens, then our problem is solved. If a function which is not one of the intended associated
functions accesses the data members of a structure variable, a compile-time error will result.
To ensure a successful compile of his/her application code, the application programmer will
be forced to remove those statements that access data members of structure variables. Thus,
the application that arises out of a successful compile will be the outcome of a piece of code
that is free of any unauthorized access to the data members of the structure variables used
therein. Consequently, if a run-time error arises, attention can be focused on the associated
library functions.
It is the lack of data security of procedure-oriented programming systems that led to object-
oriented programming systems (OOPS). This new system of programming is the subject of
our next discussion.
Introduction to C++ 7

1.3 Object-Oriented Programming Systems


In OOPS, we try to model real-world objects. But, what are real-world objects? Most real-
world objects have internal parts and interfaces that enable us to operate them. These interfaces
perfectly manipulate the internal parts of the objects. They also have the exclusive rights to
do so.
Let us understand this concept with the help of an example. Take the case of a simple
LCD projector (a real-world object). It has a fan and a lamp. There are two switches—one to
operate the fan and the other to operate the lamp. However, the operation of these switches is
necessarily governed by rules. If the lamp is switched on, the fan should automatically switch
itself on. Otherwise, the LCD projector will get damaged. For the same reason, the lamp should
automatically get switched off if the fan is switched off. In order to cater to these conditions,
the switches are suitably linked with each other. The interface to the LCD projector is perfect.
Further, this interface has the exclusive rights to operate the lamp and fan.
This, in fact, is a common characteristic of all real-world objects. If a perfect interface is
required to work on an object, it will also have exclusive rights to do so.
Coming back to C++ programming, we notice a resemblance between the observed
behaviour of the LCD projector and the desired behaviour of data structure’s variables. In
OOPS, with the help of a new programming construct and new keywords, associated functions
of the data structure can be given exclusive rights to work upon its variables. In other words,
all other pieces of code can be prevented from accessing the data members of the variables
of this structure.
Compilers that implement OOPS enable data security by diligently enforcing this
prohibition. They do this by throwing compile-time errors against pieces of code that violate
the prohibition. This prohibition, if enforced, will make structure variables behave like real-
world objects. Associated functions that are de¿ned to perfectly manipulate structure variables
can be given exclusive rights to do so.
There is still another characteristic of real-world objects—a guaranteed initialization of
data. After all, when you connect the LCD projector to the mains, it does not start up in an
invalid state (fan off and lamp on). By default, either both the lamp and the fan are off or
both are on. Users of the LCD projector need not do this explicitly. The same characteristic
is found in all real-world objects.
Programming languages that implement OOPS enable library programmers to incorporate
this characteristic of real-world objects into structure variables. Library programmers can
ensure a guaranteed initialization of data members of structure variables to the desired values.
For this, application programmers do not need to write code explicitly.
Two more features are incidental to OOPS. They are:
x Inheritance
x Polymorphism
Inheritance allows one structure to inherit the characteristics of an existing structure.
As we know from our knowledge of structures, a variable of the new structure will contain
data members mentioned in the new structure’s de¿nition. However, because of inheritance,
it will also contain data members mentioned in the existing structure’s de¿nition from which
the new structure has inherited.
Further, associated functions of the new structure can work upon a variable of the new
structure. For this, the address/name of a variable of the new structure is passed to the associated
functions of the new structure. Again, as a result of inheritance, associated functions of the
existing structure from which the new structure has inherited will also be able to work upon
8 Object-Oriented Programming with C++

a variable of the new structure. For this, the address/name of a variable of the new structure
is passed to the associated functions of the existing structure.
In inheritance, data and interface may both be inherited. This is expected as data and
interface complement each other. The parent structure can be given the general common
characteristics while its child structures can be given the more speci¿c characteristics. This
allows code reusability by keeping the common code in a common place—the base structure.
Otherwise, the code would have to be replicated in all of the child structures, which will
lead to maintenance nightmares. Inheritance also enables code extensibility by allowing
the creation of new structures that are better suited to our requirements as compared to the
existing structures.
Polymorphism, as the name suggests, is the phenomena by virtue of which the same entity
can exist in two or more forms. In OOPS, functions can be made to exhibit polymorphic
behaviour. Functions with different set of formal arguments can have the same name.
Polymorphism is of two types: static and dynamic. We will understand how this feature enables
C++ programmers to reuse and extend existing code in the subsequent chapters.

1.4 Comparison of C++ with C


C++ is an extension of C language. It is a proper superset of C language. This means that
a C++ compiler can compile programs written in C language. However, the reverse is not
true. A C++ compiler can understand all the keywords that a C compiler can understand.
Again, the reverse is not true. Decision-making constructs, looping constructs, structures,
functions, etc. are written in exactly the same way in C++ as they are in C language. Apart
from the keywords that implement these common programming constructs, C++ provides
a number of additional keywords and language constructs that enable it to implement the
object-oriented paradigm.
The header ¿le given in Listing 1.6 shows how the structure Date, which has been our
running example so far, can be rewritten in C++.
Listing 1.6 Redefining the Date structure in C++

/*Beginning of Date.h*/
class Date //class instead of structure
{
private:
int d,m,y;
public:
Date();
void get_sys_date(); //associated functions appear
//within the class definition
void next_day();
};
/*End of Date.h*/

The following differences can be noticed between Date structure in C (Listing 1.3) and C++
(Listing 1.6):
x The keyword class has been used instead of struct.
x Two new keywords—private and public—appear in the code.
x Apart from data members, the class constructor also has member functions.
x A function that has the same name as the class itself is also present in the class. Incidentally,
it has no return type specified. This is the class constructor and is discussed in Chapter 4
of this book.
Introduction to C++ 9

The next chapter contains an in-depth study of the above class construct. It explains the
meaning and implications of this new feature. It also explains how this and many more
new features implement the features of OOPS, such as data hiding, data encapsulation, data
abstraction, and a guaranteed initialization of data. However, before proceeding to Chapter
2, let us digress slightly and study the following:
x Console input/output in C++
x Some non-object-oriented features provided exclusively in C++ (reference variables,
function overloading, default arguments, inline functions)
Remember that C++ program ¿les have the extension ‘.cpp’ or ‘.C’. The former extension
is normally used for Windows or DOS-based compilers while the latter is normally used
for UNIX-based compilers. The compiler’s manual can be consulted to ¿nd out the exact
extension.

1.5 Console Input/Output in C++


This section discusses console input and output in C++.

1.5.1 Console Output


The output functions in C language, such as printf(), can be included in C++ programs
because they are anyway de¿ned in the standard library. However, there are some more ways
of outputting to the console in C++. Let us consider an example (see Listing 1.7).

Listing 1.7 Outputting in C++

/*Beginning of cout.cpp*/
#include<iostream.h>
void main()
{
int x;
x=10;
cout<<x; //outputting to the console
}
/*End of cout.cpp*/

Output
10

The third statement in the main() function (Listing 1.7) needs to be understood.
cout (pronounce see-out) is actually an object of the class ostream_withassign (you can
think of it as a variable of the structure ostream_withassign). It stands as an alias for the
console output device, that is, the monitor (hence the name).
The << symbol, originally the left shift operator, has had its de¿nition extended in C++.
In the given context, it operates as the insertion operator. It is a binary operator. It takes
two operands. The operand on its left must be some object of the ostream class. The operand
on its right must be a value of some fundamental data type. The value on the right side of
the insertion operator is ‘inserted’ (hence the name) into the stream headed towards the
device associated with the object on the left. Consequently, the value of ‘x’ is displayed on
the monitor.
The ¿le iostream.h needs to be included in the source code to ensure successful compilation
because the object cout and the insertion operator have been declared in that ¿le.
10 Object-Oriented Programming with C++

Another object endl allows us to insert a new line into the output stream. Listing 1.8
illustrates this.

Listing 1.8 Inserting new line by ‘endl’

/*Beginning of endl.cpp*/
#include<iostream.h>
void main()
{
int x,y;
x=10;
y=20;
cout<<x;
cout<<endl; //inserting a new line by endl
cout<<y;
}
/*End of endl.cpp*/

Output
10
20

One striking feature of the insertion operator is that it works equally well with values of
all fundamental types as its right-hand operand. It does not need the format speci¿ers that are
needed in the printf() family of functions. Listing 1.9 exempli¿es this.

Listing 1.9 Outputting data with the insertion operator

/*Beginning of cout.cpp*/
#include<iostream.h>
void main()
{
int iVar;
char cVar;
float fVar;
double dVar;
char * cPtr;
iVar=10;
cVar=‘x’;
fVar=2.3;
dVar=3.14159;
cPtr=“Hello World”;
cout<<iVar;
cout<<endl;
cout<<cVar;
cout<<endl;
cout<<fVar;
cout<<endl;
cout<<dVar;
cout<<endl;
cout<<cPtr;
cout<<endl;
}
/*End of cout.cpp*/
Introduction to C++ 11

Output
10
x
2.3
3.14159
Hello World

Just like the arithmetic addition operator, it is possible to cascade the insertion operator.
Listing 1.10 is a case in point.

Listing 1.10 Cascading the insertion operator

/*Beginning of coutCascade.cpp*/
#include<iostream.h>
void main()
{
int x;
float y;
x=10;
y=2.2;
cout<<x<<endl<<y; //cascading the insertion operator
}
/*End of coutCascade.cpp*/

Output
10
2.2

It is needless to say that we can pass constants instead of variables as operands to the insertion
operator, as shown in Listing 1.11.

Listing 1.11 Outputting constants using the insertion operator

/*Beginning of coutMixed.cpp*/
#include<iostream.h>
void main()
{
cout<<10<<endl<<“Hello World\n”<<3.4;
}
/*End of coutMixed.cpp*/

Ouput
10
Hello World
3.4

In Listing 1.11, note the use of the new line character in the string that is passed as one of the
operands to the insertion operator.
It was mentioned in the beginning of this section that cout is an object that is associated
with the console. Hence, if it is the left-hand side operand of the insertion operator, the
value on the right is displayed on the monitor. You will learn in the chapter on stream handling
that it is possible to pass objects of some other classes that are similarly associated with disk
12 Object-Oriented Programming with C++

¿les as the left-hand side operand to the insertion operator. In such cases, the values on
the right get stored in the associated ¿les.

1.5.2 Console Input


The input functions in C language, such as scanf(), can be included in C++ programs because
they are anyway de¿ned in the standard library. However, we do have some more ways of
inputting from the console in C++. Let us consider an example.

Listing 1.12 Inputting in C++

/*Beginning of cin.cpp*/
#include<iostream.h>
void main()
{
int x;
cout<<“Enter a number: ”;
cin>>x; //console input in C++
cout<<“You entered: ”<<x;
}
/*End of cin.cpp*/

Output
Enter a number: 10<enter>
You entered: 10

The third statement in the main() function of Listing 1.12 needs to be understood.
cin (pronounce see-in) is actually an object of the class istream_withassign (you can
think of it as a variable of the structure istream_withassign). It stands as an alias for the
console input device, that is, the keyboard (hence the name).
The >> symbol, originally the right-shift operator, has had its de¿nition extended in C++.
In the given context, it operates as the extraction operator. It is a binary operator and takes
two operands. The operand on its left must be some object of the istream_withassign class.
The operand on its right must be a variable of some fundamental data type. The value for the
variable on the right side of the extraction operator is extracted (hence the name) from the
stream originating from the device associated with the object on the left. Consequently, the
value of ‘x’ is obtained from the keyboard.
The ¿le iostream.h needs to be included in the source code to ensure successful compilation
because the object cin and the extraction operator have been declared in that ¿le.
Again, just like the insertion operator, the extraction operator works equally well
with variables of all fundamental types as its right-hand operand. It does not need the format
speci¿ers that are needed in the scanf() family of functions. Listing 1.13 exempli¿es this.

Listing 1.13 Inputting data with the extraction operator

/*Beginning of cin.cpp*/
#include<iostream.h>
void main()
{
int iVar;
Introduction to C++ 13

char cVar;
float fVar;
cout<<“Enter a whole number: ”;
cin>>iVar;
cout<<“Enter a character: ”;
cin>>cVar;
cout<<“Enter a real number: ”;
cin>>fVar;
cout<<“You entered: ”<<iVar<<“ ”<<cVar<<“ ”<<fVar;
}
/*End of cin.cpp*/

Output
Enter a whole number: 10<enter>
Enter a character: x<enter>
Enter a real number: 2.3<enter>
You entered: 10 x 2.3

Just like the insertion operator, it is possible to cascade the extraction operator. Listing
1.14 is a case in point.

Listing 1.14 Cascading the extraction operator

/*Beginning of cinCascade.cpp*/
#include<iostream.h>
void main()
{
int x,y;
cout<<“Enter two numbers\n”;
cin>>x>>y; //cascading the extraction operator
cout<<“You entered ”<<x<<“ and ”<<y;
}
/*End of cinCascade.cpp*/

Output
Enter two numbers
10<enter>
20<enter>
You entered 10 and 20

It was mentioned in the beginning of this section that cin is an object that is associated with
the console. Hence, if it is the left-hand side operand of the extraction operator, the variable
on the right gets its value from the keyboard. You will learn in the chapter on stream handling
that it is possible to pass objects of some other classes that are similarly associated with disk
¿les as the left-hand side operand to the extraction operator. In such cases, the variable on
the right gets its value from the associated ¿les.

1.6 Variables in C++


Variables in C++ can be declared anywhere inside a function and not necessarily at its very
beginning. For example, see Listing 1.15.
14 Object-Oriented Programming with C++

Listing 1.15 Declaring variables in C++

#include<iostream.h>
void main()
{
int x;
x=10;
cout<<“Value of x= ”<<x<<endl;
int * iPtr; //declaring a variable in the middle of a
//function
iPtr=&x;
cout<<“Address of x= ”<<iPtr<<endl;
}

Output
Value of x=10
Address of x= 0x21878163

1.7 Reference Variables in C++


First, let us understand the basics. How does the operating system (OS) display the value of
variables? How are assignment operations such as ‘x=y’ executed during run time? A detailed
answer to these questions is beyond the scope of this book. A brief study is, nevertheless,
possible and necessary for a good understanding of reference variables. What follows is a
simpli¿ed and tailored explanation.
The OS maintains the addresses of each variable as it allocates memory for them during run
time. In order to access the value of a variable, the OS ¿rst ¿nds the address of the variable
and then transfers control to the byte whose address matches that of the variable.
Suppose the following statement is executed (‘x’ and ‘y’ are integer type variables).
x=y;

The steps followed are:


1. The OS first finds the address of ‘y’.
2. The OS transfers control to the byte whose address matches this address.
3. The OS reads the value from the block of four bytes that starts with this byte (most C++
compilers cause integer-type variables to occupy four bytes during run time and we will
accept this value for our purpose).
4. The OS pushes the read value into a temporary stack.
5. The OS finds the address of ‘x’.
6. The OS transfers control to the byte whose address matches this address.
7. The OS copies the value from the stack, where it had put it earlier, into the block of four
bytes that starts with the byte whose address it has found above (address of ‘x’).
Notice that addresses of the variables on the left as well as on the right of the assignment
operator are determined. However, the value of the right-hand operand is also determined. The
expression on the right must be capable of being evaluated to a value. This is an important
point and must be borne in mind. It will enable us to understand a number of concepts later.
Introduction to C++ 15

Especially, you must remember that the expression on the left of the assignment operator
must be capable of being evaluated to a valid address at which data can be written.
Now, let us study reference variables. A reference variable is nothing but a reference for
an existing variable. It shares the memory location with an existing variable. The syntax for
declaring a reference variable is as follows:
<data-type> & <ref-var-name>=<existing-var-name>;

For example, if ‘x’ is an existing integer-type variable and we want to declare iRef as a
reference to it the statement is as follows:
int & iRef=x;

iRef is a reference to ‘x’. This means that although iRef and ‘x’ have separate entries in the
OS, their addresses are actually the same!
Thus, a change in the value of ‘x’ will naturally reflect in iRef and vice versa.
Listing 1.16 illustrates this.

Listing 1.16 Reference variables

/*Beginning of reference01.cpp*/
#include<iostream.h>
void main()
{
int x;
x=10;
cout<<x<<endl;
int & iRef=x; //iRef is a reference to x
iRef=20; //same as x=10;
cout<<x<<endl;
x++; //same as iRef++;
cout<<iRef<<endl;
}
/*End of reference01.cpp*/

Output
10
20
21

Reference variables must be initialized at the time of declaration (otherwise the compiler will
not know what address it has to record for the reference variable).
Reference variables are variables in their own right. They just happen to have the address
of another variable. After their creation, they function just like any other variable.
We have just seen what happens when a value is written into a reference variable. The
value of a reference variable can be read in the same way as the value of an ordinary variable
is read. Listing 1.17 illustrates this.

Listing 1.17 Reading the value of a reference variable

/*Beginning of reference02.cpp*/
#include<iostream.h>
void main()
{
16 Object-Oriented Programming with C++

int x,y;
x=10;
int & iRef=x;
y=iRef; //same as y=x;
cout<<y<<endl;
y++; //x and iRef unchanged
cout<<x<<endl<<iRef<<endl<<y<<endl;
}
/*End of reference02.cpp*/

Output
10
10
10
11

A reference variable can be a function argument and thus change the value of the parameter
that is passed to it in the function call. Listing 1.18 is an illustrative example.

Listing 1.18 Passing by reference

/*Beginning of reference03.cpp*/
#include<iostream.h>
void increment(int &); //formal argument is a reference
//to the passed parameter
void main()
{
int x;
x=10;
increment(x);
cout<<x<<endl;
}
void increment(int & r)
{
r++; //same as x++;
}
/*End of reference03.cpp*/

Output
11

Functions can return by reference also. See Listing 1.19.

Listing 1.19 Returning by reference

/*Beginning of reference04.cpp*/
#include<iostream.h>
int & larger(int &, int &);
int main()
{
int x,y;
x=10;
y=20;
int & r=larger(x,y);
r=-1;
cout<<x<<endl<<y<<endl;
}
Introduction to C++ 17

int & larger(int & a, int & b)


{
if(a>b) //return a reference to the larger parameter
return a;
else
return b;
}
/*End of reference04.cpp*/

Output
10
–1

In the foregoing listing, ‘a’ and ‘x’ refer to the same memory location while ‘b’ and ‘y’
refer to the same memory location. From the larger() function, a reference to ‘b’, that is,
reference to ‘y’ is returned and stored in a reference variable ‘r’. The larger() function does
not return the value ‘b’ because the return type is int& and not int. Thus, the address of ‘r’
becomes equal to the address of ‘y’. Consequently, any change in the value of ‘r’ also changes
the value of ‘y’. Listing 1.19 can be shortened as illustrated in Listing 1.20.

Listing 1.20 Returning by reference

/*Beginning of reference05.cpp*/
#include<iostream.h>
int & larger(int &, int &);
int main()
{
int x,y;
x=10;
y=20;
larger(x,y)=-1;
cout<<x<<endl<<y<<endl;
}
int & larger(int & a, int & b)
{
if(a>b) //return a reference to the larger parameter
return a;
else
return b;
}
/*End of reference05.cpp*/

Output
10
–1

The name of a non-constant variable can be placed on the left of the assignment operator
because a valid address—the address of the variable—can be determined from it. A call to
a function that returns by reference can be placed on the left of the assignment operator for
the same reason.
If the compiler ¿nds the name of a non-constant variable on the left of the assignment
operator in the source code, it writes instructions in the executable to
x determine the address of the variable,
x transfer control to the byte that has that address, and
18 Object-Oriented Programming with C++

x write the value on the right of the assignment operator into the block that begins with
the byte found above.
A function that returns by reference primarily returns the address of the returned variable.
If the call is found on the left of the assignment operator, the compiler writes necessary
instructions in the executable to
x transfer control to the byte whose address is returned by the function and
x write the value on the right of the assignment operator into the block that begins with
the byte found above.
The name of a variable can be placed on the right of the assignment operator. A call to
a function that returns by reference can be placed on the right of the assignment operator
for the same reason.
If the compiler ¿nds the name of a variable on the right of the assignment operator in the
source code, it writes instructions in the executable to
x determine the address of the variable,
x transfer control to the byte that has that address,
x read the value from the block that begins with the byte found above, and
x push the read value into the stack.
A function that returns by reference primarily returns the address of the returned variable.
If the call is found on the right of the assignment operator, the compiler writes necessary
instructions in the executable to
x transfer control to the byte whose address is returned by the function,
x read the value from the block that begins with the byte found above, and
x push the read value into the stack.
A constant cannot be placed on the left of the assignment operator. This is because
constants do not have a valid address. Moreover, how can a constant be changed? Functions
that return by value, return the value of the returned variable, which is a constant. Therefore,
a call to a function that returns by value cannot be placed on the left of the assignment
operator.
You may notice that the formal arguments of the larger() function in the foregoing listing
have been declared as constant references because they are not supposed to change the values
of the passed parameters even accidentally.
We must avoid returning a reference to a local variable. For example, see Listing 1.21.

Listing 1.21 Returning the reference of a local variable

/*Beginning of reference06.cpp*/
#include<iostream.h>
int & abc();
void main()
{
abc()=-1;
}
int & abc()
{
int x;
return x; //returning reference of a local variable
}
/*End of reference06.cpp*/
Introduction to C++ 19

The problem with the above program is that when the abc() function terminates, ‘x’ will
go out of scope. Consequently, the statement
abc()=-1;
in the main() function will write ‘–1’ in an unallocated block of memory. This can lead to
run-time errors.

1.8 Function Prototyping


Function prototyping is necessary in C++. A prototype describes the function’s interface to
the compiler. It tells the compiler the return type of the function as well as the number, type,
and sequence of its formal arguments.
The general syntax of function prototype is as follows:
return_type function_name(argument_list);
For example,
int add(int, int);

This prototype indicates that the add() function returns a value of integer type and takes two
parameters both of integer type.
Since a function prototype is also a statement, a semicolon must follow it.
Providing names to the formal arguments in function prototypes is optional. Even if
such names are provided, they need not match those provided in the function de¿nition. For
example, see Listing 1.22.

Listing 1.22 Function prototyping

/*Beginning of funcProto.cpp*/
#include<iostream.h>
int add(int,int); //function prototype
void main()
{
int x,y,z;
cout<<“Enter a number: ”;
cin>>x;
cout<<“Enter another number: ”;
cin>>y;
z=add(x,y); //function call
cout<<z<<endl;
}
int add(int a,int b) //function definition
{
return (a+b);
}
/*End of funcProto.cpp*/

Output
Enter a number: 10<enter>
Enter another number: 20<enter>
30

Why is prototyping important? By making prototyping necessary, the compiler ensures


the following:
20 Object-Oriented Programming with C++

x The return value of a function is handled correctly.


x Correct number and type of arguments are passed to a function.
Let us discuss these points.
Consider the following statement in Listing 1.22:
int add(int, int);

The prototype tells the compiler that the add() function returns an integer-type value. Thus,
the compiler knows how many bytes have to be retrieved from the place where the add()
function is expected to write its return value and how these bytes are to be interpreted.
In the absence of prototypes, the compiler will have to assume the type of the returned
value. Suppose, it assumes that the type of the returned value is an integer. However, the
called function may return a value of an incompatible type (say a structure type). Now,
suppose an integer-type variable is equated to the call to a function where the function call
precedes the function de¿nition. In this situation, the compiler will report an error against
the function de¿nition and not the function call. This is because the function call abided by
its assumption, but the de¿nition did not. However, if the function de¿nition is in a different
¿le to be compiled separately, then no compile-time errors will arise. Instead, wrong results
will arise during run time as Listing 1.23 shows.

Listing 1.23 Absence of function prototype produces weird results

/*Beginning of def.c*/
/*function definition*/
struct abc
{
char a;
int b;
float c;
};
struct abc test()
{
struct abc a1;
a1.a=‘x’;
a1.b=10;
a1.c=1.1;
return a1;
}
/*End of def.c*/
/*Beginning of driver.c*/
void main()
{
int x;
x=test(); //no compile time error!!
printf(“%d”,x);
}
/*End of driver.c*/

Output
1688

A compiler that does not enforce prototyping will de¿nitely compile the above program.
But then it will have no way of knowing what type of value the test() function returns.
Introduction to C++ 21

Therefore, erroneous results will be obtained during run time as the output of Listing 1.23
clearly shows.
Since the C++ compiler necessitates function prototyping, it will report an error against
the function call because no prototype has been provided to resolve the function call. Again,
if the correct prototype is provided, the compiler will still report an error since this time the
function call does not match the prototype. The compiler will not be able to convert a struct
abc to an integer. Thus, function prototyping guarantees protection from errors arising out
of incorrect function calls.
What happens if the function prototype and the function call do not match? Such a situation
cannot arise. Both the function prototype and the function de¿nition are created by the same
person, that is, the library programmer. The library programmer puts the function’s prototype in
a header ¿le. He/she provides the function’s de¿nition in a library. The application programmer
includes the header ¿le in his/her application program ¿le in which the function is called. He/
she creates an object ¿le from this application program ¿le and links this object ¿le to the
library to get an executable ¿le.
The function’s prototype also tells the compiler that the add() function accepts two
parameters. If the program fails to provide such parameters, the prototype enables the compiler
to detect the error. A compiler that does not enforce function prototyping will compile a
function call in which an incorrect number and/or type of parameters have been passed. Run-
time errors will arise as in the foregoing case.
Finally, function prototyping produces automatic-type conversion wherever appropriate.
We take the case of compilers that do not enforce prototyping. Suppose, a function expects an
integer-type value (assuming integers occupy four bytes) but a value of double type (assuming
doubles occupy eight bytes) is wrongly passed. During run time, the value in only the ¿rst
four bytes of the passed eight bytes will be extracted. This is obviously undesirable. However,
the C++ compiler automatically converts the double-type value into an integer type. This
is because it inevitably encounters the function prototype before encountering the function
call and therefore knows that the function expects an integer-type value. However, it must
be remembered that such automatic-type conversions due to function prototypes occur only
when it makes sense. For example, the compiler will prevent an attempted conversion from
a structure type to integer type.
Nevertheless, can the same bene¿ts not be realized without prototyping? Is it not possible
for the compiler to simply scan the rest of the source code and ¿nd out how the function has
been de¿ned? There are two reasons why this solution is inappropriate. They are:
x It is inefficient. The compiler will have to suspend the compilation of the line containing
the function call and search the rest of the file.
x Most of the times the function definition is not contained in the file where it is called. It
is usually contained in a library.
Such compile-time checking for prototypes is known as static-type-checking.

1.9 Function Overloading


C++ allows two or more functions to have the same name. For this, however, they must have
different signatures. Signature of a function means the number, type, and sequence of formal
arguments of the function. In order to distinguish amongst the functions with the same name,
the compiler expects their signatures to be different. Depending upon the type of parameters
that are passed to the function call, the compiler decides which of the available de¿nitions
22 Object-Oriented Programming with C++

will be invoked. For this, function prototypes should be provided to the compiler for matching
the function calls. Accordingly, the linker, during link time, links the function call with the
correct function de¿nition. Listing 1.24 clari¿es this.

Listing 1.24 Function overloading

/*Beginning of funcOverload.cpp*/
#include<iostream.h>
int add(int,int); //first prototype
int add(int,int,int); //second prototype
void main()
{
int x,y;
x=add(10,20); //matches first prototype
y=add(30,40,50); //matches second prototype
cout<<x<<endl<<y<<endl;
}
int add(int a,int b)
{
return(a+b);
}
int add(int a,int b,int c)
{
return(a+b+c);
}
/*End of funcOverload.cpp*/

Output
30
120

Just like ordinary functions, the de¿nitions of overloaded functions are also put in libraries.
Moreover, the function prototypes are placed in header ¿les.
The two function prototypes at the beginning of the program tell the compiler the two
different ways in which the add() function can be called. When the compiler encounters the
two distinct calls to the add() function, it already has the prototypes to satisfy them both.
Thus, the compilation phase is completed successfully. During linking, the linker ¿nds the
two necessary de¿nitions of the add() function and, hence, links successfully to create the
executable ¿le.
The compiler decides which function is to be called based upon the number, type, and
sequence of parameters that are passed to the function call. When the compiler encounters
the ¿rst function call,
x=add(10,20);

it decides that the function that takes two integers as formal arguments is to be executed.
Accordingly, the linker then searches for the de¿nition of the add() function where there are
two integers as formal arguments.
Similarly, the second call to the add() function
y=add(30,40,50);

is also handled by the compiler and the linker.


Introduction to C++ 23

Note the importance of function prototyping. Since function prototyping is mandatory in


C++, it is possible for the compiler to support function overloading properly. The compiler
is able to not only restrict the number of ways in which a function can be called but also
support more than one way in which a function can be called. Function overloading is possible
because of the necessity to prototype functions.
By itself, function overloading is of little use. Instead of giving exactly the same name for
functions that perform similar tasks, it is always possible for us to give them similar names.
However, function overloading enables the C++ compiler to support another feature, that
is, function overriding (which in turn is not really a very useful thing by itself but forms the
basis for dynamic polymorphism—one of the most striking features of C++ that promotes
code reuse).
Function overloading is also known as function polymorphism because, just like
polymorphism in the real world where an entity exists in more than one form, the same
function name carries different meanings.
Function polymorphism is static in nature because the function de¿nition to be executed
is selected by the compiler during compile time itself. Thus, an overloaded function is said
to exhibit static polymorphism.

1.10 Default Values for Formal Arguments of Functions


It is possible to specify default values for some or all of the formal arguments of a function. If
no value is passed for an argument when the function is called, the default value speci¿ed for
it is passed. If parameters are passed in the normal fashion for such an argument, the default
value is ignored. Listing 1.25 is an illustrative example.

Listing 1.25 Default values for function arguments

/*Beginning of defaultArg.cpp*/
#include<iostream.h>
int add(int,int,int c=0); //third argument has default value
void main()
{
int x,y;
x=add(10,20,30); //default value ignored
y=add(40,50); //default value taken for the
//third parameter
cout<<x<<endl<<y<<endl;
}
int add(int a,int b,int c)
{
return (a+b+c);
}
/*End of defaultArg.cpp*/

Output
60
90

In the above listing, a default value—zero—has been speci¿ed for the third argument of the
add() function. In the absence of a value being passed to it, the compiler assigns the default
value. If a value is passed to it, the compiler assigns the passed value. In the ¿rst call
24 Object-Oriented Programming with C++

x=add(10,20,30);

the values of ‘a’, ‘b’, and ‘c’ are 10, 20, and 30, respectively. But, in the second function call
y=add(40,50);

the values of ‘a’, ‘b’, and ‘c’ are 10, 20, and 0, respectively. The default value—zero—for
the third parameter ‘c’ is taken. This explains the output of the above listing.
Default values can be assigned to more than one argument. Listing 1.26 illustrates this.

Listing 1.26 Default values for more than one argument

/*Beginning of multDefaultArg.cpp*/
#include<iostream.h>
int add(int,int b=0,int c=0); //second and third arguments
//have default values
void main()
{
int x,y,z;
x=add(10,20,30); //all default values ignored
y=add(40,50); //default value taken for the
//third argument
z=add(60); //default value taken for
//the second and the third
//arguments
cout<<x<<endl<<y<<endl<<z<<endl;
}
int add(int a,int b,int c)
{
return (a+b+c);
}
/*End of multDefaultArg.cpp*/

Output
60
90
60

There is no need to provide names to the arguments taking default values in the function
prototypes.
int add(int,int=0,int=0);

can be written instead of


int add(int,int b=0,int c=0);

Default values must be supplied starting from the rightmost argument. Before supplying
default value to an argument, all arguments to its right must be given default values. Suppose
you write
int add(int,int=0,int);

you are attempting to give a default value to the second argument from the right without
specifying a default value for the argument on its right. The compiler will report an error that
the default value is missing (for the third argument).
Introduction to C++ 25

Default values must be speci¿ed in function prototypes alone. They should not be speci¿ed
in the function de¿nitions.
While compiling a function call, the compiler will de¿nitely have its prototype. Its de¿nition
will probably be located after the function call. It might be in the same ¿le, or it will be in a
different ¿le or library. Thus, to ensure a successful compilation of the function calls where
values for arguments having default values have not been passed, the compiler must be aware
of those default values. Hence, default values must be speci¿ed in the function prototype.
You must also remember that the function prototypes are placed in header ¿les. These are
included in both the library ¿les that contain the function’s de¿nition and the client program
¿les that contain calls to the functions. While compiling the library ¿le that contains the
function de¿nition, the compiler will obviously read the function prototype before it reads
the function de¿nition. Suppose the function de¿nition also contains default values for the
arguments. Even if the same default values are supplied for the same arguments, the compiler
will think that you are trying to supply two different default values for the same argument.
This is obviously unacceptable because the default value can be only one in number. Thus,
default values must be speci¿ed in the function prototypes and should not be speci¿ed again
in the function de¿nitions.
If default values are speci¿ed for the arguments of a function, the function behaves like
an overloaded function and, therefore, should be overloaded with care; otherwise ambiguity
errors might be caused. For example, if you prototype a function as follows:
int add(int,int,int=0);
int add(int,int);

This can confuse the compiler. If only two integers are passed as parameters to the function
call, both these prototypes will match. The compiler will not be able to decide with which
de¿nition the function call has to be resolved. This will lead to an ambiguity error.
Default values can be given to arguments of any data type as follows:
double hra(double,double=0.3);
void print(char=’a’);

1.11 Inline Functions


Inline functions are used to increase the speed of execution of the executable ¿les. C++ inserts
calls to the normal functions and the inline functions in different ways in an executable.
The executable program that is created after compiling the various source codes and linking
them consists of a set of machine language instructions. When a program is started, the
operating system loads these instructions into the computer’s memory. Thus, each instruction
has a particular memory address. The computer then goes through these instructions one by
one. If there are any instructions to branch out or loop, the control skips over instructions and
jumps backward or forward as needed. When a program reaches the function call instruction,
it stores the memory address of the instruction immediately following the function call. It then
jumps to the beginning of the function, whose address it ¿nds in the function call instruction
itself, executes the function code, and jumps back to the instruction whose address it had
saved earlier.
Obviously, an overhead is involved in
x making the control jump back and forth and
26 Object-Oriented Programming with C++

x storing the address of the instruction to which the control should jump after the function
terminates.
The C++ inline function provides a solution to this problem. An inline function is a function
whose compiled code is ‘in line’ with the rest of the program. That is, the compiler replaces
the function call with the corresponding function code. With inline code, the program does
not have to jump to another location to execute the code and then jump back. Inline functions,
thus, run a little faster than regular functions.
However, there is a trade-off between memory and speed. If an inline function is
called repeatedly, then multiple copies of the function definition appear in the code
(see Figures 1.1 and 1.2). Thus, the executable program itself becomes so large that it occupies
a lot of space in the computer’s memory during run time. Consequently, the program runs
slow instead of running fast. Thus, inline functions must be chosen with care.
For specifying an inline function, you must:
x prefix the definition of the function with the inline keyword and
x define the function before all functions that call it, that is, define it in the header file
itself.
The following listing illustrates the inline technique with the inline cube() function that
cubes its argument. Note that the entire de¿nition is in one line. That is not a necessary
condition. But if the de¿nition of a function does not ¿t in one line, the function is probably
a poor candidate for an inlne function!

Figure 1.1 Transfer of control in a non-inline function


Introduction to C++ 27

Figure 1.2 Control does not get transferred in an inline function

Listing 1.27 Inline functions

/*Beginning of inline.cpp*/
#include<iostream.h>
inline double cube(double x) { return x*x*x; }
void main()
{
double a,b;
double c=13.0;
a=cube(5.0);
b=cube(4.5+7.5);
cout<<a<<endl;
cout<<b<<endl;
cout<<cube(c++)<<endl;
cout<<c<<endl;
}
/*End of inline.cpp*/
28 Object-Oriented Programming with C++

Output
125
1728
2197
14

However, under some circumstances, the compiler, despite your indications, may not expand the
function inline. Instead, it will issue a warning that the function could not be expanded inline
and then compile all calls to such functions in the ordinary fashion. Those conditions are:
x The function is recursive.
x There are looping constructs in the function.
x There are static variables in the function.
Let us brieÀy compare macros in C and inline function in C++. Macros are a poor predecessor
to inline functions. For example, a macro for cubing a number is as follows:
#define CUBE(X) X*X*X

Here, a mere text substitution takes place with‘X’ being replaced by the macro parameter.
a=CUBE(5.0); //replaced by a=5.0*5.0*5.0;
b=CUBE(4.5+7.5); //replaced by
//b=4.5+7.5*4.5+7.5*4.5+7.5;
c=CUBE(x++); //replaced by c=x++*x++*x++;

Only the ¿rst statement works properly. An intelligent use of parentheses improves matters
slightly.
#define CUBE(X) ((X)*(X)*(X))

Even now, CUBE(c++) undesirably increments ‘c’ thrice. But the inline cube() function
evaluates ‘c’, passes the value to be cubed, and then correctly increments ‘c’ once.
It is advisable to use inline functions instead of macros.

Summary
Variables sometimes inÀuence each other’s values. be safe from unintentional modi¿cation by functions
A change in the value of one may necessitate a other than those de¿ned by him/her. Moreover, they do
corresponding adjustment in the value of another. It not guarantee a proper initialization of data members
is, therefore, necessary to pass these variables together of structure variables.
in a single group to functions. Structures enable us to Both of the above drawbacks are in direct
do this. contradiction with the characteristics possessed by
Structures are used to create new data types. This real-world objects. A real-world object has not only
is a two-step process. a perfect interface to manipulate its internal parts but
Step 1: Create the structure itself. also exclusive rights to do so. Consequently, a real-
world object never reaches an invalid state during its
Step 2: Create associated functions that work upon
lifetime. When we start operating a real-world object, it
variables of the structure.
automatically assumes a valid state. In object-oriented
While structures do fulfil the important need
programming systems (OOPS), we can incorporate
described above, they nevertheless have limitations.
these features of real-world objects into structure
They do not enable the library programmer to make
variables.
variables of the structure that he/she has designed to
Introduction to C++ 29

Inheritance allows a structure to inherit both data of the variable with which it is sharing memory. Calls
and functions of an existing structure. Polymorphism to functions that return by reference can be placed on
allows different functions to have the same name. It is the left of the assignment operator.
of two types: static and dynamic. Function prototyping is necessary in C++. Functions
Console output is achieved in C++ with the help can be overloaded. Functions with different signatures
of insertion operator and the cout object. Console can have the same name. A function argument can be
input is achieved in C++ with the help of extraction given a default value so that if no value is passed for it
operator and the cin object. in the function call, the default value is assigned to it.
In C++, variables can be de¿ned anywhere in a If a function is declared inline, its de¿nition replaces
function. A reference variable shares the same memory its call, thus, speeding up the execution of the resultant
location as the one of which it is a reference. Therefore, executable.
any change in its value automatically changes the value

Key Terms
creating new data types using structures - cin
lack of data security in structures - istream_withassign class
no guaranteed initialization of data in structures - extraction operator
procedure-oriented programming system - iostream.h header ¿le
object-oriented programming system - endl
data security in classes reference variable
guaranteed initialization of data in classes - passing by reference
inheritance - returning by reference
polymorphism importance of function prototyping
console input/output in C++ function overloading
- cout default values for function arguments
- ostream_withassign class inline functions
- insertion operator

Exercises
1. Which programming needs do structures ful¿ll? Why 10. State true or false.
does C language enable us to create structures? (a) Structures enable a programmer to secure the
2. What are the limitations of structures? data contained in structure variables from being
3. What is the procedure-oriented programming changed by unauthorized functions.
system? (b) The insertion operator is used for outputting
4. What is the object-oriented programming system? in C++.
5. Which class is ‘cout’ an object of? (c) The extraction operator is used for outputting
6. Which class is ‘cin’ an object of? in C++.
7. What bene¿ts does a programmer get if the compiler (d) A call to a function that returns by reference
forces him/her to prototype a function? cannot be placed on the left of the assignment
8. Why will an ambiguity error arise if a default value operator.
is given to an argument of an overloaded function? (e) An inline function cannot have a looping
9. Why should default values be given to function construct.
arguments in the function’s prototype and not in the 11. Think of some examples from your own experience in
function’s de¿nition? C programming where you felt the need for structures.
30 Object-Oriented Programming with C++

Do you see an opportunity for programming in OOPS on the left-hand side of the assignment operator.
in those examples? Experiment and ¿nd out whether such calls can be
12. Structures in C do not enable the library programmers chained. Consider the following:
to guarantee an initialization of data. Appreciate the
f(a, b) = g(c, d) = x;
implications of this limitation by taking the date
structure as an example. where ‘f’ and ‘g’ are functions that return by reference
13. Calls to functions that return by reference can be put while ‘a’, ‘b’, ‘c’, ‘d’, and ‘x’ are variables.
2 Classes and Objects

The previous chapter refreshed the reader’s knowledge of the structure construct provided
by C language—its use and usage. It also dealt with a critical analysis of structures along with
their pitfalls and limitations. The reader was made aware of a strong need for data security and
for a guaranteed initialization of data that structures do not provide.
This chapter is a logical continuation to the previous one. It begins with a thorough
explanation of the class construct of C++ and the ways by which it ful¿ls the above-mentioned
O needs. Superiority of the class construct of C++ over the structure construct of C language is
emphasized in this chapter.
V This chapter also deals with how classes enable the library programmer to provide exclusive
E rights to the associated functions.
A description of various types and features of member functions and member data ¿nds a
R prominent place in this chapter. This description covers:
x Overloaded member functions
V
x Default values for the arguments of member functions
I x Inline member functions
x Constant member functions
E x Mutable data members
W x Friend functions and friend classes
x Static members
A section in this chapter is devoted to namespaces. They enable the C++ programmer to
prevent pollution of the global namespace that leads to name clashes.
Example code to tackle arrays of objects and arrays inside objects form the penultimate
portion of this chapter.
The chapter ends with an essay on nested classes—their need and use.

2.1 Introduction to Classes and Objects


Classes are to C++ what structures are to C. Both provide the library programmer a means
to create new data types.
Let us brieÀy recapitulate the issues faced while programming in C described in the previous
chapter. In C, the library programmer creates structures. He/she also provides a set of tested
bug-free functions that correctly manipulate the data members of structure variables.
The Date structure and its accompanying functions may be perfect. However, there is
absolutely no guarantee that the client programs will use only these functions to manipulate
the members of variables of the structure. See Listing 2.1.
Other documents randomly have
different content
erano reducti molti Franzesi. El Prencipe de Altamura era a Brandizo;
et per intender el tutto, qui sarà scritto una lettera dil re Ferandino,
scritta a soi secretarii a Roma.

Exemplum literarum Ferdinandi regis.

Rex Siciliae al Ripol et Berardino.


Questa sera havemo hauto aviso da missier Piero Carazolo, quale
mandamo in questi dì al Ducha de Melfe et al Duca de Gravina,
come ditti Duchi hanno già alzate le nostre bandiere et si sono reduti
a la nostra fideltà, et che erano in camino per venir ad trovarse con
le zente loro. Similiter questa sera è venuto da noi lo canzelario del
conte di Capaze, el qual ne ha affirmato, per parte de ditto conte,
come sarà lo simile incontenente; et che manderia subito da noi lo
figlio con le zente soe. Da Amanthea è venuto uno nostro fidato, et
qual partì Domenica di quella città: dice che passando dui dì avanti
per Cosenza, intese che mons. di Obegnì stava malissimo, te che da
poi essendo in l'Amanthea, venne nova che era morto. Come sarà la
nova certa, ve ne daremo aviso; fra tanto del preditto darete noticia
a la Santità dil Nostro Signor, et a lo Ill.mo et Rev.mo Vicecancellier
nostro patre, et al magnifico don Gracilasso, ambassador de
Castiglia, perchè semo certi ne haveran piacer. Le zente franzese che
sono in Calabria erano divertite ad Tropeya, et stavano de lì intorno,
et ogni dì se presentano a la terra la qual sta fortissima. Et lo Rev.mo
Cardinal scrive che di quelle cosse stieno di bon animo, et che ne
lassemo lo pensier a lui.
Date in Castel nostro Capuano, Neapolis, 22 Julii 1495.
Rex Ferdinandus
Chariteus.
A tergo: Magnificis viris Aloysio Ripol et Berardino Francho secretariis
et consiliariis nostris dilectis.
Et a dì 25 zonseno a Napoli el Duca preditto de Gravina et el Duca
de Melfi con le militie loro. El Principe de Altemura smontò a San
Cathaldo in Puia, et quel Duca si dete a lui a discreptione di la
Majestà dil Re; demum andò a trovar el nostro capetanio zeneral con
le tre galie havia, poi andò a Manferdonia per alcune reliquie gallice,
che de lì se atrovava. A Napoli, preso el molo, fo messo per re
Ferandino alcune artilarie tiravano a l'armata franzese. A dì 26 de
notte el sig. Prospero Colonna con una galia partì de Napoli per
andar dal Principe di Bisignano so parente, per condurlo a ubidientia
dil Re. El prefetto de Senegaia era a Sora, indurato in nimicitia con el
prefato Re; el qual pochi zorni avanti fo scritto, per via de Ravena, a
la Signoria era morto, tamen non fo vero; pur era amalato.
A dì 27 lì a Napoli venne nova, el Principe de Altemura havia habuto,
oltra tutte le forteze de Puia, anche el Monte de Santo Anzolo; et
che tutte quelle zente franzese, di le qual era capo uno don Juliano,
dovevano venir de lì assecurate. Et a dì 28 da matina con le
bombarde fo profondato una de le barze franzese lì a Napoli. El
conte de Monte Odorisso, fratello del Marchexe de Pescara, che fo
ferito da' Franzesi, come ho ditto, stava pur cussì; poi varite. Et el
consolo nostro, a dì ditto, havendo ricevuto lettere di 26 da Roma,
andò in Castello da la Majestà dil Re, el qual li disse, Soa Majestà
havea scritto in questa terra, dimandando l'armata nostra in suo
aiuto; et che 'l favor de quella armata havia grandemente zovato a
tutte cosse sue, incomenciando da quello fo facto a Monopoli, per la
pertinentia de quelli, che exinde tutte altre terre fonno più facilmente
venute a obedientia. Per el qual benefitio grande, disse Soa Majestà,
siamo per haver perpetuo obligo verso quella Ill.ma Signoria, come
havemo et haveremo; et che sperava haver di breve il Castel nuovo,
perchè el cavo (capo, capitano) era stato a parlamento con il conte
de Trivento, et che comenzavano a patir; et Castel di l'Ovo ha
segnato, quello farà Castel nuovo, etiam loro faranno. Item el Re
mandò el sig. don Cesare con zente a Taranto, et speravano si darà
incontinente. El Prencipe de Salerno se intese in castello era
amalato. Et in questo zorno di Napoli se partì uno ambassador
deputato a Roma al Pontifice, chiamato Hieronimo Sperandio, dottor,
che alias vi fu, et anche in questa terra, come ho scritto di sopra.

Exemplum literarum Regis praedicti.

Rex Siciliae etc.


Ripol et Berardino. Questa sera havemo habuto nova da Calavria,
quelli de Terra nuova havevano mandato ad Reggio el capetanio dil
serenissimo sig. Re de Yspania et nostro....., che è là, che si dovesse
conferire in Terra nuova, atento che mons. de Obegnì era morto. Et
preditto capetanio era stato deliberato partisse per quello camino, et
poi andare a le zente franzese che son rimase in quella provintia. In
questi dì, da quelli stavano al Castel nuovo fo mossa certa pratica
per mezo dil capetanio di l'armada, che essendo noi stati ad
parlamento con ditto capetanio fin ad l'armata, parendone che non
c'erano cosse di substantia, dicessemo al ditto capetanio che non
volevamo audire più simil pratice, et restamo in conclusione che se
quelli dil castello non veniriano ad cose di fondamento et stabile, che
non si dovesse dare più orechie, et auscultare cossa che dicesseno.
Questa sera per ditto capetanio ne è stato mandato a dir, che
domane ci vole venire a parlar, parendoli havere cosse di substantia.
Noi intenderemo quello volerano dire, et a presso dil tutto vi
aviseremo. Volemo che debiate comunicare ogni cossa con la Santità
dil Nostro Signor et con lo rev.mo et ill.mo sig. Vicecancellier nostro
patre, et con li magnifici Ambassadori di Spagna et Venetia, et con
chi altri ve parerà. Hozi è venuto a noi Bernardin Branzia dal sig.
Fabricio, el qual non era ancora arrivato. Jacomo Pontano noi lo
havemo expedito; domane se ne torna con expeditione di quanto ne
ha referito.
Data in Castello nostro Capuano. Neapolis, die 27 Julii 1495.
Ferdinandus Rex.
A tergo: ut superius scripsi.
In questi zorni, andando di Roma a Napoli certe lettere dil cardinal
San Dyonisio a mons. di Mompensier, vicerè, era in Castello, fonno
intercepte et presentate al re Ferandino. Le qual qui saranno notade.

Copia di una lettera scripta a mons. di Mompensier


per el cardinal S. Dyonise, di la rota.

Mons. Io me recomando a Vuj tanto de bon cuore come posso. Io


non ho hauto mai altro che una lettera de vuj, despò che el Re è
partito da Napoli, nè saputo nove de vuj, si non per...., el qual m'ha
scritto d'Aquapendente arente Siena, et heri mi manda le lettere
originale che mons. lo conte de Lignì scriveva al suo locotenente al
ditto luogo di Siena, zercha la vittoria et felicità che 'l Re havia hauta
contra soi inimici; le qual ve ho mandate per la via de' mei signori
Colonnesi, che ho tutti zorni confortadi et intretegnudi al manco
male ho saputo, perchè tanti corieri hanno sta perduti et presi et
amazadi, che non so si haverete hauto le ditte lettere. De recao ve
rimando la copia, et vi prego che mi faciate sapere de le vostre nove
al longo, per questo presente portador; azò che le menzogne et false
inventioni di nostri inimici, noi hanno creduto far grandi danni et
dispiazeri, et desviar assà di boni amici dil Re. Ma Dio sia laudato,
che la verità di la vittoria de se est notoria, et clare cognosciuta
tante volte, a fine che non facemo de recao sua utilitade de false
inventioni. Io vi prego che spesso me scrivete de vostre nove, et la
verità; et mandatine le lettere che vorete scriver al Re, perchè ho
preso intelligentia per farle tenir secrete fino a Siena a mons. de
l'Isle, che seguramente le manderà al Re. Mons., despò le ditte
lettere, noi havemo per conto seguro che 'l Re sie arivato a Casal, et
a questa hora pol zonzer mons. d'Orliens. Noi havemo la vegnuta de'
mei signori lo principe d'Orange et mareschalcho de Riuss con una
grandissima armada. Mons., io prego a Dio che vi daga bona vita et
longa et vittoria contra nostri inimici. Mandatine la risposta a Gaieta,
per la far me tegnir come ho scritto al capetanio.
Scritto in Roma, adì 19 Luio 1495.
Io tutto vostro,
Cardinal de S. Denis.

Copia de un'altra lettera de uno franzese, che nara al


suo modo la rotta.

Villa nuova. Luni ultimo, che fo 6 de questo mese, lo Re desfece in


bataia el marchese de Mantoa con tutta l'armada de' Venetiani e
parte de quella del Duca de Milan, le quale stavano al numero de 25
milia in 30 milia persone, et poi che hanno sta bene batuti, si poseno
ben a l'andar. Io vi assegno la più bella et grossa compagnia che mai
homo habia visto, et meglio in hordene al mondo. Et a fine che voi
sapiate meglio la facione, per contar ai altri, voi dovete saper che
per il Domenega davanti, la matina, loro arivò a Fornovo, che è do
mia del suo campo, et credeva el ditto sig. che al ditto zorno avere la
battaglia, perchè aspettava soi inimici più de 8 hore sopra la bella
riva; et quando vete che loro non volevano marchar avanti, lui s'è
logà de fora dil ditto Fornovo, apropinquandosse, e lo dì driedo, che
fo el dì de la batalia, el ditto sig. partissi del suo lozamento intra 7 et
8 hore la matina, per andarse alozar viso a viso del ditto campo, de
l'altra banda de l'acqua per tutto. Et in camino li inimici per 4 bande
in terribelmente et bello ordene et lo più malitiosamente, a quello
che dicono i vechij capetanei, come era possibele; dove nui
marcheremo verso lo antiguarda et sguizari. Et potevano esser in
questo squadron de 300 in 400 homeni d'arme con 1000 pedoni.
Arente loro, più alto, a sua man dextera, marchava l'altro squadron,
per venir dar sopra la costa de nostra avantiguarda. Et li doi grossi
squadroni che stava in camin, de 400 in 500 homeni d'arme, et le
più zente da bene, passarono lo ditto fiume, poi noi, per venir dar
sopra la battaglia dove era il Re in noi, fazando sempre scaramuze
de Stratioti per ne atargar. Et fezeno sì grande diligentia, queste due
ultime squadre che vi parlo, che rimanerono li primi intra de noi, a la
banda dove stava al Re; et forno sì bene reculati, che forno rotti et
messi in fuga, et sopra el campo et ala che li fo dado, forno morti
bene 3 o 4000 homeni d'arme, senza piar nissuno presonier. Inter li
quali fo morto el sig. Redolfo, barba dil marchexe de Mantoa, che
stava el più homo da bene havesseno; uno altro signor, che si
dimanda conte Bernardino et lo fratello dil sig. di Corezo, con 15 o
ver 16 capi de squadre de quelli che erano li più valenti. Et quando
lialtri che marchavano contra nostra ditta antiguarda vederino la
ditta rotta, se retegnì subito, et tegnerono scorta d'un lato, et noi de
l'altro, et poi se retirono pocho a pocho. Et credo che, se non
havesse stà perchè non voler azzardarlo tanto, a causa di la persona
dil Re che stava lì, che quelli non haveriano habuto meior marchà
che li altri; nè in logo di chargarli, li fo dati tanti colpi di canoni, che
rimagnò in campo da 3 in 4 mille et 500, et lo campo rimase dove fu
fatto la ditta battaia al Re; lo qual logo dormì tutta la notte, et lì fece
suo lozamento. El ditto Marchexe de Mantoa si era informato dil
vestimento dil Re, et de qual banda stava per quel zorno; et per lo
saper meglio el vero, mandò uno trombetta fino dove steva el ditto
Signor, dimandando trieve per quel zorno, che era cossa strania,
perchè non erano longo uno da l'altro uno trato d'arco, et marchava
per venir fuore. Ergo, quel ditto trombetta parlò a Re, et se è
possuto bene imparar quello che dimandava, perchè havea cargo de
monstrar el Re a suo maistro: le qual cossa credo che fece, perchè
ritornasse incontinente senza altra risposta.
Per le trombete che è stà mandadi dopoi a veder, che stava in
presone de nostra zente, è stà saputo come havia fatto uno
squadron 40 de li soi capi, per piar o far qualche grande despiacer al
Re quel zorno; et forno la più parte de quelli che le...., perchè rimase
più di la mità. Li hanno el bastardo Matheo presonier, mons. de... et
lo bastardo de Pienes; che è tutti quelli che havemo noticia. Similiter
hanno presonier el conte de Petilane, et di nostri non è stà morto,
salvo Julian Bonivel, Panquenarde, Marten et Balaibre; et de questi 4
non se sa nova nissuna, perchè credo che sono morti. El Re non ha
vogliuto che si habbia scritto le nove di la vittoria fin a questa hora,
perchè la fazone de Italia si è de farsse beffe; et che la soa fuzita,
poi che forno rotti, forno verso el so campo, el qual hera fortificato
tante volte. Se il Re havesse voluto, loro havia sì grande fastidio a la
monstration che fenzevano de abandonar, tanto che havesse perso
sue forze che havesse, caminando in quella parte. Ma el Re volse più
presto dormir dove havea stà fato la bataia. Et si avesino sta zente
da bene, sono bene in hordene, ne haveriano combatuto un'altra
volta, ma fin a a questa hora havemo cavalcado ogni zorno senza
trovar loro nè altri che habia dimandato niente, salvo alcuni piccoli
Stratioti che ne fano... Et havemo tanto fatto per nostre giornate,
che doman con l'aiuto di Dio saremo passati a diexe meia arente
tutto il paexe del Ducato de Milano. Et si alcuno dimandasse perchè
mi ve facio la festa oltra sì tosto, si è perchè mons. d'Orliens è tanto
deble di suo contato, che è forza andiamo a darli socorsso; ma
andaremo prima fino a Casal, perchè el convien passar lì per le
grosse fiumere che sono in questo paexe. Intervene er sera al più
tarde a la nostra compagnia la mazor fortuna per loro che poteva
intervenir, si havesse durato; perchè una fiumera, che lo ditto Signor
havea passata una hora avanti, dove li cavalli non erano fino a li
zenochij, in uno momento venne sì grossa, che l'artiglierie che era
driedo, et più di la mità de' nostri Sguizari et qualche 600 homeni
d'arme rimagnereno da l'altra banda tutta la notte. Ma Dio ne ha sì
bene ajutati, che questa matina è discresciuta in modo, che ogni
cossa è venuto verso de nui; et si l'havesse piovesto hozi, erano in
pericolo d'esser combatuti d'una banda, et nui da l'altra, et haveria
stà pericolo de perder. Quelli de questo paese, perchè poteno saper
de novo, dicono che hanno fatto suo poter a seguitarne; et de quelli
de denanti, che sono al Duca de Milan, che, segondo loro, domane
farne qualche vegnuta. Ma poichè semo informati, metremo prova a
far loro come a l'altra volta. Niente de men non credo la mità de
quello che se dice; et se l'intervene qualche cossa, per uno altro, che
mons. de Polysì m'à mandà, ve manderò tante nove. Io credo che
dovete saper più tosto le nove che veneno da Zenoa, che non si fa
de qui; perchè le poste che veneno sono robate, ma tanto, d'uno
camino l'è. Luni medemo che noi combatessemo a Fornovo, dove vi
desiderava con quelli di l'armada che combattino, li ordinati e li.... de
Zenoa, le desfece, et rimaxe de zenoesi zercha 40 o vero 50 homeni
d'arme. Se dise che questa zornata medema mons. d'Orliens fo
asaltato dal Duca de Milano, et have el meglio niente de mancho.
Queste ultime nuove non sono troppo sicure.
Scritto a Orovenze, a dì 10 Luio, la matina, 1495.
Mi havea dementegà a dirve, come a dì de la battaia forno morti più
de mille et 800 Stratioti, et non altro.
Signato: L. de Luxemburgh.

Et queste lettere, benchè siano mal scritte, ad literam sono acopiade


di le autentice, translatade di francese in latino.
In questi zorni, poi che ancora siamo su le cosse dil Reame, in Puia
acadete, come a dì 21 Luio per uno navilio venuto se intese, come
volendossi partir tre nostri merchadanti patricij di Leze, per haver la
Signoria nostra ivi l'armata, fonno ritenuti, zoè Lucha Vendramin, fo
de sier Alvise, et Zuan Querini, de sier Piero, et uno altro. Et li soi
parenti andò a la Signoria, dolendossi di questo, et che dovesseno
proveder. Unde alcuni puiesi scolari, studiavano a Padoa, pur de ditta
terra, fo scritto a li rettori di Padoa li dovesseno far retenir et ponerli
in castello; et cussì fo fatto. Unde dopoi nostri fonno lassati, et
questi fo liberati. Vene ancora lettere del capetanio zeneral di
l'armata, di 17, 18 et 19 Luio, date pur in Monopoli, come tuta la
Puia havea levato le insegne di re Ferandino, excepto alcune roche,
come di sopra ho scritto, et quello comandava la Signoria dovesse
far, recomandando molto il locho di Monopoli, et che si dovesse
mandar custodia, partendo l'armada de lì. Ma lassiamo queste cosse
di Puia, e di altrove scriviamo.

Modo et hordine di le investiture date a Vormes per il


Re di Romani.
Per lettere di oratori a Maximiliano, di 17 Luio, se intese come,
essendo quasi a fine la dieta, el Re volse dar le investiture, et
l'hordine et modo qui sarà scritto. A dì 14 Luio, de marti, la majestà
dil Re, accompagnato da tuti li principi, baroni et oratori, che a
Vormes vi era, et a tutti fonno dati li suoi luogi, andò a dar principio
a far le investiture publice. Primo, sua majestà andò con la comitiva
in uno tribunal grandissimo, fatto su una piaza, et coperto pro majori
parte di restagno d'oro, el resto de pani de seda et de bone
tapezarie; et deseso in una caxa driedo il tribunal, Soa Serenità se
vestì in habito regal, che fo un paro de stivaleti d'oro, l'amito,
camixe, stola, manipolo et streta de vanzelio, damaschino biancho;
sopra, un pivial de campo d'oro. Tutti i ditti paramenti con so frisi
d'oro guarniti, et capuzo recamado di perle, con zoie di ogni sorte di
bon presio. In testa l'havea la corona, ne la man dreta el sceptro, ne
la man sinistra el mondo; avanti li era portado la spada. Tutte le
predette cosse d'oro, di gran precio, con bellissime zoie. Li principi
electori ecclesiastici haveano mantelli da preti, grandissimi, messi
per il collo, come portano li cubicularij in concistorio; in testa
havevano barete de scarlato, longe et conze a piete, come solea
portar i vechii; li manti et i capuzi et le barete fin a mezo erano
fodrate de armellini con le code. Li electori laici haveano questo
istesso habito di pano cremixin; li episcopi non electori haveano i so
mantelli, capuzi et barete di raso paonazo; fodradi di dossi i manti e i
capuzi tutti, et le barete fin a mezo. Li principi non electori haveano
manti de raso cremexin, come quei de' nostri oratori, fodrati
d'armellini senza code, con uno bavaro quattro deda, et un garzo da
pe' et dove el mantelletto è averto, de quella medema largeza. Li
principi che, morte alterius, poteno succeder ad esser electori,
haveano in testa un capello de raso cremexin, fodrato de armellini,
voltado davanti in suso, et da driedo in zoso, a modo de caloieri
grechi. Li altri haveano barete pur di raso, con un frixo di 4 deda di
armelini. Li langravij questo instesso habito di raxo pavonazo, fodrà
di dossi, et li marchexi fodrà di vari. Et poi sua majestà si messe su
una sedia con li electori a torno, da la banda dreta li prencipi
ecclesiastici et da la sinistra li laici; et investì prima li arciepiscopi
Magontia et Coloniense, et poi el conte Palatin et el duca Federico de
Saxonia. Cadaun di loro con 400 cavalli, tutti vestidi ad una livrea,
con un stendardo rosso che dinota la fedeltà et omagio de l'imperio,
et tanti altri stendardi quanti stadi che uno hanno, con titolo di
marchexe in suso, con le arme dei stadi: el duca Federico ne havea
12. Li arciepiscopi haveano su una maza ligadi con un cordon li sigili,
perchè uno è chanzelier per Germania, l'altro per Gallia, et l'altro per
Italia. Li electori laici haveano su li stendardi rossi quello hornamento
che è suo ufficio a portar davanti la majestà dil Re, come el conte
Paladin, el mondo; el Duca de Saxonia, la spada; et el sceptro, el
marchexe de Brandiburg. Quelli erano a cavallo haveano una
bandiera picola su la testa dil cavallo, et una su la testa loro, con
l'arma di quel stado dal qual i hanno la principal domination. A
questo modo cadauno di loro veneno con i so 400 cavalli corando
fino al tribunal, et desmontati di bon passo a la presentia dil Re, e
ditto alcune parole in thodescho, preseno li stendardi furono buttadi
a la ruffa. Poi la majestà dil Re fece molti cavalieri, tra li altri domino
Urban d'Alba, orator di Monferà. Nel far de le investidure, el vene
molti jostradori ne la piaza, con lanze grossissime et feri moladi,
adeo che ogni volta che i corano, etiam andasseno pian, ciaschuno
chi con li chavalli et chi da per loro..... zercha a li luogi de li oratori
fu pur qualche garbuglio: tra uno orator di Hongaria et quello di
Napoli, nostri et quel de Milan. Da un canto era li oratori di Spagna,
Napoli et Milan; da l'altro, Hongaria, Venetiani, et Monferà, et li
oratori di alcuni Vescovi. Et è da saper che Maximiliano non volleva
terminar, li nostri dovesse precieder Milano, ma voleva tenir la cossa
in discussa, con assegnar luogi che si potesse dedur raxon ad
utramque partem; tamen pur nostri, sì come a Roma et in ogni loco
hanno sempre precedesto a Milan, et etiam al presente li andarono
di sora. Et il zorno sequente, Soa Majestà, similibus solemnitatibus,
investì l'arciepiscopo Triverense, el duca Alberto do Saxonia, el duca
de Metelbur et el duca Federico de Brandimburg; et a dì 16 poi
investì el Langravio d'Axia et alcuni altri marchexi et prencipi.
Insumma fece zercha 30 investidure, che era bellissimo veder quelle
cerimonie. Et per lettere de ditti Oratori, oltra di questo la Signoria fo
certifichata, che a dì 15 lì era intrato el duca Henrico de Brunxvich
con 350 cavalli in arme, benissimo in ponto; et molti di loro armati
quasi a la italiana; e benchè su le arme non havesseno sopravesta
alcuna, qualche uno havea etiam le barde; el resto erano armati a la
leziera, tutti vestiti ad uno modo con genere suo. Et questo Ducha
fra 3 zorni se dovea partir per Italia, et in effetto venne, come dirò di
sotto. Di la dieta, molti diceva era conclusa, altri era prope
conclusionem.
Item, che a dì 14 da sera haviano ricevute lettere, el Re, di 7, da
Milano, con exempij di lettere dil conte di Caiazo, de 6, che narava el
conflitto de' nostri con franzesi etc. Et quel zorno, a dì 17, ditti
oratori andò a disnar con l'arcivescovo Coloniense, uno di electori di
l'imperio, el qual li fece uno solennissimo et degno pasto, dove
rasonono assa' cosse zercha a queste cosse de Italia. Et hæc satis.

Novitade di Cesena.

Sì come ho scritto di sopra di le novitade seguite in Cesena, a dì 12


Luio, et pur non cessando, Guido Guerra da Bagno intrò dentro con
alcuni partesani a la fine di Luio, et teniva da la parte de Tiberti, et
fece far uno bastion fortissimo tra la rocha vechia et la strada, per
obviar el socorso potesse esser dato da quel canto a la rocha nova.
Item, fece far certo reparo, o ver parapeto, in la murada, azò quelli
di la rocha nuova non potesseno offender la terra, et che quelli di la
terra potesse socorrer quelli di la rocha vechia.
Item, come per lettere di Andrea Zanchani, podestà di Ravena, se
intese, et etiam per una lettera de Collela Grego, contestabele a
Cervia, el qual mandò uno Francesco d'Alexandria, suo caporal,
homo fidato et sufficiente, lì a Cesena a inquerir, et poter notifichar
esso podestà dil tutto. Come, a dì primo Avosto, a hore 15, Guido
Guerra disse a tutti li soi cittadini: Andate a disnar, poi tornate tutti
armati; judicava per dar la battaglia a la rocha nuova, tamen non
seguite altro; et che aspettaveno 500 fanti di Bologna. Et a di 12
steteno etiam in arme, et a hore 24 ne gionse 50 fanti di ditto
numero. Et in ditto zorno, a hore 21, fo fatto publica crida, che tutti
li marangoni se ritrovasseno in piaza con li istrumenti soi, quali
subito veneno in gran numero, et ritornono ne le murate, dove si
messeno a lavorar getti, scale, et ogni altra cossa necessaria per dar
una battaglia. Et a dì 3 da matina fece portar in Cesena gran
quantità di legnami per coprir il ponte di la porta dil fiume, acciò
potessesi intrar e ussir di la terra per ditto ponte senza offesa di la
rocha, et comenzono a lavorar. In questo zorno li fanti cridavano:
Siega! Siega! Bagno! Bagno! ch'è la caxada di Guido Guerra. In la
rocha era zercha 50 homeni d'arme, li qualli se difendevano
virilmente. Et l'arcivescovo di Arles, dal qual causa dite novità, se
ritrovava a Montifior, et diceva volleva venir a Cesena con le zente dil
sig. di Pexaro e ducha di Gandia. Tamen, Piero Michiel era lì a
Pexaro, a guidar ditte zente, sollicitava di menarle in campo a
Novara. Et a dì 3 Avosto venne a Ravena dal Podestà uno domino
Thomaso Buzardo, cuxin del prefato episcopo, con lettere
credentiale, dicendo esso episcopo havia terminà di andar a socorrer
la rocha di Cesena, et desiderava saper si la Signoria nostra li havia
dato alcun hordine di darli quelle fantarie eran lì; et si tal ordine non
era zonto, perchè il teniva fusse in camino, pregava ge le volesse
consentir, perchè si dubitava non la expugnasseno. Et el podestà si
excusò, non havia altro hordine, nè potea darli senza licentia di la
Signoria. In Cesena in questo mezo la rocha era bombardata, et loro
di rocha bombardavano etiam. Et vedendo il Pontifice queste novità,
mandò uno breve a Guido Guerra, che sub poena excommunicationis
non dovesse turbarli la sua città di Cesena, imo ussir de lì, et lassar
viver pacifice quelli cittadini, nè impazarsse in quelle cosse; et che
mons. lo episcopo di Arles potesse andar al suo governo di ditta
terra. Et zonto ditto messo a Guido Guerra, quello lo fece statim
impichar a uno arbore con il breve davanti il collo, che fu cossa assà
crudel. Tamen, dopoi fonno sedate le discordie, et il Pontifice mandò
uno altro governador, chiamato domino Nicolao Fiesco, genovese,
episcopo di Forlivio, vedendo el populo non volleva questo vescovo
di Arles. Et non quattro mesi dopoi, ditto Guido Guerra, quello fece
ad altri li fo fatto a lui, come tutto di sotto sarà scritto.
A Venetia, a dì primo Avosto, essendo compito di fabrichar el fontego
di la farina a San Marcho, ch'è bellissimo; et questo fo decreto per
più comodità dil populo, che cussì come era uno a Rialto, ne fusse
uno a San Marcho; et eletto do signori, li qualli fonno Benedetto da
Molin et Marco Falier, fatto li fontegeri, et quelli havesseno custodia
di quello. Or in questo zorno fo fatto una precession di Rialto a San
Marcho, con trombe et pifari, con uno San Marcho biancho, et tutti li
fontegeri et fachini che portono su le spalle 460 stera di farina per
metter in ditto fontego; poi vene li signori scrivani etc. Et fo di
sabado, et comenzono a metter farina dentro et vender. Et il
marchexe di Mantoa mandò in ditto fontego stera 400 di farine, le
qual fusse vendute lire 4 el ster, acciò el populo havesse bon
merchato, che vallea lire 5 il ster; sì che a questo modo have
principio ditto fontego.
A dì 30 Luio, in Pregadi fo messo 4 decime, do al monte vechio et do
al monte nuovo, a pagar una fin mezo il mexe di Avosto, l'altra per
tutto il mexe; et si possi metter arzenti in zecha, juxta el solito. Et la
parte prima fo presa, et fo dato tal cargo a Maffio Soranzo, fo di
domino Vettor, cavalier et procurator, havesse tal arzenti a receverli,
et con una bolleta de li provedadori dil sal erano fatti creditori a la
camera de imprestidi al monte nuovo. Et poi, a dì 7 Avosto, fo preso
che chi pagava le do decime donate in termene di zorni 8, zoè fino a
XV dil mexe, havesse di don ducati 12 per cento; le qual decime era
numero 55 et 56, et quelli davano arzenti al sal, a ducati 6 la
marcha, saranno fatti creditori di le decime numero 57 et 58. Item,
che quelli pagava al termene le decime dil monte nuovo, numero 38
et 39, habino di don ducati 5 per cento, oltra il pro'. Queste provision
fo causa si scodesse da ducati 25 milia in su per decime, ma fevano
per richi et non per poveri, perchè ad ogni modo li poveri non
pagava se non con pena poi di X per cento a le cazude, et non havia
dono alcuno. Sì che nostri feva ogni cossa per trovar danari, per la
grandissima spexa haveano, maxime dil campo a Novara.
Ancora in questo zorno fo preso, l'armada marittima era a Monopoli,
fortifichato quel locho, et lassatoli custodia et uno soracomito per
governator, qual paresse al zeneral, poi dovesse passar a Corffù, et
ivi star fino la Signoria nostra li comandava. Et zercha questo fo
assa' disputato, però che era tre oppinione di Savij di Colegio: alcuni
volleva ditta armata andasse a Napoli, per dar reputation a re
Ferando; altri andasse a Zenoa, poi a Niza di Provenza dil re di
Franza; altri a Corffù. Et questa fu presa, et spazato al capetanio
lettere. In questo mezo si amalò di dopia terzana; et poi, alquanto
migliorato, messe governador in Monopoli Nicolò Corner, era
soracomito, et in Pulignano Nicolò Paladin, cavalier, era
soracomito.... Et poi, a dì 12 Avosto, nel conseio di Pregadi, per le
nove succedeva di Napoli, fo decreto ditta armada, col capetanio
zeneral nostro, Antonio Grimani, procurator, el qual era quasi varito,
dovesse andar a Napoli; et questo per haverla con grande instantia
el Ferandino richiesta. Quello seguite scriverò di sotto.
In questi zorni fo mandato in campo ducati 6000 al Marchexe di
Mantoa, capetanio zeneral nostro, a ciò facesse 1000 provisionadi
per guarda di la sua persona. Et ditto capetanio, abuto la nuova di la
sua creatione, scrisse una lettera a la Signoria, di sua mano,
rengratiando, promettendo fede perpetua. Et a dì 3 Avosto, per
Colegio, fu eletto pagador in campo, in luogo de Daniel Vendramino,
era amalato, Orssato Morexini; et abuto danari de qui, a dì 10 ditto,
et venuto a Padoa, et sic successive per le camere, havendo danari
per poter far la paga al suo zonzer; et menò con lui rasonato Andrea
di...., scrivan a la camera di Padoa.
A dì primo Avosto, nel conseio di Pregadi fu conduto il conte di
Petigliano, zoè scritto a li Provedadori in campo dovesseno tramar di
accordarlo con la Signoria nostra, con fiorini 30 milia in tempo di
pace et 40 in tempo di guerra, per anni 5, titolo di Governador
zeneral, tengi cavalli 1400; ma lui non volsse aceptar, et tamen si
adoperava a li exercitij dil campo. Pur a la fine con più summa fo
conduto, come, descrivendo le cosse seguide questo mexe in campo,
sarà scritto. Et il sig. Virginio Orssini, habuto licentia da' nostri et dil
Duca de Milan, ritornò versso Roma a li suoi castelli.
In questo zorno, zonse in questa terra una bellissima reliquia, zoè la
anconeta che fo dil Re di Franza, portata per uno di Val Brembana,
chiamato Cristallo, el qual era ballestrier dil Marchexe di Mantoa,
bandito dil brexan et bergamasco, al qual prima li fo fatto salvo
conduto. Et con lui vene uno cittadin di Bergamo, chiamato el conte
Urssino di Rotta, fidelissimo nostro, et quello mi baptezò io Marin
Sanudo, compositor di questa ystoria. Et per saper il tutto, havendo
questui in campo preso uno franzese di anni zercha 66, chiamato
Cabriel Molendina, el qual era stato, ut dicitur, a servicio dil Re di
Franza, et li trovò ditto Cristallo adosso ducati 101, o vero scudi....,
questa anconeta con zoie et degnissime reliquie, zoè di la vesta di
Christo et tutti li misterij di la Passione, cossa di farne grande
extimatione; et uno subioto d'oro ch'el Re talhora sonava,
chiamando certi chani.... Et habuto tal cosse et questo preson, si fuzì
di campo, et vene in bergamasche; et conferito con ditto conte
Urssino, come havia tal cosse, lui consigliò dovesse venir a
presentarle a la Signoria, che li faria di gran bene. Et lui dicendo non
era mai stato a Venetia, nè sapeva a che modo far; unde ditto conte
Urssino, fidelissimo, volse venir im persona a sue spexe a menarlo a
ditta Signoria nostra. Et, zonto, li fa fatto salvo conduto per anni 100
et uno, et presentato la ditta anconeta, a tempo era reduto el
Conseio di X, et vista con gran devotione per le cosse sacre eran
dentro, come per lettere in francese pareva, vi fosse etiam zerte
perle et zoie atorno. La qual vidi et basai in la capella de' Procuratori,
con gran devutione, perchè ivi fu posta, poi messa nel santuario di le
zoie. Et volendo remeritar a questui portò tal presente, li dixeno
dimandasse quello volleva. Rispose, esser cavato dil bando; et cussì
fu fatto il salvo conduto. Demum, a dì 18 Avosto, preseno de darli
ducati 10 al mexe di provisione, et ducati 50 per spexe l'havia fatto,
et ducati 100 de beneficii, zoè de intrada a l'anno a uno suo fiol, et
habbi la taglia data a ditto franzese, che era ducati 300, et li 100
ducati li trovò adosso; sì che fu assa' remeritato. Ma ben, prima li
desseno alcuna provisione, scrisse a li rettori de Bergamo dovesseno
mandar de qui ditto franzese, era lì in custodia; et cussì mandato,
zonse in questa terra a dì 7 ditto, fo messo in caxa dil capetanio di le
preson. Et poichè fo examinato, fo dato et restituto a ditto Crestallo,
che lo havia preso. Et per quel poeta nominato di sopra, fo fatto a
questa anconeta, o vero paxe, epigrama, zoè questo:
Epigramma de anchoneta ac reliquiis acceptis a
Gallis.
Abstulit a Gallo pacem Deus armipotente;
Quid mirum, pacem si modo Marcus habet?
Despexit pacem Gallus. Miracula cernis:
Anchoneta patet, paxque reliquit eum.
Hanc Crystallinus rapuit, qui bergomas extat,
Maximus hic meritis perspicuusque suis.

A dì 10 Avosto, zonse in questa terra uno gripo, sopra il qual domino


Prudentio da Trane, era capetanio dil Re a Monopoli, et menato per
Alvise di Albori; et, poi che stete alcuni zorni qui, fo lassato andar,
havendo habuto salvo conduto dal capetanio zeneral.
A dì 12 ditto, vene lettere di Antonio Vincivera, secretario a Bologna,
come el magnifico Joanne havia per spie, el Re de Franza a Turim
stava di malavoia, per esserli morto in la bataia 83 baroni, et che per
tutta la Franza era levati assa' coroti.
A dì 6 Avosto, zonse lettere per la via di Zenoa, di Francesco Capello,
kav., et Marin Zorzi, oratori nostri al Re et Raina di Spagna, date a dì
12 Luio in Burgos. Narra come erano stati da Barzellona fin a Burgos
in camino zorni XXI, et passato per lochi amorbati, et cativi
alozamenti habuti a Barzelona chatelena, Saragosa di Ragon;
demum assa' honorati. Et che a dì 6 ditto, zoè Luio, di Luni, fo il
zorno di la bataia, ritrovandossi mia 3 di Burgos, li veneno contra
molti signori et gran maistri, zoè li presidenti de la città de Burgos, el
comandador mazor, tutti li cavalieri, il comandador di Chalatra', il
comandador di la Cantara, il comandador di Lion con cavalieri di
l'hordine di San Jacomo, el conseio de Aragon, el conseio de
Chastiglia, lo arziepiscopo di Messina, lo arziepiscopo di Calgos, lo
episcopo de Burgos, de Vallentia, lo episcopo de etc. Item, de Villa,
de Salamanca, de Tui, de Almeria, de Maioricha, de Barzelona con
altri prelati, el ducha di Nazera, conte di Benivento, l'armirante di
Ragon, conte de Niena, conte di Goziano, conte di Trivigno,
marchese di Villafranca, presidente di Moran, prescidente de
Chastiglia, signori et baroni et cavalieri assa' altri; in tutto 3000
cavalli, fra i qual era 200 mulle. Et a hore 24 faceva l'intrata in la
terra; et il Re et la Raina erano a le finestre, et con gran jubilo dil
populo introno a questo modo. El Capelo con l'arzivescovo de Milan,
ambassador dil Duca, et il Zorzi con l'altro de Milan; et andati a lo
alozamento. Poi el zorno driedo, ebbeno audientia. Era sentato il Re
et la Raina su do sedie regal, et li fece bona et perfetta ciera, et
volse tutti 4 sti oratori lì sentasseno per mezo, su uno scagno. Et
presentate le lettere di credenza, Marin Zorzi li fece una oration
latina; et il Re li fece risponder a uno maistro Diego, frate
predichator valentissimo. Poi Zuan Battista di Sfondradi, orator de
Milan, fece la sua oratione et risposta. Andono el Re, la Raina et
questi 4 oratori in una camera secreta; et Francesco Capello
notifichò a Soa Majestà el bisogno de Italia, et che dovesse romper
al Re de Franza. Et il Re disse che ad ogni modo el volleva romper, et
che 'l manderia di ogni ij uno; et dimostrò poi lettere havia di
Perpignano, come Franzesi li havia scritto, che dovesseno levar ditte
zente, che etiam loro si leveria. Item, che havia cavalli 13 mille et
8000 pedoni, et che scrivesseno in questa terra et a Milan, che certo
romperia, perchè la liga lui la voleva mantegnir, et esser amico
nostro.
Per lettere di Fiorenza, a dì 8 ditto, se intese come Fiorentini,
seguendo pur l'impresa di reaquistar Pisa, et etiam Monte Pulzano
da' Senesi, in questi zorni a presso Cassina et Monte di Sasso fonno
a le man con Franzesi, et ne rupe zercha 200; parte di qual fonno
aperti per mezo, perchè si divulgavano haveano danari ne le viscere,
tamen non trovono alcuna cossa. Et pur non restavano Fiorentini di
volersi acordar et far liga con il Re. Do loro ambassadori erano a
Turin; et certo si divulgava, tal liga et amicitia havesse a esser causa
di perturbar Italia, per aderirsi a esso Re. Quello seguite, et le lettere
scritte zercha questo, di sotto intenderete.
Per la venuta di le nave di Soria, le qual zonseno a dì 16 ditto, et per
lettere di Damasco, nostri fo certifichati come el sig. Turcho havia
mandà uno ambassador al Soldan al Chaiero per queste cosse de
Franza, havendo mo assae paura, et che de li Mori quasi vollevano
far garbuio a le natione, dicendo: Questo Re di Franza prosperava, et
vuj non reparate. Unde ne veniva a dischatiar nuj, sì come le
prophetie loro dicono, che a questi tempi la sua leze deva patir. Unde
Zuan Vallaresso, consolo, chiamato il conseio di 12, terminono di far
certe lettere false, pareva venisse de qui, per le qual si advisava esso
Re de Franza era rotto et andato in malhora, come, ita volente Deo,
fu pocho da poi; et di questo deteno sacramento a tutti, adeo,
mostrate queste lettere, Mori fonno aliegri, et non seguite altro; pur
merchadanti stevano con gran paura di loro. Et oltra di questo se
intese come il Soldan, havendo inteso che nel monasterio di frati di
monte Syon in Jerusalem, li frati haveano arme nel convento, et che
aspettava el Re de Franza, unde mandò alcuni Mori lì a veder, et
vollea ruinar el tempio e occider li frati; et, cerchato ben per tutto,
non trovono se non cortelli da taiar dil pane; et li frati li dixeno non
erano di tal sorte, nè venuti a la religion per tenir arme ascose, et
che era vania et calunnia. Unde, trovato la verità, non seguì altro.
A Roma el Pontifice, exortato da li oratori di la liga, et maxime dal
veneto, dovesse excommunichar el Re de Franza, a ciò tornasse in
Franza, lassando pacifice Italia, unde, chiamato concistorio et
desputato, deliberono di farli uno brieve, el qual sarà qui sotto
scritto; et questo per lettere di 3 Avosto di Roma se intese; et voleva
mandar uno mazier fino a Turin a portarlo. Anchora fece esso
Pontifice in concistorio uno nuovo decreto, che de cætero, li 4
Patriarchi siano cardinalli, zoè quello de Jerusalem, di
Constantinopoli, di Antiochia et Alexandrino; et questo fece perchè
aliquando in corte fra ditti Patriarchi et Cardinali sono venuti in
contrasto zercha a li luogi, perchè li Patriarchi dicevano dover
preceder et esser propinqui al Pontifice, et Cardinali non vollevano;
et questo fo causa di l'odio ha el Patriarcha da cha' Lando nostro in
corte per haver voluto precieder; unde non l'hanno mai voluto far
cardinal, et tamen è dignissimo prelato. Hor el brieve dil Pontifice,
mandato al Re de Franza, scriviamo; el qual fo traduto in terza rima
per Zorzi Summarippa, veronese patricio, et butato a stampa; ch'è
belissimo lezer.
Exemplum brevis sanctissimi Domini nostri ad Carolum Regem
Francorum [140].

Cosse seguite in campo di Novara, dil mexe di


Avosto, succincte descritte.

Vedendo questa gallicha historia, per le cosse successe et qui


verissime descripte, venir assa' grande volume, unde mi è forzo di
abreviar; et però, pretermetendo lettere per li tempi zonzevano in
questa terra di campo, però che una al zorno almancho era scritta a
la Signoria per li Provedadori, solum qui scriverò zorno per zorno
quello seguite dil mexe di Avosto, et sic poi successive in ditto
campo. Et nil miremini, lectores; chè, licet non me habi trovato
presente, ma tutta la verità, nil praetermisso che sia da conto, qui
scriverò, et prima:
A dì primo Avosto, pur essendo el campo nostro a Castel Chiasol
sotto Novara, et in grandissime desputatione di levarse, Ducheschi
volevano se tirasse più avanti, et li Provedadori volevano redurse in
loco securo. Unde el Duca de Milan scrisse el zorno driedo vollea
venir in ditto campo.
Item, in questo zorno esso Duca mandò una lettera al sig. Galeazo
suo capetanio in campo, notifichandoli esser conclusa la liga con la
compagnia dil Bo, o vero li sette comuni che sono sguizari, i qualli fin
hora hanno dato assa' aiuto al Re de Franza. La qual nuova, intesa
da' nostri, fo tenuta perfettissima. Et poi venuto a Milan, li capitoli
sigillati, di questo fece gran dimostratione di alegreza, facendo fuogi;
et cussì in campo. Questo accordo fo fatto per forza de danari; et fo
divulgato esso Duca de Milan le deva ducati 30 milia in tempo di
pace et 40 milia in tempo di guerra. Et ditti sguizari mandono a dir a
li sguizari erano in campo dil Re de Franza, et quei sono in Novara
col Duca di Orliens, in termene di 3 zorni si debbino redur in loro
paesi, sotto pena di rebellione et confiscation di beni. Et cussì in
campo aspettavano ussisse li sguizari di Novara.
In questo zorno vene una spia nostra da Verzei, mia X di Novara,
dove il Re havia mandato cavalli 400 et 3000 pedoni, et continue
veniva li franzesi; notifichava il Re esser a Turin, et si aspettava a
Verzei a dì 2 ditto; et che judichava in tutto, ivi, fin quel hora, vi
fusse di le persone 8000, et divulgavano di venir asaltar il nostro
exercito; et ditta spia, per esser tolto suspetto, ebbe cinque ferite.
A dì 3 ditto, Bernardo Contarini, provedador di stratioti, scrisse a la
Signoria una lettera, come li era stà dati in governo li altri stratioti da
poi el partir de Piero Duodo, i qualli si sforzerà di governarli secondo
le sue picol forze, non sparagnando faticha etc.
Item, che inteso la creation de lo illustrissimo sig. Marchexe,
capetanio zeneral, per segno di alegreza, havendo uno cavallo
bellissimo leardo de valuta de più de ducati 100, el qual lui lo havea
guadagnato, et quello alegramente donò; stratioti prendono qualche
sacomano franzese, discalzo et in camisa, unde li bastonò et cazono
in la terra; et ultimo, havendone preso alcuni, per più disprecio de'
franzesi, esso Provedador fece stratioti li vendesseno per uno melon
l'uno, tanto pocho li stimavano.
A dì 2 ditto, el Duca de Milan con soa moglie et oratori di Spagna,
Napoli et veneto, con la soa corte partì di Milano et vene a
Vegevene; demum in campo. Et questo zorno, a hore 6, venendo la
Domenega, fo a dì 2 Avosto, montò a cavallo el capetanio zeneral
nostro, et el suo capetanio sig. Galeazo, et Bernardo Contarini con
80 cavalli de stratioti, et andono contra Soa Excelentia mia do di là
da Vegevene, et, scontrato con bel hordene, fatto le debite
acoglienze, Bernardo Contarini preditto volsse dismontar et tocharli
la mano; ma il Duca mai li volse tochar, se non montato fo a cavallo.
La Duchessa era con do charete, una coperta di pano d'oro, l'altra di
veludo cremexin; et cavalchando versso Vegevene, molto ringratiò
esso Bernardo di portamenti in suo servitio; et dismontò a
Vegevene; a hore 20 montò a cavallo et vene a Vespole, dove dovea
alozar Soa Excellentia quella sera, mia 6 distante dil nostro campo,
dove scontrò Luca Pixani, provedador nostro, el qual con assa' cavalli
li veniva contra. Et però il Duca volsse passar ditta villa, et in
campagna, tochato la man a ditto Provedador, ritornò ad alozar a
Vespola, et el capetanio zeneral, provedador, et el resto veneno in
campo per quella notte. Poi la mattina, fo a dì 3 ditto, essendo il
Duca a cavallo per venir in campo, volendo ussir di Vespola, la mula
li scapuzò e gittolo in una pozza di fango, per modo tutto se infangò
etc. la veste; subito si mutò, et dove era vestito di una veste
damaschin negro, curta per fino al zenochio, si tramudò in una di
quella foza, damaschin cremexin; et, aproximato mia do dil campo,
el sig. Marchexe, capetanio, con Lucha Pixani, provedador, Daniel
Vendramin, pagador, Bernardo Contarini, condutieri et molti stratioti,
li andono contra, et lo acompagnò fino a lo alozamento dil sig.
Galeazo, suo capetanio, di S. Severino; et nostri tolseno licentia de
Soa Signoria. Li oratori era con lui veneno a smontar a lo alozamento
dil nostro campo; et cussì non seguite altro quel zorno.
A dì 4 ditto, el Duca, capetanio zeneral nostro, et il suo, li oratori
Spagna, Napoli, et li provedadori con Hironimo Lion, kav., orator
nostro, et Bernardo Contarini, conte di Petigliano, et il conte di
Chaiazo, reduti in uno, consultono utrum el nostro exercito si
dovesse levar dove l'era, redurse più avanti, o andar a Vegevene, o
pur star fermo. Et parlò sapientissimamente el conte di Petigliano.
Rispose el Duca. Poi parlò Marchiò Trivixan, provedador; et cussì
steteno in desputation. Et il Duca volsse veder, oculata fide, el tutto;
et chavalchò per li alozamenti, dove Ruberteschi erano di opinione
stesse el nostro exercito; tamen per questo zorno non concluseno
alcuna cossa. Soa moglie, la Duchessa, vene a star con lui in campo;
et, oltra li 3 oratori nominati, havia tre altri etc.
A dì 5 ditto, Bernardo Contarini non potendo correr a Verzei, perchè
non volevano anchora romper guerra a la Duchessa di Savoia, da
matina mandò 200 cavalli de stratioti a la volta de Verzei, per veder
si Franzesi vollevano venir a scharamuzar con loro; et, aproximati a
mezo mio lontano di la terra, trovono zercha 20 cavalli franzesi, et
10 ballestrieri a cavallo di Zuan Jacomo di Traulzi; li quali, visto
stratioti, si messeno in fuga; Franzesi si salvono in la terra; et li
balestrieri fonno tra morti et presi tutti con molte ferite; uno di qual
fo examinato per esso Provedador, et la examination soa mandò a la
Signoria.
In questo zorno fo fatto in campo una mostra zeneral di tutte le
zente; era colateral nostro Hironimo di Monte sopranominato; et el
Duca de Milan nel suo campo, sopra tutte le zente d'arme, Lorenzo
d'Orffeo da Mozanega, et comissario suo Galeazo Visconte. Hor el
Duca con madona soa moglie volse veder questa mostra, che fo
bellissima, et za molti anni non fo fatta simile.
A Venetia, vedendo le cosse de Novara andar a la longa, preseno in
ditto zorno che si dovesse strenzer Novara, bombardarla et far il
tutto per poner fine a l'impresa. Et cussì par el Duca contentasse, et
fusse dato el guasto a la terra, et ogni altra provisione; fo tre volte a
consultatione con li Provedadori, stete uno dì et mezo in campo, poi
tornò a Milan.
A dì 7 ditto, terminato di meter Novara in assedio, in questo zorno
dete principio, che prima la notte intrava vittuarie dentro a loro
piacer; et mandono cavalli 200 con 100 fanti a uno locho mia 4
lontano, chiamato...., per custodia; adeo franzesi più non porano
ussir di la terra.
Item per li ballestrieri presi per stratioti a dì 5, se intese el Re esser
a Turin, e diceva aspettava zente de Franza da persone 20 milia; et
che domino Joan Jacobo di Traulci si trova a Verzei.
In la terra inteseno vin non vi esser; pan rasonevolmente, et che la
notte questi paesani el portano, perchè il pagano bene. Item, nostri
principiono a far le strade per poter dar la bataia a la ditta terra di
Novara, et il Duca di Orliens si confortava con la venuta dil Re.
A dì 9 ditto, nostri corsse et spianò uno castello chiamato Bulgaro,
fra Novara e Verzei; item, seguiteno di dar el guasto a Novara,
tagliando arbori, vigne etc.; et stratioti prese do franzesi et alcuni
chariazi; a la volta di Verzei fo mandato altri 400 fanti.
A dì 10 ditto, el nostro campo se levò dove era, et vene a
conzonzerse con quel dil Duca de Milan, vicino a Novara, in uno
locho chiamato Caxuol; et li Provedadori alozono in castello, el
capetanio et altri di fuora; li pavioni (padiglioni) e tende erano stese,
bellissimo veder, et li stratioti a la campagna, et Bernardo Contarini
sotto una trabacha.
A dì 12, per spie inteseno el Re esser tra Turin et Chier, con la
inamorata sua a Chier, dove spesso andava et stava a piaceri,
recreandossi alquanto de li affanni portati. Et a dì 11 vene uno
trombeta suo in campo a dimandar uno preson; el qual disse, Soa
Majestà era a Chier, aspetava zente, et veria a Verzei poi a
combatter con nostri.
In questo zorno vene fuora de Verzei zercha 100 todeschi, si
atrovava ivi col Re sotto il Traulzi; et questi veneno per il
comandamento di loro capi sguizari; et, venuti nel nostro campo,
ebbeno soldo. Et anchora di altri sguizari di Novara ussite, in summa
numero 250 in tutto, e tutti fonno charezati, e dato soldo da' nostri.
Quelli dil campo duchescho menava in longo di dar el guasto a
Novara, et di ozi in domane menava la cossa; tamen pur da la sua
banda poi conveneno dar.
In Novara fevano gran repari, et ogni zorno se fortifichava sì dentro
come fuori; non haveano vin ma ben axedi, di li qual ne bevevano
quelli baroni, con zucharo butado dentro; formenti assai, et feceno
molini cinque da man; et cussì masenavano in farine; fevano pan
negrissimo et chativo; carne poche, nè non ve haveano se non di
chavallo. Et perchè scharamuzando con thodeschi ogni giorno
franzesi, pur ne era feriti qualche uno, et volendolo miedegar, dicitur
el vuovo valleva soldi 30 l'uno, cossa incredibile, per non esser
galine. Questo tutto si have da uno nostro prexon che fuzite; ogni
notte fevano signali de fuogi, dimandando soccorsso.
A dì 14 ditto, dil campo duchescho se partì alcuni homeni d'arme,
capo uno fiul fo dil conte Zuan Boromeo, et andò a li alozamenti. Li
provedadori si dolse con el sig. Galeazo, capetanio, et con el conte
de Chaiazo. Risposeno, non saper nulla, et che provederebbe a
questo.
Fo scritto a Millano al Duca, mandasse 2000 guastadori in campo,
per esser gran bisogno per le cosse acadeva.
In questa matina, per uno di Monferà, partì di Novara, inteseno el
Duca de Orliens fece far una crida, che, in termene di 3 hore, tutti
quelli non haveano soldo si dovesse partir di la terra, con tutte le
meretrice et li soi homeni; unde se partì tunc 150 homeni non
haveano soldo. Item, mazenavano al zorno, con quelli molini da
man, da manzar per 100 homeni et non più; non bevevano vin za
zorni XV, per esserli manchato. Dil Re si divulgava a dì XV dovea
esser a Verzei, tamen indusiò qualche zorno a venir.
In ditto zorno zonse in campo borgognoni 60 a piedi, belli homeni et
ben armadi. El capetanio zeneral volsse si toleseno a nostro soldo
per uno mese, a fiorini 4 di Rens per uno; erano stati a Milan,
sperando el Duca li desseno soldo più di un mese, et ebbe solum
uno fiorin per uno.
El sig. Marchexe de Mantoa, capetanio zeneral nostro, non se sentì
bene et se amallò di fluxo; stava in letto in una cariola sotto il suo
pavion (padiglione), et li Provedadori lo andò a visitar.
A dì XV ditto, Piero Marzello et Zorzi Emo, i qualli a dì 28 Luio nel
conseio di Pregadi fonno electi oratori a portar el baston et
stendardo di capetanio zeneral in campo a lo illustre Marchexe di
Mantoa; unde, partiti a dì 6 Avosto da Venetia con molti zoveni
patricij, andati per veder il campo, et trombe et pifferi dil Principe
nostro; et zonti a dì 14 a Vespola, la sera ivi alozono. Et la matina, fo
il zorno di S. Rocho, dovendo venir in campo, Bernardo Contarini con
stratioti li andò contra mia 5, et, trovato ditti oratori, veneno di
longo. Et el sig. capetanio mandò suo fratello, sig. Zuane di
Gonzaga, era al soldo de Milan, et Hanibal Bentivoy, pocho lontano
di Vespola; poi li andò contra el conte di Petigliano con un squadron
a cavallo armado a la liziera et senza elmeti; poi andò una squadra
de cavalli todeschi a cavallo, pur armati a la liziera; poi li cavalli
alemani dil Duca, armadi come andavano, zoè il corpo di la curaza,
arnesi, schiniere et zelade. Et zonti ditti oratori con lo stendardo
spiegato et il baston avanti, sonando trombe et pifari, si tochono la
man; et lì fo dimorato alquanto. Et dismontati al pavion dil
capetanio, dove era fatto uno altar da dir messa, con alcune cortine
atorno, fo dil Re de Franza, divisade di raso bianco et veludo
paonazo, con molte lettere dorade di sopra, zoè questi segni C. A.,
che vien a dir Carlo et Anna, la nome di esso Re et Raina. Et qui
sotto era, oltra el capetanio nostro, provedadori et oratori, el sig.
Galeazo, capetanio zeneral dil Duca, el conte di Petigliano, el conte
di Chaiazo, sig. di Rimano, sig. di Corezo, Hanibal Bentivoy, sig.
Gasparo Frachasso con tutti altri nostri conduttieri et ducheschi,
vestidi di zornede d'oro et d'arzento, con belle colladene d'oro. Et el
sig. Marchexe havia una zornea di restagno d'oro, et avanti lui era
uno forzier coperto de panno d'oro, dove el se inzenochiava. Il
stendardo era posto in mezo il pavion, et baston d'arzento sopra
l'altar; et fo cantato una solenne messa, con cantadori, pifari, et
trombe venuti de qui. Et, fornita, fo portato el baston a Zorzi Emo, el
qual dovea far le parole, et il stendardo. El qual apresentò a ditto
Marchexe, per nome di la Signoria, dicendo con gran gravità, che la
Illustrissima Signoria per li soi boni portamenti et opere havia
diliberato ornarlo del ditto capitaniato zeneral, zoè dil titolo di tutte le
sue zente d'arme, et decorar Soa Excellentia di l'insegne dil sceptro
et vexilo dil protetor nostro San Marcho, a conservation et
mantenimento dil Stato di essa Illustrissima Signoria, a honor et
perpetua gloria de Soa Excellentia, et a confusion de tutti li inimici
de quello Illustrissimo Stado, con altre parole di questa substantia.
Et lui rispose: Magnifico ambassador, a mi par impossibele poter
responder a le parole de Vostra Magnificentia, ma dirò ben che non
per merito alcun quella Illustrissima Signoria, ma per l'amor et
benivolentia che quella li portava, la se havea degnà de honorarlo de
tal insegne, dil baston et honorifico vexillo. Lo qual con gaiardo et
forte animo lo accepto, sperando far tal opere, che la Illustrissima
Signoria cognoscerà haverlo conferito a persona che li mostrerà
qualche bon fructo, preponendo el ben, utele et comodo de quello
Illustrissimo Stado a la vita propria, et in fino nel corpo di mia madre
era servidor de la prefata Illustrissima Signoria. Potrà haver uno
capetanio più praticho de mi, ma di fede tale mai lo troverà al
mondo. Et finito, tutti andono al suo lozamento; et li ambassadori
veneno alozar con li Provedadori, et la sera fo convidati li
zentilhomeni a zena col capetanio a uno suo pavion, et cussì poi la
mattina a disnar alcuni andono etc.
In questa notte passata, el sig. Galeazo, capetanio dil Duca, et el
conte di Petigliano andono asaltar li borgi di Novara con zercha 8 in
X milia persone, tra cavallo et piedi, da diverse bande, per brusarli si
tenir non li potevano. Et da una banda esso sig. Galeazo con 5000
alemani et 400 cavalli, da l'altra el conte de Chaiazo con alcuni altri
pedoni et cavalli, da la parte verso Vegevene la nostra zente col
conte di Petigliano; et l'hordine era di andar do o ver tre hore avanti
zorno, ma non andono ducheschi se non a l'alba. Et cussì nostri,
acostati a ditti borgi, principiò a fichar fuogo in alcune caxe, et con i
nimici principiono a scharamuzar. Fonno rebatudi fino a le terze
sbare, per modo comenzono a trazer bombarde, passadori et freze;
li nostri con schiopeti et passadori. Et in questa baruffa fo morti de'
nostri zercha 200, feriti alcuni; et da una spingarda fo morto Alvise
Lanza, contestabele nostro; li altri moriteno, fonno alemani dil
campo duchescho, et de' nostri zercha 64; et, si asaltavano a l'hora
deputata, nostri certo ottenivano li borgi.
In ditto zorno, di 15 ditto, zonse lettere di la Signoria di 12,
cometeva dovesseno nostri far corarie fino a Verzei, brusando etc.,
perhò che li ducheschi numquam havia voluto, dicendo Madama di
Savoia era parente dil Ducha, et non era bon farli danno, perchè era
costreta a far quello la faceva, non potendo resister a' franzesi.
Item, questa sera zonse el nontio dil Pontifice in campo con la
scomunega dil Re di Franza; era mondano, et mandò uno dal Re a
dimandar salvo conduto.
Per uno preson nostro, era in Novara, rescatato et pagato la taia,
vene in campo et referite esser gran fame in la terra; masenavano a
man, non haveano vin se non chara 5 in tutta la terra, assa' amalati
da ponta. Et questa notte, tre hore avanti zorno, alcuni cavalli di
Verzei con farine intrò in Novara; et che si aspettava venisse il Re a
darli soccorsso.
A dì 16 ditto, li Provedadori fece lezer la lettera di la Signoria al
capetanio, andati a soa visitatione con li oratori. Et disse, era stato
sempre di questa opinione; et che se dia etiam el guasto a Novara,
con mortari et mangani trazer a la terra; le bombarde grosse, erano
mia cinque di là de Vegevene, di l'hordine dil Duca fo tornate ivi.
Item, 100 alemani, fuziti dil Re, nostri soldono con fiorini de Rens 4
al mexe per uno. Et li do capi referite esser tre settimane erano
partiti di Aste, dove era il Re con persone utele et inutele 13 milia;
haver solum 3000 alemani, di qual eran scampati 1500; tamen poi li
zonse altri mille et ducento, et quelli fuzino fo per non haver le so
page.
Item, che 'l Re havia mandà in Franza per danari, ma non li havea
potuto haver, però che dicevano, vollevano prima Soa Majestà vadi
in Franza, poi faranno quella deliberatione li parerà; et ch'el Re
volleva venir, passà questo caldo, a Verzei, a far la massa, poi
socorrer Novara.
Item, zonse in campo nostro 200 elemani, venuti di Elemagna per
haver soldo, et per conseglio de domino Zorzi di Pietra plana,
capetanio di li elemani ducheschi, nostri li asoldono. A tutti fo dato
sacramento per el ditto Zorzi, juxta el solito, di fedeltà; tamen
haveano poche armadure.
In questo zorno zonse in campo Orssato Morexini, pagador, con
ducati 18 mille. Li andò contra Bernardo Contarini con alcuni
contestabeli et stratioti.
Quello andò a Turin, per tuor il salvo conduto per il Nontio dil Papa,
ritornò dicendo bisognava saper la sua nome.
Per do sacomani de Reame, era con Zuan Jacomo de Traulzi, fuziti di
Verzei, venuti qui, et riferiteno li soldati taliani in Verzei esser mal
voluti da' franzesi, et che alozano separati da loro, et in tutto sono
da 8 in 10 millia persone, tra le qual 2000 alemani et alcuni
guasconi; et che era zonto, za tre zorni ivi, el sig. Constantin Arniti,
venuto da Monferà con cavalli 40, et aspettava il resto fin 100
homeni d'arme; cento era con il Traulzi, el resto franzesi; et
vollevano metter li pavioni fuora di la terra, ma pur terminono de
aspettar el Re; tamen haveano gran paura de stratioti; dopoi che i
preseno i ballestrieri dil Traulzi, dicevano voler venir contra nostri e
intrar in Novara.
A dì 17 el Duca de Milan scrisse in campo, esser contento si cora a
Verzei, et si riportava al suo capetanio; et cussì consultato, el conte
de Petigliano et el conte di Chaiazo erano di oppinione. Ma pur el
sig. Galeazo slongava.
El capetanio zeneral nostro, migliorato, ussì di lo alozamento, et
vene da li Provedadori; tamen non era ben varito.
In campo nostro era za zonti 40 homeni d'arme di la conduta dil
Duca di Gandia, sotto questi, videlicet: sotto il conte Christofaro di
Gonzaga, numero 20; sotto Iacomo da Poiana, vicentino, numero 8;
sotto Zenon Avogaro, da Treviso, numero 8; sotto il Zenoese, era con
il prefetto, numero 2, et do altri separati. Questi erano
mediocremente a cavallo, ben armati, atti homeni a cavallo, ma in
arte militar inexperti, dil Zenoese in fuora. Haveano habuto ducati 30
per curaza da domino Aloysio Becheto, orator dil Papa qui a Venetia.
Venne Francesco Grasso da Roma, et 4 contestabeli, zoè Zuan da
Feltre, et tre altri. Li Provedadori li tolseno, et li dette 100
provisionati per uno, zoè di 150 page di Alvise Lanza, et 100 di
provisionadi fo dil Cicogna, el qual era partito senza licentia. Item
pagò 200 di Bernardin di Ugoni, era amalato et partito di campo. El
residuo di quelli fo di Zuan Biancho de Sicilia et di Zuan Anzolo di
Urbino. Et a li presone de li contestabelli deteno provisione; et oltra
di questi fanti, la Signoria scrisse dovesseno far 200 elemani, non
potendo haver nè desviar quelli era con il Re et duca di Orliens in
Novara; et li Provedadori li mandono a far, come dirò.
A hore 3 di notte zonse una spia di Verzei, et notifichò come dovea
venir cavalli 300 di farine per entrar in Novara, li qualli doveano
partir a hore una di notte, e far più di 20 mia quella notte, e venir in
la terra, e slongava la strada X mia per andar per vie sigure. Et el
capetanio zeneral subito, licet fusse amalato, montò a cavallo et fece
metter in hordine le zente, zoè 700 homeni d'arme, et Bernardo
Contarini dete la mità di stratioti et alcune fantarie. Et a hore 4
andono a la volta di Vespola, mia 5 dal campo, versso Vegevene,
perchè doveano ditta scorta et vittuarie far quella via. Anchora in
quell'hora montò a cavallo el sig. Galeazo, capetanio zeneral dil Duca
de Milan, con homeni d'arme 400, fanti alemani 5000, et esso
Bernardo Contarini con il resto de stratioti; et andono a la volta di
Novara, in su la strada maistra versso la montagna, e lì dimorò per
fino a do hore di zorno. Visto non pareva niuno, el sig. Galeazo
ritornò, et cussì etiam era ritornato el capetanio. Ma Bernardo
Contarini, desiderando con li stratioti di far qualcossa, andò per
quella strada maistra versso la montagna, et, chavalchato mia 8, si
voltò per costa verso Verzei, visitando molti castelli, era prima
dominati per franzesi, ma per stratioti reaquistati; et, acostato a uno
castello chiamato la Badia, mia 3 vicino a Verzei, et non potendo
haver alcun li venisseno contra, se non che trovò in una ara cinque
franzesi con assa' femene che tribiava; et li franzesi volendo
scampar, li stratioti li azonze con le lanze in la schena, ne amazono
tre, do feriteno a morte, dei qualli non si potè far alcuna
examination. Et cussì ritornò stratioti a li loro alozamenti.
Quelli di Novara mostrava fuogi et li studava, poi di novo li
apizavano; per i qual signalli dimostrava esser in gran necessità,
dimandando soccorso da Verzei.
A dì 18 ditto, essendo stato la notte avanti el capetanio zeneral
nostro per aspettar venisseno quelli cavalli con le vittuarie, et non
essendo venuti, dubitando la notte seguente non venisseno, mandò
el conte Carlo de Pian de Melletto et Carlo Secho con bona suma di
zente su la strada, da la qual via havevano più sospetto.
Fo principiato a far uno bastion a presso la terra, et, per non haver
guastadori, non se compite sì presto; unde li Provedadori rescrisse di
novo a Milan li mandasseno, perchè non era venuti di 2000 se non
200, li qualli erano stati do zorni et fuziti; et, volendo dar el guasto,
necessario era esservi guastadori.
Item, fo comenzà a far uno fosso per fortifichar el campo, et
continue lavoravano; ancora fo principiato a dar il guasto a la terra
da uno canto.
Et a hore 4, nostri inteseno era ussito di Novara più di 500 cavalli a
la liziera, e fuzivano verso Verzei; et quei di la terra, a hore 2 in 3,
trete molte bombarde præter solitum, et levono 3 volte fuogo in
zima di la torre, poi lo smorzò. Et el capetanio, inteso questo, subito
montò a cavallo a la liziera con assa' cavalli, et andono driedo di
questi fuzivano. Quello seguite, intenderete.
El messo, andò a tuor dal Re el salvo condutto, non era ancora
ritornato, et el Nuncio pontificio stava lì in campo.
A dì 19 ditto, per tre vie, nostri haveno nuove di Verzei. Prima, a
mezo zorno, zonse uno fo mandato per Tadio da la Motella a Verzei e
a Turin, et referì esser partito a dì 16 da Turin, dove el Re con la so
corte era, et spesso andava a Chier per veder la inamorata soa.
Item, di Franza non era venuta zente, ma ni anche si aspetavano; et
che da Turin fino a Verzei era alozate da 4 in 5 milia persone, in
Verzei 8 in 10 milia; in tutto, el Re se ritrovava haver da XV in XVI
milia persone, in tutto, tra utele et inutele, senza quei sono in
Novara; et che se dicea volea venir a trovar il campo, et socorrer
Novara. Et che el Duca de Savoia steva malissimo.
Item, a hore 22, el capetanio zeneral have per do soi trombetti,
venuti da Verzei, come in questo zorno era zonto ivi 8000 elemani et
1800 homeni d'arme, et che volea venir asaltar lo nostro campo di
notte da tre lai (lati) a un tempo; da Verzei, da Novara, et da un'altra
via; tamen per questo nostri non hebbeno paura, ma avevano con
grande....; et el capetanio havia ordinato li collonelli, e tutto.
Item, a hore una di notte vene uno vexentin, bandito di Vicenza,
chiamato Basilio de la Scuola, el qual era stato in campo dil Re, et
ozi, partito di Verzei mostrando andar a Turin, vene da' nostri et
refferì a li Provedadori esser in Verzei lanze 1000 tra franzesi et
taliane, elemani zercha 5000, con alcuni guasconi, borgognoni,
savogini et paesani; in tutto, con quei è col Re, persone 15 in 16
milia; et che aspetavano el Re là per tutta questa altra settimana; et
che ogni zorno andava in Verzei do homeni d'arme ducheschi a
parlar con quelli baroni. Item, che hanno mandato el balio del
Degiun a condur gran numero de elemani; tamen era ito con pochi
danari; et era mesi cinque li provisionati non havia habuto denari; et
a Verzei era zonto el Maraschalcho de Giaè et altri gran maestri, per
veder qualche bon lozamento, per metersi col campo fuora di la
terra; altri diceva era venuto per dar la paga.

Zente da cavallo et a piedi si ritrovava in Verzei, sì


come riferite el vicentin sopra ditto.

Mons. de Fois, locotenente dil Re lanze 60


La compagnia dil Duca di Orliens » 60
Compagnia di mons. di Lignì, cuxin dil Re » 100
Compagnia di mons. l'armiraio di Franza »
venuto 100
Compagnia di mons. Arbereto venuto »
nuovamente 50
Compagnia dil Grand Venor, idest cazador, ut »
supra 50
Compagnia di mons. di Borbon venuta, ut »
supra 50
Compagnia porta castroni per insegna, »
venuta ut supra 50
Mons. di Guisa » 50
Mons. d'Alban » 50
Mons. d'Armansa » 50
Mons. d'Auson, fratello di mons. de Obegnì » 50
Mons. di Serva » 50
Compagnia de mons. de Verzì » 30
El balì.... d'Auson » 20
Mons. de Beumon » 40
D. Zuan Jacomo di Traulzi » 40

Summa
lanze 900

Cavalli lizieri numero 1000; et questi hanno do arzier a cavallo per


homo d'arme.
Homeni da conto è ivi.

Mons. de Fois.
Mons. el Marchial.
Mons. el Metre de l'artilaria.
Mons. di Pienes
Mons. el Visconte de.......... gran tesorier.
Mons. de Serva.
Mons. d'Auson.
Mons. de Beumon.
D. Joan Jacomo di Traulzi.
Sig. Constantin Arniti.
D. Camillo Vitelli.
Sig. Troian Papacoda.

Fantarie.
Tra todeschi, savoini, guasconi, piamontesi et altre generation,
zercha 5500.
Artilarie.
Serpentine numero 5, di 8 pie' et mezo in circa longe, traze ballote di
ferro de lire 35, a unze 18 la lira.
Colovrine, zoè passavolanti, numero 4, di 12, 13 et 14 pie' longi
l'uno, traze ballote di lire 22 et meza.
Falconi, a modo spingarde, numero 14, traze ballote di piombo di lire
10 in 12 l'una, sono longe pie' 7.
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like