Archive for the ‘Programming’ Category

c++ pointer

1.pointer must be initialized

2.*a=&b,address of b=>a

3.all points needs 4 bytes. short*p=&b,means type b needs 2 bytes

4.*p=&b: b addr=>p value;b=*p:value that p points to =>b;*p=5:5=>value at p points to   *p=0:void pointer

5.after pointer declaritino:p=&b,works,just like type,”short *” is a type

6.memory:stack,global storage,code area,register(stack-top pointer or instructive pointer),the rest is heap

7.stack can be released automatically,but heap needs to be released by person

8.new:allocate memory for heap;new returns address,so p=new int;

9.p=new int;=>delete p(p still exists,but not point to memeroy anymore;=>p=0;delete p(delete void pointer)

10.create new object/new pointer=>call constructor;delete pointer/working range ends=>call destructor

11.member function: object.getage() is equal to p->getage()

12.const int*p: the value at p can not be changed;int * const p:the address stored in p can not be changed

13.cin.getline(buffer,buffersize)to get the input string

14.isanum():Tests whether an element in a locale is an alphabetic or a numeric character.

15.if after you called a function,you wanna keep the value of variable,pointer or reference as parameter,which means you can change the value in the function,such as:GetWord(char* theString,char* word,int & wordOffset)

16.const int * p: p is a pointer who points to an int variable.and the variable can not be changed by pointer.int* const p:p is a pointer who points to an integer.and this pointer can not be assigned again.

c++ class

1.data and methods in one func are private by default.declaraion:class,visit:.

2.in Class,public accessors and member functions,private member data

3.difinition of class:”::”

4.constructor and deconstructor functions,same name with classname:Cat()=>Cat kitty;,~Cat()//Cat(int,int)=>Cat kitty(2,3);

5.member function const: getAge() const; cz it doesn’t change value of member variables of objectany member funcs that won’t change member varialbes should be set to const!which is a good habit!

6.class declaration is put in .hpp file which is like an interface,and class difinition is put in .cpp file,and #include ” .

7.inline member function:1)inline in difinition 2)in declaration,write the whole difinition 3)hpp”

8.struct,default public,but without methods

9.different instances of the same class can visit each other’s private member data!

c++ function

1.function are all global,but if u wanna call it,u must declare it first.

e.g. if wanna call a func in main(),you should before main(),write func prototype and define func after main()

2.global variables:define outside main,any function can use it;local variables,effective in block

3.function:return(x<5)=>function is bool

4.default parameter:func(a,b=1,c=2),attention!if b doesn’t have a default num,it’s useless that a has a default num.

5.reload function=>polymorphism:only return type is different,wrong!

c++ variables

1.case sensitive:myAge

2.Ctrl+F5:see result

3.for both unsigned or signed,overflow will lead to return to square one.

4.enum CoLOR{Red,Blue…}

5.to write simple codes,dont use too many brackets

6.! >> && >> ||

7.if(x=3)=>x=3,true and if(x=0)=>x=0,false

I/O

output:

  • println()

input:

  • int n1=readInt(“enter”)
  • double n2=readDouble(“enter”)

 

ACM library

acm.program is a package

it has classes like “ConsoleProgram”DialogueProgram”GraphicsProgram”
acm.graphics :package

it contains:GObject,GFillable…

 

so in acm library, you can check any packages and classes included

VC+Matlab

http://www.vckbase.com/document/viewdoc/?id=1435

It can be applied in graduate thesis presentation:

GUI with VC, and call M functions to calculate or draw plots.

Visual Studio shortcut

Fn+

  • Ctrl + K + C – comment
  • Ctrl + K + U -uncomment
  • Shift + Alt + Enter – full screen
  • F5 – debug
  • Shift + F5 – stop debugging
  • F9 – breakpoint
  • Ctrl + Shift + F9 -delete all breakpoints
  • F10 – step out
  • F11 – step in

Programming Methodology(Standford)

This is an amazing open course from Standford whose lecturer is Mehran.

It introduces most of the basic to intermediate knowledge about programming using Java.

No more than 30 hours to learn Java is a pretty good deal.

I recommend beginners to have a look at it.

how to generate a correlated matrix in Matlab

to generate a correlated matrix H=[X;Y] with covariance matrix \Sigma:

first generate an uncorrelated matrix H’=[U;V]

So H=sqrt(\Sigma)H’

E[HH^H]=\Sigma