




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Advanced Topics in Electrical Engineering; Subject: Electrical Engineering; University: Syracuse University; Term: Spring 1999;
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





1. Statements Preprocessor directives Declarations and Definitions Expressions l-values and r-values Statement evaluation model Overloaded operator model 2. Declaration, Definition, Expression Invocation A declaration informs compiler of a type A definition allocates memory and defines its content via compiler and run-time system Invocation changes program state as defined by a program expression 3. Statement Grouping Blocks Functions Classes Programs Systems 4. Strict typing Declare before use conversions Header files Implementation files 5. Data input and output Command line Standard input Standard output Files Mouse events - windows Edit controls - windows 6. Memory models Static classical model Stack reusable scratchpad Heap dynamic allocation for run-time flexibility 7. Classes and objects Construction and destruction Function overloading Syntax equivalences **_8. Templates
10. Packaging in modules Header file Directive guards Manual pages Maintenance pages declarations Implementation file prologues definitions test stubs 11. Syntax and Semantics Syntax is the grammar which defines correct use of symbols to form statements Semantics defines the meaning of a statement
bool condition = true; const long int x = 3L; double xCoordin;
struct point { double x; double y; }; point myPoint = { 1, 2 }; class neuron { public: neuron(int n); ~neuron(); numInputs(); double& weight(int n); double& input(int n); double output(); private: double *weights; double *inputs; int _numInputs; };
int iarray[3] = { 1, 2, 3 }; point points[3] = { {0,0}, {1,-1}, {-1,1} }; neuron nArray[5];
point &pointAlias = myPoint;
enum colors { red, green, blue };
An expression is a combination of one or more identifiers, constants, strings, parenthesized expressions, and function invocations. Combinations are formed with operators. x * y x% i++ 3 + f(x) + g(y) “this is a string” *(ptr + 2) Each term in the expression must have been declared previously and must be type compatible with the other terms.
An l-value is a named storage location. int x; point myPoint; An r-value is an anonymous (compiler defined) memory location used to store temporary values, e.g.: 2 + 3 f(x)
A statement is an expression followed by a semicolon. When the compiler evaluates a statement the statement is scanned and: all functions are evaluated first and replaced by their return values if any combinations are evaluated using the highest priority operators first and each is replaced by its value before preceding to the next combination the order of evaluation can be controlled using parentheses. Parenthesized expressions are evaluated first. 23 + 4 (23) + 4 6 + 4 10 Only l-values may appear on the left side of an assignment operator int x = f(y); As statements are scanned during compilation the compiler looks for type mismatches. If found it will attempt to resolve them through language defined conversions or one level of user defined conversion^1. If this does not succeed an error is declared. (^1) Definitions of conversions can be supplied by a class designer to show how to convert other types to and from the type of the class.
Classes Classes and structures are collections of heterogeneous variables and functions which are allowed to operate on that data. The only difference between C++ structures and classes is that structures by default allow clients to directly access their data and classes do not. class point { // class declaration public: point(double x, double y); point(const point& p); ~point() { } xval() { return _x; } yval() { return _y; } point operator+(const point p) { return point(_x+p._x, _y+p._y); } private: double _x, _y; }; // constructor def point::point(double x, double y) : _x(x), _y(y) { } // copy constructor def point::point(const point &p) { _x = p._x; _y = p._y; } point myPoint(1,2); // object declar/def double xCoor = myPoint.xval(); // invocation point yourPoint(2,-1); // this is addition of two points point newPoint = myPoint.operator+(yourPoint); // and this is a nicer equivalent form point newerPoint = myPoint + yourPoint;
Program A program is a grouping of^2 : preprocessor statements global data declarations class and function declarations function definitions Each program must have exactly one main function. This is where execution of the developer’s code begins. Execution of developer’s code ends when the thread of execution leaves the program’s main function. Modules When programs get relatively complex we partition them into modules. In this class a module is defined by exactly two files^3 : Header file consisting of a manual page, maintenance page, declarations^4 , and optional design notes. Implementation file consisting of a module prologue, function definitions (each function has a small prologue) and a test stub. The complex program consists of an executive module which is responsible for all activities of the program. It delegates most of its work to one or more server modules. Each server focuses on a single activity or a cohesive set of related activities. The executive module includes the header files of each of its servers with preprocessor include statements. Any of the server modules with use the services of one or more of the other servers also includes their header files. This inclusion allows the compiler to check the types of all function invocations to make sure that the data interfaces are valid. System A system is a group of programs, each running in its own process, that interact cooperatively through shared data and remote procedure calls to carry out some major activity. (^2) Program statements are usually ordered in the sequence shown here. (^3) There is one exception to this “two file” rule. An executive module need not have a header file since no other module uses its services. (^4) No definitions are allowed in header files except for constants and inline functions.