User Tools

Site Tools


opus:spring2012:rmatsch:cprogpart2

cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)…xxxx ■ logic and operators (and, or, not, xor)

■ Scope (Block, Local, Global, File)

■ Type Casting

■ Structures (Declaration, Accessing Elements, Pointers to)

■ typedef, enum, union

■ Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments

■ Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)……x

■ I/O Streams (cin, cout, cerr, stream operators) [C++]……xxx

■ Namespaces [C++]…xxx

■ Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]

■ Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]…..xxxxx

■ Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

■ Overloading (Functions, Operators) [C++]

■ Exception Handing (throw, try, catch) [C++]

■ Templates, STL (Standard Template Library) [C++]

Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)

Flags In programming, a flag is a predefined bit or bit sequence that holds a binary value. Typically, a program uses a flag to know when a data stream ends and new data begins. good example is flags used in networking. For example: 1010100 (flag to say hey begin recording) 0101101 (data) 0111011 (data) 0101011(flag to say hey end of data stream)

assembler Is a program that takes basic text in a programing laguage and translates it into bits the processor uses for excution of task. is you are engineer that builds computers you would most likly know assembly laguage.

Binary Code code made of 0's and 1's known as low level programming, called machine language that most programmers don't work with but compiler use.(Assembly language)

Preprocessor program started by the compiler as the first part of translation,it handles #include, #define, and #if.by replaceing #include with stdlib.h or other hearder files you have listed example #include <stdlib.h>

cprog Keyword 10

I/O Streams (cin, cout, cerr, stream operators) [C++]

Definition

in c you use stdin, stdout, and stderr. in C++ you use cin, cout, and cerr. cout- is an object of class that represents the standard output stream. cin- Standard input stream (object) cerr- Standard output stream for errors (object)

Demonstration

<iostream> in C++ example while (true) {

 cout << "Please enter a valid number: ";
 getline(cin, input);

in c int value =0; printf(“please enter a number:\n”); fscanf(stdin,%d,&value);

Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]

Definition

c++ is a way to maintain your code through c lasses to make code more organized. in this class there is there is a public,private protected. these are the access for the class. what is in public can be accessed from anyone. thoses in private cannot be accessed at all from anyone unless there is a way to access it in protected like in the below example with get x.

Demonstration

#ifndef _GATE_H
#define _GATE_H
 
//sample code for classes dealing with inheritance
//abstract base class..
//base class
 
class gate{
        public:
                gate(); // constructor
                bool getx();
                void seta(bool);
                void setb(bool);
        protected:
                void setx(bool);
                bool a;
                bool b;
        private:
                bool x;
};
#endif

Type DEf

Definition

When using same type of data for many declarations, you can customize its name and “re use it with out re writing the name again and again . In C++, the type def keyword allows you to create an alias for a data type. The formula to follow is: typedef [attributes] DataType AliasName; The typedef keyword is required. The attribute is not.

Enum short for enumerated data allow a user to define a fixed set of words that a variable of type enum can use as its value. The words are assigned integer values by the compiler so enum values can be compared.

A union is comprised of a collection of variables of different types, just like a structure. However, with unions, you can only store information in one field at a time. Once a new value is assigned to a field, any existing data is overwritten with new data. The use of unions can save memory if you have a grouping of data and only one of the types is used at a time. The size of a union is dependent on the size of it's largest data member.

Demonstration

struct person{
        char *name;//or --char name[20];
        unsigned char age;
        short int weight;
        float gpa;
        };
//struct differ from union bec struct  allocate memory for each and dont share like union
        typedef struct person P;
        P p1,p2,p3,p4,p5;
        struct person p1;
        struct person p2;
        struct person p3,p4,p5;

        p1.age = 29;

Standard I/O (STDIO, STDOUT, STDERR)

Definition

stdio or standard input is defaulted to the the keyboard. standard output is defaulted to the screen. stderr is also defaulted to the screen for err msgs

Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

Definition

is a thing that is inherited. example: B can inherit A and be a child

Demonstration

Demonstration of the chosen keyword.

gate :: gate() {

      a=b=x=false;

} bool gate :: getx() {

      return(x); //return x to have acces to x

}

void gate :: seta(bool a) {

      this->a=a; //property of c++ refer to self

} void gate :: setb(bool b) {

      this->b=b;//-> this is a pointer

} void gate :: setx(bool x) {

      this->x=x;

}

Namespaces [C++]

Namespaces allow to group like classes, objects and functions under a name.

namespace myNamespace {

int a, b;

}

Funtions,parameters

Definition

A function in the C programming language is code that has a name and property that are reusable. This means that a function can be called on from as many different points in the program as needed.

A Parameter in the C programming language is any data that is passed to a function. Demonstration

Demonstration

#include<stdio.h>
#include<stdlib.h>
 
int sum(int, int, int, int); //function and parameters expected
 
float avg(int, int, int, int); //function and parameters expected
 
int main(int n1)//main is accepting a integer value for parameter 
 
{
return(0);
}

cprog Objective

cprog Objective

establish a better understanding of c and c++

Definition

the objective entails learning about type defs classes and working projects

Method

create a program that incorporates classes with code and type defs

Analysis

upon Reflection of my results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • I did ok
  • Is there room for improvement?
  • Yes
  • Could the measurement process be enhanced to be more effective?
  • Yes
  • Do you think this enhancement would be efficient to employ?
  • Yes
  • Could the course objective be altered to be more applicable?Yes
  • How would you alter it? I wouldn't
opus/spring2012/rmatsch/cprogpart2.txt · Last modified: 2012/04/02 05:16 by rmatsch