You are on page 1of 44

 

C++ Training Program

Version 0.01
Corporate Headquarters: USA Office:
eInfochips Ltd. eInfochips, Inc.
11 A/B Chandra Colony, 4655 Old Ironsides Drive, 
Ellisbridge,  Suite 385, Santa Clara, 
Ahmedabad 380 006  CA 95054,
INDIA  USA 
Tel  +91­79­2656 3705          Tel  +1­408­496­1882
Fax  +91­79­2656 0722 Fax  +1­801­650­1480
Confidentiality Notice

Copyright (c) 2000­2004 eInfochips. ­ All rights reserved.

This document is authored by eInfochips and is eInfochips intellectual property, including the copyrights in all countries
in the world. This document is provided under a license to use only with all other rights, including ownership rights,
being retained by eInfochips. This file may not be distributed, copied, or reproduced in any manner, electronic or
otherwise, without the express written consent of eInfochips.
CONTENTS 

C++ Training Module Supplement
1DOCUMENT DETAILS..................................................................................................................................7
1.1Document History ..................................................................................................................................................7
1.2Acronyms................................................................................................................................................................7
1.3References.............................................................................................................................................................7
1.3.1Books...............................................................................................................................................................7
1.3.2Weblinks...........................................................................................................................................................7
1.4List of Figures.........................................................................................................................................................7
1.5List of Tables..........................................................................................................................................................7
1.6Schedule.................................................................................................................................................................7

2INTRODUCTION.........................................................................................................................................10
2.1Prerequisites.........................................................................................................................................................10
2.2Assistance............................................................................................................................................................11

3DAY 1 & 2 ( REVISION ).............................................................................................................................12
3.1Data Types...........................................................................................................................................................12
3.2Variables & their scope.........................................................................................................................................12
3.3Operators..............................................................................................................................................................13
3.4Functions..............................................................................................................................................................14
3.5Arrays ..................................................................................................................................................................14
3.6Strings...................................................................................................................................................................14
3.7Pointers & References..........................................................................................................................................14
3.8Dynamic memory..................................................................................................................................................15
3.9Structures & Unions..............................................................................................................................................15
3.10Dos'.....................................................................................................................................................................15
3.11Dont's..................................................................................................................................................................15
3.12Exercises............................................................................................................................................................16

4DAY 3 ( OOPS )..........................................................................................................................................18
4.1Theory of OOPs and C++.....................................................................................................................................18
4.1.1Features supported by C++:...........................................................................................................................18
4.1.2Process and Methodology for working with C++.............................................................................................19
4.2Class.....................................................................................................................................................................20
4.3Object...................................................................................................................................................................21
4.4Do's.......................................................................................................................................................................21
4.5Dont's....................................................................................................................................................................21
4.6Exercises..............................................................................................................................................................21

5DAY 4 & 5 ( MORE ON OOPS FEATURES... )..........................................................................................23
5.1Constructor...........................................................................................................................................................23
5.2Copy Constructor..................................................................................................................................................23
5.3Destructor.............................................................................................................................................................23
5.4Static and Constant Members...............................................................................................................................23
5.5Friend function......................................................................................................................................................24
5.6Dos.......................................................................................................................................................................24
5.7Donts'....................................................................................................................................................................24
5.8Exercise................................................................................................................................................................24

6DAY 6 & 7 ( POLYMORPHISM )................................................................................................................26
6.1Function Overloading............................................................................................................................................26
6.2Operator Overloading...........................................................................................................................................26
6.3Exercise................................................................................................................................................................26

7DAY 8 (INHERITANCE)..............................................................................................................................28
7.1Exercise................................................................................................................................................................28

8DAY 9 (NAMESPACE & VIRTUAL FUNCTION)........................................................................................30
8.1Dos'.......................................................................................................................................................................30
8.2Don'ts....................................................................................................................................................................30
8.3Exercises..............................................................................................................................................................30

9DAY 10 ( TEMPLATES, EXCEPTION )......................................................................................................31
9.1Template...............................................................................................................................................................31
9.2Exception..............................................................................................................................................................31
9.3Dos'.......................................................................................................................................................................31
9.4Don'ts....................................................................................................................................................................31
9.5Exercises..............................................................................................................................................................32

10DAY 11 ( FILES )......................................................................................................................................34
10.1Dos'.....................................................................................................................................................................34
10.2Donts'..................................................................................................................................................................34
10.3Exercises:...........................................................................................................................................................34

11DAY 12 ( STL )..........................................................................................................................................35
11.1Exercise..............................................................................................................................................................35

12C++ PROJECT .........................................................................................................................................36
12.1Requirement Specifications................................................................................................................................36
12.2Suggested Architecture Diagram........................................................................................................................36
12.3Module Description.............................................................................................................................................38
12.3.1Packet..........................................................................................................................................................38
12.3.2Generator.....................................................................................................................................................39
12.3.3Device BFM..................................................................................................................................................39
12.3.4Monitor.........................................................................................................................................................39
12.3.5Scoreboard...................................................................................................................................................39
12.3.6Agent............................................................................................................................................................40
12.3.7Utility.............................................................................................................................................................40
12.3.8Configuration................................................................................................................................................40
12.3.9DUT..............................................................................................................................................................40
12.3.10Env.............................................................................................................................................................40
12.4Important Instructions.........................................................................................................................................40
12.5Back pointer Example.........................................................................................................................................41
12.6Testcase Example..............................................................................................................................................42

13MARKING FOR EXERCISES OR PROJECT...........................................................................................44
13.1Acceptance criteria.............................................................................................................................................44
13.2Marking Criteria...................................................................................................................................................44
C++ Supplement                      E­infochips Pvt. Ltd.

1 DOCUMENT DETAILS
1.1 Document History 
Version Date Author Description
1.2.1 13 December 2004 Kunal Shah Initial Draft
Harish Patel
1.2.2 14 December 2004 Kunal Shah Changing the training schedule from 16 days to 12
Harish Patel days, Adding PISO and SIPO into the project

1.2.3 30 December 2004 Harish Patel Removed known errors listed in Err1.2.1 version


1.2.4 11 March 2005 Niraj Patel Reviewed by Niraj
Harish Patel
1.2.5 28. November 2008 Ekata Mehul

1.2 Acronyms
Acronym Description
API Application Program Interface
BFM Bus Function Model
VC Verification Component
SIPO Serial In – Parallel Out
PISO Parallel In – Serial Out
STL Standard Tool Library

1.3 References
1.3.1 Books

The C++ Programming Language Special, 3rd Edition, Bjarne Stroustroup
C++ Primer, Stanley Lippman
Object Oriented Programming in C++, 3rd Edition, Robert Lafore

1.3.2 Weblinks

http://www.cplusplus.com

http://www­plan.cs.colorado.edu/diwan/class­papers/mi.pdf. (for multiple inheritance)

1.4 List of Figures
1.5 List of Tables
1.6 Schedule
C++ Supplement                      E­infochips Pvt. Ltd.

Item Time Duration
(Days/Hours)
Training + 12 Days
Exercises
Project Simultaneously with
training
Test 1 Hour
Total Hours 97 man­hours

Sr. Topics Days


No.

Basics of C++ with reference to C
data types with typecasting; variables; user defined data types; functions; arrays;
1 pointers & references; dynamic memory allocation; exercises 2
2 OOPs
History of OOPs 
evolution of C++
tour of C++
thinking in terms of C++.
Objects and Classes 1
More on classes and objects
Constructor
Destructor
Static and Constant Members
Friend functions
inline functions
3 Reference members 2
Polymorphism 
Function overloading
4  Operator overloading 2
5 Inheritance 1
6 Namespace & Virtual Function 1
7 Templates & Exception Handling 1
8 Files 1
9 Standard Template Library (STL) 1

Note: 
• Trainee can refer at least any one of the books mentioned.  It is advisable to use the latest version.
B1 = Object Oriented Programming in C++, Third Edition, Robert Lafore
B2 = C++ Primer, Stanley B. Lippman
B3 = The C++ Programming Language Special , Bjarne Stroustrup
C++ Supplement                      E­infochips Pvt. Ltd.

• Browsing of “C++_Training.ppt” is mandatory.
• Reading of C++_Supplement will be beneficial for better programming and avoidance of errors.
• “C++_Manual” gives you the better understanding of working with C++ programs i.e. way to execute
it, ways to debug, etc.
• Reading STL_docs.tar is optional.  It can be used as a reference for getting information on any kind
of STL.
• Set of working programs will be supplied with this. Names of the programs related to the topics are
mentioned in the presentation / supplement  using the format (program_name.cpp)
C++ Supplement                      E­infochips Pvt. Ltd.

2 INTRODUCTION

The purpose of this document is to supplement the C++ training.  Along with providing the
reference of dos' and donts' of C++, it also explains C++ Training schedule in general and provides
proper guidelines for successful completion of training. Goal of this training is to familiarize trainee
with concepts of objected oriented language C++ and to practice it. It also provides exercises for
better understanding of those concepts. Trainee needs to read all the Chapters of this document
carefully. Any book mentioned in the References (Section 1.6) can be used to refer the concepts of
language. Links mentioned in (Section 1.3.2) are authenticate ones and other links may be referred
after checking the authenticity of the contents on the same.

Trainee should take care of following things while preparing the exercises/project.
• Proper directory structure
• Proper partitioning of code into files
• Follow coding style guidelines
• Proper comments
• Optimized code

Trainee is advised to look over the schedule (Section 1.6) of the entire program and plan it
accordingly.

The exercises & project given in this document are based on making the trainees suitable for the
working environment of E­infochips. So most of the terms used in them are related to verification &
design.  Trainee needs to understand those terms first and then should start working on it.

This training can be used as tutorial of C++ at introductory level. Also, It can be arranged as 3­4
day interactive­workshop to conduct a C++ course for programmers.

2.1 Prerequisites
Trainee should be familiarized with the concepts of microprocessor, microprocessor based
systems, assembly language, assemblers and compilers. Previous work or academic orientation to
the programming languages such as Pascal, C and Basic could be an added advantage towards
understating of C++. 
C++ Supplement                      E­infochips Pvt. Ltd.

2.2 Assistance
If the trainee has any query regarding this document/exercise/project then he/she can consult
assigned mentor. In case mentor is not able to resolve it or mentor insists then trainee can send an
email on the following alias. Generally all queries are responded within a day.

To: ekata.mehul@einfochips.com
Sub: C++ Training: Query regarding Document/Exercise/Project
C++ Supplement                      E­infochips Pvt. Ltd.

3 DAY 1 & 2 ( Revision )
3.1 Data Types
1. Integral and floating types are built­in types, other types are constructed using built­in types.
Thus a type is a concrete representation of a concept.
2. Every data type have a fixed size of storage and hence the range of values they can represent
(it is compiler dependent)
3. Every type can be again assigned with constant literal e.g. 'a' is char constant literal.
4. wchar_t – “wide character”. Used to hold character set of Unicode. It takes the form L”ab” as
character literal, when declared.
5. Negative integers are stored in two's complement forms. Other storage representations of
floating points per say single precision (float), double precision (double) and extended precision
(long double) is assumed to be known.
6. There is no negative 0, since complement of 0 returns ­1 (as all values are 1's)
7. Refer to <limits>, whenever needed to check implementation dependent aspects.
#include <iostream.h>
#include <limits.h>
using namespace std;

int main()
{
cout << "largest float=" << numeric_limits<float>::min();
return 0;
}

8. “void” ­ normally used to specify either the function not returning any values or as a base type for
pointers to objects of unknown types. 
9. Refer to the all rules and regulations for constants / literals of all the data types.
10.typedef – creates synonyms for the data types.
11.enum / classes ­ distinct types with identical semantics / identical representation can be
available from 'enum' or 'classes'.
12.The exact memory storage for union is architecture dependent. Hence, should take care of for
any portable program.

3.2 Variables & their scope
1. Variable / Object – Contiguous storage of memory locations and referred by 'lvalue'. 
2. Data types, when assigned with variables, are called as “Declarations”. There can be many
declarations but only single definition for each name in the program. All declarations must agree
on the type of entity referred to.
C++ Supplement                      E­infochips Pvt. Ltd.

Specifier * base­type       declarator  initializer*


(virtual / extern / long) (name with operator *, &,[]) (values to be initialized)

3. Some definition may also specify 'value' for the entities they define – for types, templates,
functions and constants, the 'value' is permanent and is always initialized with 0.
4. Names starting with underscore ( _ ) are reserved for special facility in implementation and run­
time environment, so should be avoided in application programs
5. Scope of the variable – sections in the program from where the variable is accessible. It is
controlled using blocks { }.
• Global – outside any function, class or namespace
• local – hides the global scope. Hidden global can be accessed using :: operator. No.
way to use hidden local variable.
• Static objects live till end of the files
• Automatic lives from the declaration till the concerned block ends
• Array elements, non­static structure or class members have lifetimes based on who
they are members of. 
• Dynamic variables can have user control.
6. Variables defined without an initializer in namespace or global are automatically initialized. 

3.3 Operators
Below is the list of operators used in C / C++ along with their description, precedence and
associativity

Leve
Operator Description Grouping
l
1 :: scope Left­to­right
() [] . ­> ++ ­­ dynamic_cast static_cast
2 postfix Left­to­right
reinterpret_cast const_cast typeid
++ ­­ ~ ! sizeof new delete unary (prefix)

* & indirection and
3 Right­to­left
reference (pointers)
+ ­ unary sign operator
4 (type) type casting Right­to­left
5 .* ­>* pointer­to­member Left­to­right
6 * / % multiplicative Left­to­right
7 + ­ additive Left­to­right
8 << >> shift Left­to­right
9 < > <= >= relational Left­to­right
10 == != equality Left­to­right
C++ Supplement                      E­infochips Pvt. Ltd.

11 & bitwise AND Left­to­right


12 ^ bitwise XOR Left­to­right
13 | bitwise OR Left­to­right
14 && logical AND Left­to­right
15 || logical OR Left­to­right
16 ?: conditional Right­to­left
17 = *= /= %= += ­= >>= <<= &= ^= |= assignment Right­to­left
18 , comma Left­to­right

3.4 Functions
1. Main ( ) is also the function from where the execution of the program starts. 
2. Values to the argument are assigned in left to right manner.
3. Command line arguments implies supplying arguments to main ( ) function.
4. One can supply variable numbers of arguments to the functions using eclipsys (...) and va_arg.
(variablearg.c)

3.5 Arrays 
1. Array index always starts from '0' (zero)
2. One can add any number of dimensions to an array with the same syntax structure as used for
single dimensions.
3. Complete array cannot be passed as a parameter. Only the address can be passed in C++.
void procedure (int arg[])  // declaration of function
procedure (myarray); // calling of function
4. When multi­dimentional array is  passed as argument, later dimensions have to be mentioned,
so that compiler can know about the depth of the array.
void procedure (int myarray [ ][3][4])

3.6 Strings
1. Full fledged “string” library is supplied. It contains all the functions that can be operated on string
datatype.
2. The standard header file <sstream> defines a class called stringstream that allows
a string­based object to be treated as a stream, using which we can perform conversion from
integer to string very easily. We have more control as interpretation of the input is required.
(e.g. sstream.cpp)

3.7 Pointers & References
1. Whenever wants to use generic data type, one should use void pointers.
C++ Supplement                      E­infochips Pvt. Ltd.

2. References can be thought of as a synonym of an object to what it refers to.
3. References can also be thought of as a constant pointer that is dereferenced every time it is
used. The only thing it cannot be manipulated the way pointers can be.

3.8 Dynamic memory
1. Mainly used when the amount of memory storage is not fixed at the time of writing programs
2. Scope of the memory allocated will be till freed by using “delete”.

3.9 Structures & Unions
1. Unions can have members but not static ones. As the compiler is not aware of the type of
member stored in memory, we cannot have constructor / destructor members in unions. They
are best used in low level codes or a part of class keeping track of what in stored in unions.
2. Structures / Union is also a kind of class but without encapsulation feature:  – All the members
declared within them becomes global. You don;t have access controls and hence no
encapsulation.

3.10 Dos'
1. Before assigning the values from one data type to another, should always check for autotype
data conversions. They are difficult to debug errors.
2. For writing a portable code, use “sizeof( )” function as much as possible. Also one can use STL,
wherever feasible.
3. Be aware of where a pointer points to, and what is the size of that space.
4. Always check if a pointer points to NULL before accessing it.
5. Always check the precedence and associativity of the used operators in the expression to get
the valuation of the expression.
6. Always double sure the termination of recursive / re­entrant functions.
7. Always type cast the data when using with void pointers, since they cannot be directly
dereferenced.
8. C++ don;t guarantee the “garbage collector” for such objects and hence usage of “delete”
should become essential.
9. Use named arrays instead of pointers. This will confirm for the memory storage and lead to less
“segmentation faults”
10.Typecasting be done using new style casts viz. static_cast, reinterpret_cast, const_cast etc.
instead of basic C style typecasting.
11.use const or enum to define manifest constants.

3.11 Dont's
1. Assuming 'unsigned int' working only for +ve values will not fit implicit conversion rules.
2. Avoid hiding scope of global variable using locals.
C++ Supplement                      E­infochips Pvt. Ltd.

3. Avoid directly dereferencing a pointer variable. One should always check for it to be NULL
pointer or not.
4. Usage of un­intialized pointer is hazardous.
5. Creation of dangling references is dangerous for the memory usage. You will run out of memory
later.
6. The use of word “static” to mean “local to translation unit” is deprecated (used heavily but better
not to use). One should use unnamed namespace instead of it.
7. Macros are almost never necessary in C++.  
8. don't use malloc( ) in C++. Instead use new operator doing same job better. Also instead of
realloc( ), try using vector[ ]
9. Avoid using *void. If you must use an explicit type conversion, try using one of the “new casts” of
more precise statement of what you are trying to do.
10.Minimize the use of C style arrays and strings, instead one can use standard library string and
vector

3.12 Exercises
1. Try to get sizes of some fundamental types, pointers and enumerations. Also find their largest
and smallest values (Hint: sizeof( ), <limit.h>)
2. Write a code to check the auto­conversion working between 'unsigned int' and 'signed int'. Try
giving all various data and explain the output.
3. Write a program to check whether given two strings are same or not? Try using as small code as
possible. You need to use pointers.
4. Understand the working of variable argument program supplied and make some changes in it of
your choice, except only the strings to be printed.
5.  What output is expected using the line: v[i] = ++i; Write a small code the check your answer.
6. void qsort(void *base, size_t num_elements, size_t element_size, int (*compare)(void const *,
void  const *)); ­ Above statement can implement the quick­sort algorithm on any type of data.
Justify the statement.
7. An insertion sort is performed by adding values to an array one by one. The first value is simply
stored at the beginning of the array. Each subsequent value is added by finding its ordered
position in the array, moving data as needed to accommodate the value and inserting the value
in this position. Write a function called insort that performs this task and behaves in the
same manner as qsort, i.e it can sort an array by a key value of any type and it has similar
prototyping.
8. Implement a linked list program with support for following options
• Add new node
• delete any node based on node number
• change value of a node
C++ Supplement                      E­infochips Pvt. Ltd.

• search through linked list for a specific value of any structure element.
• Sorting of the nodes (not the only values within) will carry bonus marks.
Trainee can implement any structure of his/her choice. Usage of functions and switch­case is
must.
       NOTE: To implement a linked­list, it is must to have one element of type pointer to the same
structure.
9. Implement a library program for stack data structure with support for the operations
● push
● pop
● peep ( just looking at the top element )
It should support all the data types and should have an array of pointers to the functions
implemented as a part of the program.

                       
C++ Supplement                      E­infochips Pvt. Ltd.

4 DAY 3 ( OOPs )
4.1 Theory of OOPs and C++
There are many different kinds of programming paradigms, OOP is one among them. In OOP,
programmers see the execution of the program as a collection of dialoging objects. The main
characteristics of OOPL include encapsulation, inheritance, and polymorphism.

Object­oriented languages such as Simula67 and Smalltalk existed prior to C++. But because C++
was built on top of the C programming language (and could compile existing C programs), it was
able to bring the abstractions of object­oriented thinking into the mainstream.

C++ owes much to C i.e. mainly the syntax part. C is retained as a subset of  C++. Also the low
level working of C is retained in C++. The class and object concept was borrowed from Simula67.
Polymorphism was introduced inspired from Algol68. Templates were introduced to reduce the
work of macros and typecasting (since it has lot of memory related problems – yet to deal with it).
they were inspired from Ada and Clu. Also exception handling was inspired from Ada, Clu and ML. 

C++ was earlier initiated as “C with Classes” since 1980. C++ was coined by Rick in 1983. Lot of
people used it and that led to the standardization of the language in 1994. 
4.1.1 Features supported by C++:

1. C++ has inspired a great deal of thought surrounding software design and development, from
design patterns to meta­programming.
2. It is portable among hardware platforms and its lower­level expressiveness, C++ will assuredly
be essential in a world of faster, smaller hardware.
3. By supporting several programming paradigm, C++ supports various levels of expertise to be
achieved.
4. C++ is the single mode language – selects the overloading of the function i.e. calling of the
function statically at compile time. Multi mode / multiple dispatch languages will do the same
dynamically.
5. It is event driven and hence can work with real time constraints.
6. It was mainly designed for working with the systems where memory and time were severely
tested.
7. for most codes, maintainibility, ease of extension and ease of testing is an issue. C++ caters to
all of them nicely. hence to be used, specially in the area where lot of changes are expected
with time.
8. Graphics and user interfaces are the areas where C++ is majorly used giving lot support to
numerical computations.
C++ Supplement                      E­infochips Pvt. Ltd.

9. It is also able to coexist with codes and fragments of earlier languages.

Thoughtlessly applying the programming style of one language on another leads to a awkward,
poorly performing and hard to maintain code. You should start thinking in the way of C++.

4.1.2 Process and Methodology for working with C++

Normally for any programming task, three steps are done: ­ first to analyze the problems to
understand it clearly, second is to find out key concepts within it and thirdly is to implement the
ideas using some programming language. 

Identify key application concepts, identify useful libraries, build new libraries in support of the
application concept, try out ideas early, integrate early, test early and often, use documentation
and tutorial material as design tools, and grow larger programs from smaller ones (iterating along
the way). It should be obvious that I'm focusing on relatively small projects just now.

Focus on key concepts; focus on their interfaces; focus on the management of resources (memory,
files, locks, and so on); focus on error handling. The design of good invariants for classes and
Resource Acquisition Is Initialization (RAII) are key techniques.

One should normally design a new class for a new concept since each class will let us know how
objects of that classes can be – created, manipulated, destroyed and even represented. Finally
one should be able to think in terms of classes and their relationships with each other. if not, still
more to analyze for the problems. 

The structures of 'tree' i.e. hierarchical will be very important for the relationships among classes.
One should be able to represent the same without having cyclic mutual dependencies, else no
programming language can help. Main help can be on separation of interfaces and
implementation. Try to structure the ideas of the program as readily as possible. Some of the ready
tips for the thinking process are as below:
1. If you can think of “it” as a separate idea, make it as “class”
2. If you can think of “it” as a separate entity, make it as “object” of some class.
3. If two classes have a common interface, make that interface an abstract class
4. If two classes have something significant in common, make that commonality as a base class
5. If a class is container of an object, make it as templates.
6. If a function is implementing an algorithm for an container, make it as template function for the
family of containers.
7. If the set of classes, templates, etc are logically related, place them in a common namespace.
C++ Supplement                      E­infochips Pvt. Ltd.

8. When you define a class that does not have some mathematical entity (e.g. Matrix) or some low­
level structure (e.g. Linked list):
● don;t use global data, use members
● don't use global functions
● don't use public data members
● don't use friends, ,except to avoid above tips
● don't put “type field” in the class, use virtual functions.
● Don't use inline functions, except as a significant optimization.

4.2 Class
1. A class is a user defined type. We define new type where there is no counterpart available as
built­in type.  They differ with built in types the way they are created and not the way they needs
to be used.
2. There are three parts in the definition of a class: data  members, member functions, and access
control.
3. Regular classes which are not abstract classes or does not belong to hierarchical structures are
called “concrete” classes. They are also called as value types. They are intended to do single
task very methodically. So, normally not used for much modifications and also are used as we
use regular built in types. Its size is known as compile time itself and hence objects are allocated
at run­time stack.
4. A data member name always refer to that member with which object it is invoked.
5. When a class member invokes a function, other members of the same class and its base
classes are preferred over the appropriate potentially matching another global function with
proper arguments.
6. Struct / Union is also a kind of class but without encapsulation feature:  – All the members
declared within them becomes global. You don;t have access controls and hence no
encapsulation.
7. Advantage of class – localization, hence very useful in debugging. Also providing public
interface concept. Potential user may check only the definition of class members to use the
class.
8. Static member becomes a part of the class but does not become a part of the object of that
class. Also, a function that needs access to the members of the class, but doesn't need to be
invoked for the particular object, is a static function. Hence its name needs to be qualified with
the name of class, rather than objects.
9. Declaring a const member function indicates that this function does not change any value of the
member functions. It goes as with the return data type. It can be invoked by both const and non­
const objects, while non­const members can be invoked only by non­const objects.
C++ Supplement                      E­infochips Pvt. Ltd.

10.Each member function knows what object it was invoked for and can explicitly refer to it using
“*this” pointer. The type of this is *const implicating that its value cannot be changed. Its clear
usage will be visible in linked list program.
11.The storage specifier “mutable” indicates that it allows updating, even if called through const
objects. It should be used when part of the representation is allowed to change.
12.The member function defined within the class is taken to be “inline” member function. If we want
it to be defined outside still being inline, we need to use inline keyword.

4.3 Object
1. It is variable of a certain class.
2. We can place objects at a specific location using allocator function with extra arguments and
supplying them when using new operator.

4.4 Do's
1. Represent concepts as classes.

4.5 Dont's
1. Don't declare a variable before you need it, so that you can initialize it as when you declare it.
2. One should avoid using context dependent classes (e.g. today) for the better maintainibility and
portability of the program.

4.6 Exercises
1. Define a class to represent a bank account.  Include the following members:
Data members
1. Name of the depositor
2. Account number
3. Type of Account
4. Balance amount in the account
Member Functions
1. To assign an initial values
2. To deposit an amount
3. To withdraw an amount after checking the balance
4. To display name and balance
2. Set is a collection of elements. Define a class that performs the operations:
● adding elements to the set
● removing elements from the set
● copying one set to another
● intersection of two sets
● union of two sets
C++ Supplement                      E­infochips Pvt. Ltd.

● checking the membership of the element within the set
Create three different files and compile them together.
3. Define a class for analyzing, storing, evaluating and printing simple arithmetic expressions
consisting of integer constants and the operators +, ­, /, *. The public interface should look like
class Expr {
.....
public:
Expr (char *);
int eval( );
void print ( );
};
     The string argument for the constructor Expr::Expr ( ) is the expression. The function Expr::eval(
) returns the value of the expression and Expr::print( ) prints the representation of the expression
on cout. 
Define class Expr twice, once using the linked list of the nodes as the representation and once
using the character string as the representation. If possible, experiment with different ways of
printing the expression viz. fully parenthesized, postfix notation, assembly code, etc.
C++ Supplement                      E­infochips Pvt. Ltd.

5 DAY 4 & 5 ( More on OOPS features... )
5.1 Constructor
1. It is the function to initialize the objects. Since it constructs values of a given type, hence
constructor. Thus a constructor establishes an invariant for the class which can be later used by
other member function and they should maintain it also.
2. More than one constructor can be provided, where they obey the same overloading rules as
other functions.
3. One can even use default values for the arguments, with same rules as for the functions
4. Default constructors can be invoked explicitly.
5. As consts and references (members) needs to be initialized, default constructor will not be able
to do so. It has to be taken care of by user­defined constructor.
6. Member Initialization List with constructor is mainly used to initialize the constant data members.
7. It may not be defined as constant, since they have permission to operate on constant objects
and can even assign values to their data members (except they are also constant)

5.2 Copy Constructor
1. Class objects can be copied, which results in the copy of each and every member. Any object
can be even initialized by copy, even in the presence of user defined constructor. This is implicit
“Copy constructor”
2. A class must have a copy constructor if it has dynamic memory allocations and pointer
members. This will ensure the memory allocations at the time of creation of objects leading to
lesser errors causing core dumps.
3. Always check for self assignments (use *this) in case of copying.

5.3 Destructor
1. Function that gets executed when the object is destroyed is destructor. It releases the resources
acquired by the object. It is normally invoked implicitly, but can be called also.
2. It may not be defined as constant, since they have permission to operate on constant objects
and can even assign values to their data members (except they are also constant)

5.4 Static and Constant Members
1. A constant object be modified only by the constant member function of the class
2. Data Member constant is initialized using member initialization list only.
3. No member function can assign any value to constant data member.
4. Constant data member cannot be declared for the size of an array since it receives its value at
run time and not compiler time.
5. Static data member ensures only a single copy across all the objects of the class and by default
initialized to zero '0'.
C++ Supplement                      E­infochips Pvt. Ltd.

6. Static Member function cannot receive an implicit argument and hence cannot refer to “*this”.

5.5 Friend function
1. The friend functions can serve, for example, to conduct operations between two different
classes

5.6 Dos
1. Always recommend use member functions instead of friends to change state of the members
within the class.
2. Use inline functions to avoid function­calling overhead
3. Below mentioned is the list mentioning the way objects can be created and then destroyed
accordingly. It is very essential to avoid errors regarding scope of the objects.
1. A named automatic object which is created each time its declaration is encountered in the
execution of the program and is destroyed each time the program exits the block in which it
was declared.
2. A free­store object which is created using new operator and destroyed using delete operator
3. A non­static member object which is created as a member of another class object and
created and destroyed when the object of which it is member, is created and destroyed.
4. An array element which is created and destroyed when array of which it is an element is
created and destroyed.
5. A local static object, which is created once when its declaration is encountered in the
execution of the program and is destroyed once at the termination of the program.
6. A global, namespace, or a class­static object, which is created once “at the start of the
program” and destroyed once at the termination of the program.
7. A temporary object which is created as a part of evaluation of the expression and is destroyed
when the expression is completely evaluated.
8. An object placed in memory obtained from user­supplied function guided by arguments
supplied in the allocation operation
9. A union member, which may not have a constructor or a destructor.
10.“Inline” functions must be defined in every translation unit in which it is used.

5.7 Donts'
5.8 Exercise
1. Define a class String that could work as a user­defined string type.  Include constructor that will
enable us to create an uninitialized string
String s1; //string with length 0
and also to initialize an object with a string constant at the time of creation like
String s2(“How are you?”);
C++ Supplement                      E­infochips Pvt. Ltd.

Write a complete program to test your class to see that it does the following tasks:
a. Creates un­initialized string objects
b. Creates objects with string constants
c. Concatenates two strings properly
d. Displays a desired string object
2. Define a class “Histogram” that keeps count of some numbers in intervals specified as
arguments to Histogram's constructor. Provide functions to printout Histogram. Handle out of
range values.
3. Given the program
                  # include <iostream>
void main( )
{
     std::cout << “hello world\n”;
}
modify it to produce the output as
Initialize
hello world
clean up!
Do not change main ( ) in any way.
4. Usage of “*this” pointer is not allowed in any static function member of the class. Why?
5. One cannot overload destructor the way you can do it for constructor. Why?
6. Check out the details of working with bit field data members. 
7. Define a class named “Menu” which uses linked list of strings to represent a menu of options.
Use a nested class, “option” to represent the set elements. Define a constructor, a destructor
and following member functions for Menu:
1. insert – inserts a new option at a given position. Provide a default argument so that item is
appended to the end.
2. Delete – it deletes the existing option
3. choose – displays the menu and invites the user to choose the option.
8. Modify the menu class so that an option can itself be a menu thus allowing nested menu.
C++ Supplement                      E­infochips Pvt. Ltd.

6 DAY 6 & 7 ( Polymorphism )
6.1 Function Overloading
1. The ambiguity between two functions is not resolved using the return data type. The reason for
not considering return data type is to keep resolution for an operator or function call context –
independent i.e. Can look upon the functions in isolation and do the type conversion, wherever
required.

6.2 Operator Overloading
1. Operator new and delete should be overloaded only when the object will require to occupy much
lesser space and hence space may be wasted due to overheads.
2. Overloaded new and delete will operate only for those objects in which class they are defined.

6.3 Exercise
1. Use function overloading to find “Volume” of a cube, cylinder and rectangular box.
2. Create a class for “String” operation to accomplish the following tasks using Operator
Overloading:
i. String 1 = String 2;
ii. String 3 = String 1 + String 2;
iii. String 3 = String 1 – Number of characters  
iv.       //remove number of characters from end of string
v. String 1 == String 2 (compare 2 strings)
3. Write a friend function to overload “<<” operator.
4. Write the friend functions for other operations on “Set” viz. intersection (*), union (+), inequality
(!=), difference between two sets(­), subset (<=). You may write one function as member
function, another as non­member global function and third as friend function.
5. Write a matrix class that performs the operations of addition, substraction and multiplication for
two matrices. That should contain a constructor, destructor and operator overloading for +, ­ and
* operators.
6. Work with Binary class. Also overload another operators “­” for difference between two binaries
and “[]” to get bit position and give the value at that index to be 0 or 1.
7. Complete the implementation of following String class. Note that two versions of constructor and
= are required, one for initializing / assigning to the String using char *, and one more member­
wise initialization / assignment. Operator [] should index a String character using its position.
Operator + should concatenate two strings.
Class String {
public:
C++ Supplement                      E­infochips Pvt. Ltd.

String (const char*);
String (const String&);
String (const short);
~ String ( );
String & operator = (const char *);
String & operator = (const String&);
char & operator [ ] (const short);
int Length ( ) { return (len);}
     friend String operator + (const String&, const String&);
     friend ostream operator << (ostream &, String &);
     private:
char *chars ;
short len ;
     };
C++ Supplement                      E­infochips Pvt. Ltd.

7 DAY 8 (INHERITANCE)
1. Protected Access Right was introduced so that the encapsulation / abstraction feature may also
be protected and there can be some freedom granted in accessing the members of the base
class. This was really essential for extensibility

7.1 Exercise
1. Consider a class network of the below figure:

Staff

Name
Code

Account Admin

Pay Experience

Person

Name
Code
Experience

The class Person derives information from both account and admin classes which in turn derive
information from the class Staff.  Define all the four classes with initialization of all the variables
and write a program to create, update and display the information contained in the Person objects.
Now, add a function in Admin class, which returns an enumerated type having following
categories.
1) NOVICE (if experience < 1 yr)
2) JUNIOR (if 1 yr < experience < 3 yrs)
3) SENIOR (if 3 yrs < experience < 5 yrs)
4) EXPERT (if 5 yrs < experience < 10 yrs)
5) CRAZY (if experience > 10 yrs)
C++ Supplement                      E­infochips Pvt. Ltd.

Modify the program to print names of all the employees categorized as described earlier.
Eg. NOVICE:  CRAZY:
John Smith Albert Conery
Alicia Walker

2. Extend the program given of “inheritance.cpp” to display the area of circles.  This requires
addition of a new derived class circle that computes the area of a circle.  Remember, for a circle
we need only one value, its radius, but the get_data( ) function in the base class requires two
values to be passed. (Hint: Make the second argument of get_data( ) function as a default one
with zero value.)
3. Start working on project which needs to be completed within next 4 days.
C++ Supplement                      E­infochips Pvt. Ltd.

8 DAY 9 (NAMESPACE & VIRTUAL FUNCTION)
1. Separate namespaces be used for separate modules i.e. To specify logical structure of the
program. They are used to provide modularity in the program. Only declarations of functions to
be done within, so that
– it provides the information as to what services are offered by that module. This will help
us in making of proper interfaces.
– Provides common environment for the functions implemented in it.
2. A namespace is a scope. Ordinarily, local scopes, global scopes and classes are namespaces.
Usual scope rules holds for namespaces. All the functions and other units of the program are
normally in some namespaces, except main( ) ­ needs to be global for run­time environment to
recognize it specially.
3. Avoid short names for namespaces. If required, use aliases for long names of namespace.
4. The purpose of interfaces is to minimize the dependencies. Minimal interfaces leads to systems
that are easier to understand, better hiding properties, easier to modifications and faster to
compile.
5. All the mixing of using directive and using declarations are possible with priority of declarations
over directives.
6. Older C libraries can be included as namespace using “using” directives.
7. Namespace is open i.e. One can add functions to it from any locations. For the same, keep the
scope of namespace open across files for the larger programs.

8.1 Dos'
1. Use “using” directive (for complete namespace) / declaration (for one member of namespace) if
one namespace elements be referred in another namespace.
2. Use namespaces to avoid names clashes.

8.2 Don'ts
1. Avoid having unnamed namespace.
2. Avoid order dependencies when constructing global and namespace objects

8.3 Exercises
1. Write a complete program for desk calculator (not scientific). This should have all relevant
separate namespaces and interfaces. 
2. Write the same exercise as in Q2 of previous day but to have “area ( )” as virtual function.
3. Rewrite above Q  2 making “area ( )” as pure virtual function and use dynamic allocation of
memory for pointers accessing the same function from derived classes.
C++ Supplement                      E­infochips Pvt. Ltd.

9 DAY 10 ( Templates, Exception )
9.1 Template
1. One can have even the instantiated template class as base class. More description on the same
can be referred from the book.
2. Along with the template parameters, one can even pass non­template parameters.
3. Normally we have interfaces in .h file and implementation in .cpp files, but that cannot be true for
templates. Because templates are compiled when required, this forces a restriction for multi­file
projects: the implementation (definition) of a template class or function must be in the same file
as its declaration. That means that we cannot separate the interface in a separate header file,
and that we must include both interface and implementation in any file that uses the templates.
4. Since no code is generated until a template is instantiated when required, compilers are
prepared to allow the inclusion more than once of the same template file with both declarations
and definitions in a project without generating linkage errors.

9.2 Exception
1. It is intended to handle non­local errors. Local errors should be handled normally.
2. Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our
program by transferring control to special functions called handlers.
3. To catch exceptions we must place a portion of code under exception inspection. This is done
by enclosing that portion of code in a try block. When an exceptional circumstance arises within
that block, an exception is thrown that transfers the control to the exception handler. If no
exception is thrown, the code continues normally and all handlers are ignored.
4. A exception is thrown by using the throw keyword from inside the try block. Exception handlers
are declared with the keyword catch, which must be placed immediately after the try block.
5. We can have multiple “catch” functions with different parameters types. Also we can have
nesting of try­catch block. If we want external “catch” to handle, internal block needs to simply
write “throw”, without passing any parameters.

9.3 Dos'
1. Use user­defined exceptions rather than built­in types.
2. Better to keep error handling and normal code separate
3. Use templates to specify families of functions and types and

9.4 Don'ts
1. Doing error handling at the same level of abstraction of the code where error occurred, is
hazardous.
C++ Supplement                      E­infochips Pvt. Ltd.

9.5 Exercises
1.  Add exception handling for all relevant errors in the previously made calculator program. Also
keep a record of mistakes you make and later on suggest appropriate ways to avoid such
mistakes.
2. Write a program that throws the error in one function and catches in another.
3. Write a program consisting of functions calling each other to the calling depth of 10. give each
function an argument that determines at which level an exception is thrown. Have main( ) catch
these exceptions and printout which exception is caught.
4. Write a function that either returns a value or that throws the value based on an argument.
Measure the difference in run­time between the two ways
5. Write a class template for FIFO (queue) the similar way as done for LIFO (stack) in the given
programs. You may also overload the “>>” operator for inputing the data instead of “insert ( )”
function. 
6. Write a template for the singly linked list that you would have designed in the first two days
exercise.
7. Consider the following function which is used for receiving a packet in the network system:
void ReceivePacker (Packet *pack, Connection *c)
{
switch (pack­>Type( )) {
case controlPack: //....
break;
case dataPack: //....
break;
case diagnosePack: //...
break;
default: //...
}
}
Suppose we wish to check for the following errors in ReceivePacket:
a.  That connection c is active. Connection::Active ( ) will return true if this is the case
b.  That no errors have occurred in the transmission of the packet. Packet::Valid( ) will return
true if this is the case
c. That the packet type is known (the default case is exercised otherwise)
Define suitable exceptions for the above and modify ReceivePacket so that it throws an
appropriate exception when any of the above cases is not satisfied. Also define a throw list for
the function.
8. Write a class template to represent a generic vector.  Include member functions to perform the
following tasks:
C++ Supplement                      E­infochips Pvt. Ltd.

i. To create the vector
ii. To modify the value of a given element
iii. To multiply by a scalar value
iv. To display the vector in the form (10, 20, 30, …)
9. Write a program with the following:
i. A function to read two double type numbers from keyboard
ii. A function to calculate the division of these two numbers
iii. A try block to throw an exception when a wrong type of data is keyed in
iv. A try block to detect and throw an exception if the condition “divide­by­zero” occurs
v. Appropriate catch block to handle the exceptions thrown
C++ Supplement                      E­infochips Pvt. Ltd.

10 DAY 11 ( files )
1. Files talks about external and internal linkages.
2. There are systems where file is not the logical unit of storage. Hence 'source code' means entire
code and 'translation unit' indicates code after the usage of preprocessor.
3. “export” template can only be used given a declaration only.
4. Consts and typedefs have internal linkages (by default), but can be given explicit external
linkages using “extern”.
5. A given class, template, enumerations, etc must be defined exactly once in the program. This is
called as “one­definition­rule” (ODR). This specifies that if two declarations are given across
files, they need to be word to word matching.
6. “extern” will be overridden when the variable / function is defined again. Initialization with
declaration is same as definition
7. C++ uses a convenient abstraction called streams to perform input and output operations in
sequential media such as the screen, keyboard or files. A stream is an object where a program
can either insert or extract characters to/from it. We do not really need to care about many
specifications about the physical media associated with the stream ­ we only need to know it will
accept or provide characters sequentially.

10.1 Dos'
1. To do better interfacing and linkages across files, one can use the concept of adding “header”
files, which normally consists of namespaces, type definitions, template declarations and
definitions, function declaration, inline function definitions, data declarations, enumerations,
name declaration, include directives, macro definitions, conditional compilation directives,
comments, etc. This header file may be then “included” in the source programs.
2. “rdstate” ­ returns the state of the stream  e.g. Cin / cout stream or any file stream; one should
check it after the operation performed.

10.2 Donts'
1. Avoid defining templates, classes, enumerations, etc. in more than one files, though they may
follow ODR. This can lead to untraceable errors later.
10.3 Exercises:

1. Write a program that reads a text file and creates another file that is identical except that every
sequence of consecutive blank spaces is replaced by a single space.
C++ Supplement                      E­infochips Pvt. Ltd.

11 DAY 12 ( STL )
11.1 Exercise
1. Write a program using the find() algorithm to locate the position of a specified value in a
sequence container.
2. Write a program that accepts a shopping list of five items from the keyboard and stores them in
a vector.  Extend the program to accomplish the following:
i. To delete a specified item in the list
ii. To add an item at a specified location
iii. To add an item at the end
iv. To print the contents of the vector
C++ Supplement                      E­infochips Pvt. Ltd.

12 C++ PROJECT 
12.1 Requirement Specifications
  Design a verification component that includes minimum following modules/classes.

No Module Class Name File Name Basic Function


(*.h,*.cpp)
1 Packet vc_packet ei_vc_packet A frame/packet to be sent to the
dut
2 Generator vc_generator ei_vc_generat Generates Packet and send to
or BFM whenever it asks for
3 Device vc_bfm ei_vc_bfm Gets the Packet from Generator
BFM and injects into the DUT serially
4 Monitor vc_monitor ei_vc_monitor Here it works as the receiver of a
Device
5 Scoreboar vc_scoreboard ei_vc_scorebo It gets the frame from BFM and
d ard from Monitor and compares them
if they are equal or not
6 Agent vc_dev_agent ei_vc_agent Top level class of a Device
7 Utility ei_utility ei_utility Utility class that contains all the
utility components, e.g.
encoder/decoder, SIPO/PISO,
scrambler/descrambler
For this project it should have
8bit/1bit SIPO/PISO
8 Configurati vc_config ei_vc_dev_co It contains parameters required to
on nfig be configured from user
9 DUT vc_dut ei_vc_dut It is a Device Under Test 
10 Env vc_env ei_vc_env It the most top level class that
contains instances of a DUT and
an Agent.

The verification component should be able to generate the frame and able to inject it into the dut.
The Env class can be instantiated into main() function.

12.2 Suggested Architecture Diagram
C++ Supplement                      E­infochips Pvt. Ltd.

The following diagram is the suggested architecture diagram of the verification component.
Trainee can add any module/block as per requirement but should not exclude any module from it.

U
T
I
L
SIPO PISO I
T

main ()

Env
Agent

Configuration
Packet
Generator
Scoreboard

Device
Monitor BFM

DUT
C++ Supplement                      E­infochips Pvt. Ltd.

12.3 Module Description
This section contains description of all the classes.
12.3.1 Packet

The packet is a basic data­item required to sent to the DUT.  It is a class/struct that contains
declaration of all the fields.  The structure of a packet is mentioned by below diagram.

ST1          ST2        Length      Parity             ……… Data Bytes 1 to 10……….                   END 

Payload

Description of each field of the Packet.

Field Valid Value Description


Name
ST1 0XFE First Byte of the start indication of the packet
ST2 0XAB Second Byte of the start indication of the packet
Length 1 to 10 Length of the Payload in the packet (Number of bytes)
Parity 0X00 to 0XFF Parity of the Payload
Payload 0X00 to 0XFF Data to transmitted into the packet
END 0X11 End Symbol of the Packet
C++ Supplement                      E­infochips Pvt. Ltd.

Values of the fields that are not in the range as per mentioned in the above table should be
considered as “Invalid Values”.

The Packet should be transmitted bit­by­bit from ST1 to END.  The order of transmission should be
from MSB to LSB.  So very first bit to be transmitted will be MSB of ST1. 

Each bit in parity field indicates even/odd parity of that bit­position in payload byte calculated for
each byte of payload. User can keep a configuration field that indicates whether to put even or odd
parity in the frame.
12.3.2 Generator

BFM will call a method (function) of a generator.  So generator will return a pointer of the packet.
Generator should generate the values of the fields as per configured by the user.
It will have a pointer of configuration class that points to the same configuration class defined in the
top level Agent.  While sending packet to the BFM, Parity field can have any value.

12.3.3 Device BFM

BFM calls generators method when it is supposed to have transmit the packet.  It gets the pointer
of Packet from generator and then it will calculate parity of the Payload.  It will overwrite Parity field
into the packet.  Then it will call method of Utility class – “PISO” that will convert parallel byte into
serial data.  Then after it will inject the packet bit by bit into the DUT.  BFM also calls the method of
scoreboard and passes pointer of packet to it.  BFM should print all types of message (“cout”
statements).  It should have all debugging messages also.

12.3.4 Monitor

Whenever packet is injected into the DUT method of monitor will be called and it will form a packet
from list of bit.  So for that monitor will call method of Utility class – “SIPO” that will convert bit
stream into a byte.  List of bytes will form a packet.  The monitor will check the packet as per the
protocol rules, it will show an error message if it finds anything wrong in the packet (e.g. Wrong
Parity, Invalid values of the fields etc.).  Then after it sends the packet to the scoreboard.  Monitor
should have proper messaging.  It should print message for start of packet received and end of
packet and also for all errors.

12.3.5 Scoreboard

Scoreboard compares both the packets and if it finds any mismatch then it shouts for an error.  
C++ Supplement                      E­infochips Pvt. Ltd.

12.3.6 Agent

Agent is the top level class that has instances of all the classes as shown in the architecture
diagram.  Agent should provide the interface between two modules.

12.3.7 Utility

Utility is the class that contains all the generic and utility kind of methods that can be used any
project/component.  Here basic need is to design Serial to Parallel Converter (SIPO) and Parallel
to Serial Converter (PISO).  So it should have minimum these two methods.  Utility can be
instantiated into an Agent and Monitor and BFM can call its methods through back pointer
of an agent class.

12.3.8 Configuration

This is one of the important modules of the VC.  It should have all the possible parameters that can
be used for configuring the VC.  User can configure any parameter using APIs of this class.

12.3.9 DUT

DUT is basically a device under test.  VC should be designed in such a way that it can verify DUT.
But in our case dut will work like a 1 – bit buffer between a BFM and a Monitor.

12.3.10Env

Env is the very top level class that instantiate all the classes mentioned above.  It should have all
the APIs that can be accessed by user. Main() function should have object of the Env.  
Suggest APIs are :
Do_vc_tx_transaction(int number_of_transaction);
Set(fields_of_packet, value);
Get(fields_of_packet);

There are many more APIs possible in the configuration class and in the Env also.
Trainee has to define and add more APIs.

12.4 Important Instructions
1. It is mandatory that the code of the project should contain Exceptional Handling, Pointers,
STLs, Templates, Polymorphism, and Inheritance.  (All the concepts should be used at
least once in the whole project code.)
C++ Supplement                      E­infochips Pvt. Ltd.

2. Trainee is not allowed to take instance of one module into another module except Packet
and Generator.  That means you can not take instance of Monitor, BFM and Scoreboard into
one another.
3. User “Back pointer” concept where ever required (e.g. BFM wants to call Monitor’s method
then first it has to call Agent’s method using its back pointer then Agent’s method will call
monitor’s respective method).  
4. All the variables of a class should be declared as private members while functions as public
members
5. All the variables should have get and set method.  The get method will return value of a
variable and set method will set the value of that variable.  That means one class cannot
use variables of other class directly. (e.g. bfm.x = 10 is not allowed, bfm.set_x(10) is
allowed.  Where x is a private data member of class bfm)
6. All header files should be there in Include director and source files should there in Src dir.
7. Coding style guidelines must be followed.

12.5 Back pointer Example
Back pointer means pointer of the Top­level class defined inside a class that is instantiated into
that top level class.  Here in the following example top_ptr is the back pointer of the top class
defined inside bfm class which is instantiated into that top class.  The aim of this example is to
show how to access top level module’s method from the module instantiated inside that top
module. 

File: ei_vc_bfm.h
------------------------------------------------------------------
#ifndef _bfm_h
#define _bfm_h

//Forward Declaration of the top class - without including ei_vc_top.h


class vc_top;

class vc_bfm
{
public:
vc_top *top_ptr;

void bfm_m();
};
#endif
------------------------------------------------------------------

File: ei_vc_bfm.cpp
------------------------------------------------------------------
#include “ei_vc_top.h”

#include "ei_vc_bfm.h"
C++ Supplement                      E­infochips Pvt. Ltd.

void vc_bfm:: bfm_m()


{
top_ptr->top_x();
}
------------------------------------------------------------------

File: ei_vc_top.h
------------------------------------------------------------------
#include "ei_vc_bfm.h"

#ifndef _top_h
#define _top_h

class vc_top
{
public:
vc_bfm *bfm_ptr;
top()
{
bfm_ptr->top_ptr = this;
}
void top_x();
};
#endif
------------------------------------------------------------------

File: vc_top.h
------------------------------------------------------------------
#include "ei_vc_top.h"
void vc_top:: top_x()
{
cout<<"Top class's method is called "<<endl;
}
------------------------------------------------------------------

12.6 Testcase Example
The testcase should look like following example.

#include “ei_vc_env.h”
int main()
{
  vc_env  env_obj;
  
  env_obj.set(Length, 3);
  env_obj.set(Parity, TRUE); //Indicates even parity otherwise odd
  //Other configuration method

  cout << “Starting tx transaction “ <<endl;
C++ Supplement                      E­infochips Pvt. Ltd.

  env_obj.vc_env_do_tx_transaction();
  cout << “End of tx transaction “ <<endl;

  return 0;
}
C++ Supplement                      E­infochips Pvt. Ltd.

13 MARKING FOR EXERCISES OR PROJECT
After successful completion of Exercises/Project or at end of the timelines as defined in Section
2.2, whichever is earlier, trainee has to send the respective items that matches with the
‘Acceptance Criteria’ as described in Section 13.1 on to the following mail alias.
To: ekata.mehul@einfochips.com
Sub: C++ Training: Submission of Exercise/Project

13.1 Acceptance criteria
Exercises/Project will be accepted as per following Acceptance Criteria.

Item Criteria
i. Final Package to be submitted:
Exercises         [trainee_code]_C++_day[number]_[exercise
number].tar
This .tar file should include source code, desired input file,
expected output file and “limitations.txt” (in case if any)
ii. Coding Style Guidelines should be followed
iii. All the functionality in a given problem should be
implemented. If anything is not implemented or remaining
then trainee should be include that information in a
separate file (e.g. Limitations.txt)
iv. Code should be well commented
v. Code should compile and execute properly 
i. Final Package to be submitted:
Project  [Trainee_code]_C++_Project.tar
ii. Rest all instructions are same as that for exercises

13.2 Marking Criteria
1. Submissions of all the exercise in time and in proper format carries 10 marks each for each day.
2. 50 marks are alloted to Project
3. Late submission will deduct single mark on each consecutive day.
4. Limitations within the project / exercises will reduce the marks but will be dealt looking at case to
case basis
5. Submission of .tar file should be appropriately as mentioned along with the complete naming
convention, this will allow it to be checked automatically using scripts

You might also like