Vasusir Class Notes
Vasusir Class Notes
basics for you 9.30 Am to 6.00 PM stay in the building. balance between knowledge gathering interview preparation exam preparation.** ( small issue ) programming is good but then there is something called company and customers. IT (Invite Trouble ) industry
Trusting is always done to avoid thinking. when we tell we know a concept what does it mean. 1. we should tell the concept in 1 or two simple sentences maximum 2. give an example 3. if we know very well then talk about syntax. they use the word expereince unnecessarily 3 year donkey 30 years donkey only. concept -- not a function of time. syntax is a function of time. so this you may know you may not know .
we are going cover c, DS and C++ 1. with what we are covering, we will be able to balance between knowledge gathering and interview. 2. interview, they ask lot of freaky questions. let us C or C puzzles ( good book ) in IT industry, book industry. fat books people will not read it thin books people will not buy it.
1. introduce you to C with all its advantages and disadvantages. 2. check what is your programming style and
logic building abilities. quick summary 1. timing 2. how to talk without example it is scrap. 3. dont foucs on syntax in the beginning 4. focus on let us C or c puzzles 150 pages, it comes with questins and answers. you code the program, and predict the answer run the program, match the answer and if not correct bo back of the book and look which is the correct answer is why.
knowing a programming language (***) 1. documentation standard for the language (1/5) 2. VARIABLE DATA TYPES, SCOPES, casting rules (5/5) void f1(int x, int y)
int z ;
} 3. how to handle runtime errors and quantify them (5/5) 4. string handling and date handling (2/5) 5. knowledge of datastructures like linkedlists and dictionaries (2/5) how to use then write your own thing. and writing your own thing necessary evil becuase favourite thing for interview people. 6. how to use good tools, test code, profile code ( .00001/5)
A.c int *j=NULL; editor visual studio 6.0 -- interview favoutie code block gnu compiler -- this is good option in today world. challenge in every project is understand requirements (miracle) Design. key thing in design. 1. tradeoff 2. Abstraction = loose coupling 3. consistency.
Quick summary 1. timing 2. books stick with c puzzles or let us c. 3. minimum meaning of knowing a language.
4. basic things to know in design. Coding forget creativity and welcome systematism. 1. always put the requiremetns at the top of the code in form of a comment. 2. we start coding. we should know some basics. 2.1 what do you prefer 10000 compile time error or 1 runtime error. A) 10000 compile time error 2.2 ) what do you prefer 10000 compile time error or 3 compile time error. 3 compile time error. do frequent compilation.
C features and problems. 1. simple becuaes minimum number of keywords. problems are more than the advantages in C.
1. lot of features are compiler dependant and you should know them. 2. C belieives that if a programmer is dumb he should suffer. this is a big problem if you think from a project point of view. array boundary violations you cannot prevent it in C if we return some local variable unnecessarily it will cause problems. ..... what features we want to use. 1. .h 2. int main 3. pass by value, pass by address( pointers). 4. arrays 5. structures 6. dynamic allocation 7. bitwise operators. 8. a little bit about file IO. we want to adding two numbers. int main() {
int i =3; int j = 4; int k = i + j; printf("%d",k); return 0; } int sum(int x, int y) { return x+y; } int main() { int z = sum(2,3); printf("%d",z); } int sum(int x, int y); int main() { int z = sum(2,3);
what am I assuming about you in terms of programming? 1. you know how to write a hello world program in C, 2. you know if else conditions. 3. loops about the way we need to talk, but important thing any thing that cannot be proven technically should kept as a low priority thing. scary word in interview in real life called " in
depth". most of the times when people use this word called "in depth" what they are telling they know lot of words in english and ok our vocabulary improves.
basic things, as a programmer our job is to be pessimistic and not optimistic. in desktop dont have any files other than shortcuts. desktop folder will not have spaces, spaces will create problems
projects. for you in the lab, all you need just one project. create all your programs under this project. try to keep the filenames as meaningful as possible. if hello world program does not work super computer program will not work. it always better to call a function and then define it than define a function and think where to call it. when you call a function, you are forced to think about the functionname, input arguments and return type and then we have to fill up the {} as a c programmer we are never supposed to ignore warnings. if we do we create problems in the project.
style of programming. 1. jsut prove that function is getting called. 2. hello world works everytime. 3. when function does not prove. input arguments are got properly. 4.check the return type of the function. anytime you call a function without a signature it is problem. in any project there has to be only one main and we have to ensure. comments they are required, but in case you dont know whether they are required or not required, dont use them. makeup is good only for alive things and not for dead things. dont worry too much formatting ...
while working, it obvisouly is like this. 1. we should know concept 2. we should know syntax. 3. then we can think of logic building.* mix all 3, gurantted hell. stages of a c program running. 1. pre compilation. this simply means the source code size will increase. 2. compilation process. 3. linking process. your code is getting linked to libraries. call a function and dont define it. 4. runtime error. violating the array boundary 5. logical errors. if ( i == 3)
int k =3; int j =4; int l =5; for( bih ) { if( k == 3) // s1 if( j == 4) //s2 if( l == 5) //s3 break; }
Arrays in general. internally array may be anything. when you talk about arrays you dont need to use pointers. array contiguous memory alloation it has got a common name. you can access it with an index. running thru an array without knowing its size, scary. String array great, because at the end there is a wall null. but determined can climb walls also. array of size 3. int deviceIds[3]; #define size 3 int main() {
int deviceIds[size]; you want to make the 1st element of this array as 4. 2nd element as 5, thru a function.
in terms of assignments. 1. write a program that adds two numbers in add.c, prove it works 2. write a program that subtracts two numbers in sub.c , prove it works. 3. write a program which show a menu 1. add 2 sub 0. exit if user enters 1, then call the add function defined in add.c if user enters 2, then call the sub function defined in sub.c if users enters 0, come out of the program. most horrible way of cming out of the program is exit(0); exit means sucide mission.
couple of things which are banned in our coding . 1. global variables are banned. there are standards like misra standards, jSF standard Motor Industries Standard Research Association. 2. exit(anything); 3. never use infinite loops while(true) { break; }
while (condition) { }
second assignment for you. what is aim of assignment just chexcking do you know hwo to use loops , integer declarations and some function writing. as a programmer we are supposed to do things according to reuriemens and not according to "real" life. write a program called function.c show a menu in the function as m1 1. register a device. 2. activate a device 0. exit. until user selects 0, program should not exit. when user selects 1 ie register a device, ask for deviceId if deviceId is positive ie greater than 0, then go to a menu called m2, else show a message saying device registration failed.
when user selects 1, ask for deviceid if deviceId is between 11 and 20 and go menu m2, else show a message device not accessible as of now. m2 menu. 1. update device status 2. back to main menu. until user selects 2, be in menu m2. when user selects 1, ask for deviceId, if deviceId is more than 33 and less than 66 then ask for status, if status is a value between 10 and 20 , show a message saying status updated. else show a message sayign device not accessible hence status cannot be updated.
third program. 1. create an local int array of size 3 in main. 2. ensure all elementsw in this array are assigned -1. 3. show a menu as follows. 1. 2. 3. 4. 5. add remove modify view all exit.
when user tells add, select the first position in the array where value is -1, at that position ask a positive number from the user and in case it not there in the array add it to that position. the program should work, no matter whatever option the user choses and it does not mean that user will
do add first and then remove.... if all elements are added , show a message saying no more elements can be added. during remove, ask for a number and look that number in the array at that particular position make it as -1. during modify, ask for a positive number and ask for a replace number. in case the number is found in that position replace the new number provided it is not already taken. else show "appropriate" messages.
view all, show all values entered by user. that means -1 should not appear.
anthems 1. developer anthem. 1.1 there are other people other than me in the project. 2. project anthem every project changes. 3. cdac anthem 3.1 i will not travel in the class. 3.2 will not get distracted. 3.3 afternoon sleep is banned. hOpe is yesterday 1. vc++ 2. how you can work with vC++ everybody violated the concept of doing many
projects. people saving the file as .cpp and getting into entertainment mode. minimum basic in c extension is .c 3. in terms of technical concepts. 3.1 why should use function prototype 3.2 meaning of knowing a language. 3.3 c code portability we have to know some conditional compilation. 3.4 design 3.4.1 tradeoff. 3.4.2 abstraction.
approach matters and any concept the key thing 1. concept in one or two sentences. 2. example 3. syntax
all people how to declare int variable , write a main function create new functions and then use basic programming constructs. writing function prototype main funciton defintion.
0. how to write a header file, header implementation and then a .c file which contains main and then tell why all this is scrap as of now. 1. 2. 3. 4. storage classes some regions,stack or heap pass by value, pass by address ( pointers). structures.
test.c sort.h
sortimpl.c
Abstraction will never understandable if we think of only one person doing the entire job. tomorrow is atelast expected better than today -- HOpe. people OR disease. AND.
sortimpl.c
when we use headers we are trying to implement the concept of 1. first decide what you want to cook 2. then we will think how to cook (how to cook can chagne with time)
Storage classes. heap and non heap what is heap. heap is a memory region which can be controlled by the programmer. when we tell dynamic allocation it means we
are talking about the heap region. non heap are memory regions which are not controlled by programmer. storage class tells how long a variable is available in the memory of the system during the execution of the program. storage classes should mistaken with scope. scope is where a variable is accessible. storage class is how long a variable is present. a variable may be present in memory and not be accessible because of its scope. a variable can be associated with only one storage class. void f1() { auto register int i; //sscary thing, }
4 storage classes in C. 1. auto -- default storage class for local variables. ie variables which are defined inside the function, come into existence when the function starts and they get removed from memory when the function goes out. this is termed as auto. 2. register -- story telling, if you make a variable as register, the system will store it the high speed registers of the cpu and hopefully the variable is accessed in a faster way. what is proof, no proof belive it. 3. static static means the variable is available in memory from the beginning of the program till the end of the program. when we have a static local variable we can clearly see, that the variable is local in scope ie outside the function it is not accessible, but it continues to exist
outside the function also. void f1() { static int i=3; i++; printf("%d", i); } int main() { f1(); printf("ok"); // i =4; //compilation i is local scope. f1();
4. extern. extern and static have got special meaning when we talking about multiple source files. somebody asks do you know what is static in C? you want to know about static storage class in general static local variable -- scope and storage class. static global variable or function.
when we have a global variable , global variable is usually a bad idea to use, becuase we cannot control where we are changing it. at the same time global variables are not totally useless, .
global variables are used typically to share data between two functions which dont call each other.
f1() f2() f1 does not call f2 f2 does not call f1 but they need to share data, that means we need a global variable. but the moment we create villain called f3 will come cahnge the variable value. so how to prevent this, answer is.
we create a separate .c file. put the global variable in this file. write only f1 and f2 functions in this file. make the global variable as static. then this variable will not be accessible outside the file ie it gets a file scope. we are able to reduce the scope of the global variable by making it as static.
but however smart you make a program there is nothing that can compete with stupidity of people in the project. what we have discussed so far is. 1. header file and why library is important. 2. storage classes and implilcation of static on local variables and global variables. static global variable referred outside the file results in a linker error. 3. extern means a resource should be available to other files also. it could be functions or it could be variables. storage classes. 1. what is storage class. 2. auto and register. static. 2.1 local variables. 2.2 static with respect to global variables or functions.
extern global variables or functions. extern and static with respect to functions are spoken in context of linkages. when a function has got extern linkage it means the function can be accessed anywhere in the application wehn a function has got static linkagee it means function is accessible only in the file where it is defined. phases 1. define storage class. it applies non heap area and variable definitions. 2. register and auto 3. static local variable -- storage class and scope 4. static global variable and function -linkage. story concluces by talking about extern.
Structures. pass by value pass by address dynamic allocation. some more assignment ( drugs ) make a document like this. 1. date 2. list of topic covered. 3. in each topic what did you learn, give "your own example" and put a .c file or .h filename where you have demonstrated the concept. 4. go google and find out best practices on that topic in case you have some.
typical approach a program is 1. we define the variable with some scope ( we think why we used the scope) 2. we call functions on need basis, think what we need to pass , and what it needs to return
if any 3. have a program that works hopefully. this only hope , most of times program dont work, then it is ok. as long as the program leaves details to why it did not work. rules are only people who dont know anything.
Structure. 1. aggregated type. example suppose we want about a device, device has got two features one is deviceId and then a status. device is not only deviceid or only status, it is both put together. if this is what we want then we need a structure.
how to create a structure. struct Device { int deviceId;// memory is not allocated so //no storage class is associated because in //struct only declaration }; int status;
everything inside the structure are only declarations. void f1() { struct Device d; //d is auto d.deviceId =23; //deviceid and status also is auto. d.status=4; } int deviceIds[10];
structure is an aggregated type things inside structure are declarations how to create a structure array and strucutre variable. pass by value pass by address. it is way thru we pass arguments to the function. suppose we have a function called f1, we need to pass some i int , variable to the function how i is passed , it can be passed either by value or by address. suppose we have a function called f1, we need to pass some i variable which is of type struct Device, to the function how i is passed , it can be passed either by value or by
address. pointers. are mechanisms to achieve. 1. pass by address. 2. dynamic allocation. pointer. what are teh important in terms of syntax. 1. a pointer is also a variable. 2. it got a ability to store the address of other variable. 3. most important it can access the other variable content thru the address.
suppose we have a variable called j its address is 83. and we have a pointer variable called k, it stores j address. then thru k we can change value of j.
which is big , int or char --int int j =3; int *k = &j; int *m = k; //*m =4; printf("%d",j); dont know should i use pointers or i should not use pointers? use pointers.*** (conditions apply) some of the most stupid things we can do with pointers? 1. learn pointer arithmetic ie ptr++ or ptr-2. using pointers with more two levels of indirection is pathetic. int *p; // great int **p;// great int ***p;// dumbness begins.
when does pointers not work. pointers will not work, if we talk about two different process.
In development we can know things "completely" and then start by tyhen we are dead. when we are working on a topic we get doubts about other topics then we cannot do phd on the other topic , we should do a small program on the other topic and at the same remember our original topic , complete poc on the doubt and resume our actual program. pointers will not have meaning if we talk across two differnt process this is becuase address is for one particular process. use pass by value when you talk about two different process
in remaining case be happy with pass by address. 1. stupidity is team effort. 1. header file concept 2. structure concept 3. pointer concept. 3.1 pass by address. 3.2 pass by value , pass by address is not working two process communicating. 1. prove that library works. 2. you take yesterday array program and see whether you can design a header implementaions thru library and main just calling the functions. 3. read summary document what we have done. 4.
no shortage of information, but question can we summarize. summarize. 1. c style of coding. 2. storage classes. 3. pointers. 3.1 pass by address. 3.2 dynamic allocation. pass by address conserves memory. pointers, dont make sense across process. then fate is to use only pass by value. Structure. 1. aggregated type. 2. only when we use structure we can see pass by address conserves memory.
type of pointer, indicates how many bytes it operates on. 1. try to talk about pointers dynamic allocation. 2. function pointers very very important, without this no c project will exist. 3. void ptr, it depends on our mood whether it is good or bad. 4. structure programs. 5. preprocessor directives. 6. string.( favourite thing for the interview) in terms of syntax. 1. how to create a pointer. 2. how to assign an address to the pointer. 3. NULL. 3.1 null is a formal definition for garbage 3.2 it can be used only with pointers.
int *x ;
QUICKLY const pointer and pointer to const . const pointer -- pointers address cannot change. pointer to a constant -- the value of the address which the pointer is holding cannot change. int i=3, k =4; int *j = NULL; j = &i; *j = 5;// this also possible dont like pc j = &k;//this also possible. dont liek this cp stupidity in design is always a team effort stupidity once it becomes popular it is no longer stupidity.
when we are defining a pointer. int *z; // z is a pointer. afterwards if we want to refer z as just a pointer, then we use just z. if we want to refer to teh value of z, then we put *z.
in all projects, typically bad things begin with good intentions. pass by address, is also pass by value only eventually. whenever we do pass by address, and if we lose the address we got, then whatever chagnes we do inside the function will not get reflected outside.
dynamic allocation. 1. programmer wants to control when to allocate memory and when to deallocate memory.
2. dynamic allocation we are used to the world of heap. 3. in all the languages we get some ready made syntax to allocat ememory . what the system tells, tell me how much memory you want me to allocate. ok we tell 13 bytes i want ok fine system will give usually, until we have done some R&d. ok system give us the starting address of where the allocation has began. ok after that what to do, that is dependant on the programmer. tghe most important thing is not to lose the starting address. we told the system give me 17 bytes. ok system gave 17 bytes and told teh starting address is 33.
most important thng is not to lose the 33. no I will lose ok, entertainment guranteed. in form of memory leak. memory leak something in heap and nothing in non heap area. we have everthing on heap and nothing on non heap area, scary program. in c typical funtion we use is malloc. int main() { char *x = malloc(19); } x is a local variable or not a local variable.? x is on stack or on heap? dangling pointer there is a pointer which was pointing to something in the heap once upon a time.
now it is not pointing to that. but we are thinking it is still pointing and if we operate on it then again contact microsoft.
Drug goes like this. 1. create a program and allocate 10 bytes of memory 1st byte store a character called A and next 4 bytes store a number called 7. and next byte store a chracter called Z. and next 4 bytes store a number 33. and then use printf and print the 2 characters and 2 numbers you have here. heavy dosage drug take it only after you felt you understood concept.
status in the main create a local array of Device pointers. struct Device *devices[3]; initialize all these pointers to NUll. 1. register device 2. activate device 0. exit use your old program in case you want to. register a device, in the first position in the array where ptr is pointing to NULL. ask for deviceId , if deviceid is positive and not present in the array, then allocate memory for the device in that position and store teh deviceid detail in the device structure variable. if it is not added, show message deviceid already taken, or no more devices can be added.
after register menu m2. 1. update device 2. back to main menu 2 remains same. 1, ask for a status and then update that particular deviceid status and update the status status shoudl be positive. show appropriate messages.
in menu1 when we tell activate device, we should ask for deviceid, in cas ethat deviceid is found in teh array then go to menu2, else show first register a device. do appropriate cleaning up as necessary. ------------------------next phase.
in the menu1, add an option remove device. if user selects remove device, ask for deviceid and remove "that particular device from the array" and later that should be usable for adding. next phase write header files and make a library if possible.
you should know hwo to attempt programs in phases. standard conditions apply global variables is banned. not more than 4 condition in a function local array in main. goto is banned. measure time how much you took to complete the program.
function pointer. function pointer is not a freaky concept it is a important concept. freask point, when a person starts with syntax it is sure he does notknow concept. what is a function pointer. 1. function pointer is a mechanism in C to do event handling. what is a event.? event means two thins will happen 1. chnage in a variable value ( state change) 2. somebody is interested in knowing about it. in any event handling key things are 1. source of event. 2. place where event needs to be reported usually these two are different people most of times when we code we are in 2.
Events will always happen in a queue. function pointer. there are three steps for function pointer in terms of syntax. 1. creating a function pointer. 2. assigning the function pointer with a function name. 3. using the function pointer which typically calls the function. all the 3 done by one person, function pointer not required. what happens in real life is 1 and 3 is done by one person -- source of the event 2 is doen by other person. -- where we are listening for the event. creating a function pointer. how to create, to create a function pointer we should know the return tyep of the function and also what input arguments the function
will take we dont need to know functionname. 1. example on function pointer 2. what to do in the lab.-- balance.
let us there is a program which calls a function called f1, asks for data, if data is coming as -1. immediately the program has to die( exit(0) ). else program should continue but before program dies it should execute some lines of code, example resource deallocated.
syntax.
all of you will pass in exam,until you use the word, it gives error any time in the lab. compiltime error linker error runtime error logical error.
1. explain me storage classes. 4 storage classes are covered. 1. main function two variables one with local, one with register storage class. 2. function which will be called from main, it will local static variable. 3. in the project add one .c file in that make one global variable static and another variable non static and prove that static global variable
has got file scope. write a function and prove how extern works. 2. header files 2.1 header file concept 2.2 library concept 2.3 usage of library 2.4 duplicate headers why it should be included. header file put two things not only function but one strucuture definition. 3. pointers structure. pass by address cp pc cppc dynamic allocation free function pointer void pointer. 4. structures. create astruture
pass the structure demonstrate . and demonstrate -> what all is pending in C 0. character and string handling**** 1. some examples of preprocessor directives. 2. formatting functions in C 3. file handling in C. 4. bitwise operators. 5. some story telling how C works "internally". 6. election promise we can touch on pthreads.*
write one code to show how code can be written. this all is stupid only in lab exam if header file is not written ....
0. 9.00 AM 1. structure pointer array 2. function pointer 3. importance of char and string, string handling drugs. take it seriously 4. preprocessor directives approaches which matter. 1. can we write a small to prove concept in case we have a doubt during the coding of project. 2. concept, example, syntax. 3. using notepad before coding. we cannot use the word called experience in a dumb way. cocnept surely does not require experience.
Deiter Rams -Jonathan Ive. -- Ipod, Ipad Jay Allard. - gui expert. logic could change from person to person. menu2, you no longer need the array, you just need the individual element. new drug 1. drug1.c , ensure active device works. 2. during update , ensure status is positive. 3. add an option in menu1 for delete , ask for deviceId and remove the element from that position. 4. make header, make library and then ensure program still works.
doubts 0. basic thing when we have doubts, write it down. 1. extern. 2. static global variable.
3. constant pointer and pointer to a constant. 4. dynamic allocation. 5. what should be there in header and library concept.***
1. make library 1.1 we shoudl select a project in vc++ as static library. 1.2 make a .h file. 1.3 make a .c file. 1.3 please dont write main function. under build option select build the lib file. 2. using the library 2.1 prove hello world works. 2.2 copy the lib file and header into the project. 2.3 call the function and compile but please dont run it. 2.4 in project menu settings, link, give the
library name
dynamic allocation. 1. you need a ptr. 2. you need malloc 3. dont lose the address that ptr is holding. 4. but ptr must travel, what to do, ok create another ptr and store ptr address there and then let ptr travel. 5. free (ptr);
int *ptr = malloc(sizeof(int)*2); int *const ptr1 = ptr; *ptr =3; ptr++; *ptr =4; printf("%d",*ptr); ptr--; printf("%d",*ptr); free(ptr1);
non heap area instead of stack, stack will apply only to local variables.
suppose we have an int called i in main function its value is 3. we want to pass this value to a function changeI by address. here it should change i from 3 to 5.
then we want to pass this i to another function by pass by address only where it needs to print the i value.
static and extern. 1. static and exstern both are storage classes. 2. static ensures a resource is available in file scope only 3. nons tatic resources can be accessed outside the file also provided we use extern. 4. we use extern for a static resource, it will be a linker error.
function pointer. function pointer , I will explain thru two phase 1. cocnept 1.1 function pointer is used for event handling. 1.2 typically we write a function and somebody will be calling our function
under a particular circumsntance. example -- atExit ready made function in C, we supply this a function whcih we have writtten, this function which we written will get called whenever system knows that aprogram is about to exit. 2. syntax.' there 3 parts to it. 1. create a function pointer, 2. assigning the function pointer with a function 3. deferencing the function pointer. suppose we want to create a function pointer called x. we have to know what type of function we want to point to. x will point to a function whose return type is void and input argument is void. void (*x)(void)=NULL; SUPPOSE WE HAVE TWO FUNCTIONS F1 AND F2, BOITH OF WHICH DONT RETURN OR TAKE ANY ARGUMENTS. that means to this x
we can assing either f1 or f2. this is called assignment of function to function pointer. x = f1; then when we refer to (*x)(); this will result in either f1 or f2 gettign called depending on what is assigned to x. 1 and 3 is done by one person 2nd is done by another person. example. Event handling we use the word called callback. we have a button called b1. b1.onclick = f1; // this does not mean f1 is getting called now. it means only when the button b1 is clicked
then it has to call f1. Pthread. prove that you know hwo to write a hello world pthread program and prove youi know its syntax.
void pointer. 1. it is mechanism to indicate a pointer can hold anything kind of address. 2. wwe cannot deference a void ptr. 3. a person who is using void ptr should know what void ptr contains. and typecast the void ptr and get things done. 4. remember the developer anthem and do the pthread program. example malloc returns you a void ptr. beucase malloc tells look I want give you an address and what you do with it, is left to you.
void *ptr = malloc(5); char *ptr1 = ( char*)ptr; Strings. drug, create a char array and accept a string into it and then print how times a letter is repeated in teh string. last week interview question. char x[]="Hello"; H1 e 1 l 2 o 1
char in C does mean just char it also means a byte. char x[10] need not be a string. it just be a byte array of 10
String means some characters followed the null character. people give string logic just to see whether persons can do pointer' arithmetic properly. int main() { char x[10]; strcpy(x,"hello"); x[0]='Y'; printf("%s",x); } B.c int main() { char *x ="Hello"; *x ='Y'; printf("%s",x); } void pointer. char and strings
when everything fails in the project, then we can get busy thinking about the name of the project.
yesterday 1. key thing you should how to talk about a concept in theory.
1. void pointer. 1.1 it indicates that a pointer can hold any address. 1.2 we will not be able to on void ptr. 1.3 we typically typecast void ptr to some other pointer before thinking of using the content pointed to by the void ptr. 1.3 using void ptr is matter of "showing that we want to be a decent programmer". void* malloc(int size)
2. function pointer -- syntax should be clear, but still application we need to do some homework, you have look pthreads.
drugs is ok, but then doing drugs which are more relevant to the interview would be better.
pass byaddress story of losing address and predicting whether results come properly or not. we started with the string adventure. the advantage being we have continous allocation with the wall at the last in case we see it we can stop. can you identify mutable and immutable strings.
any double quoted string assigned with a char * cannot be changed. char *s ="Hello How are you"; formal char array which is holding a string. it is mutable. drug. accept a string and find out total nubmer of words
Today 1. spend your time on strings more , some drugs on strings do it. 2. how functions execute 3. introduce you to datastructures. ( 3 and 4 welcome to world byheart it ) stack, queue it will be only demonstrate stack and queue. logic building questions in linkedlist. Trees - concept of trees. concept of graphs three sorting algorithms 4. the stack. 5. macro and function , preprocessor directives.
function call execution we should know ie until function gets executed completely i twont return back. void f1() { f2(); statement } int main() { f1(); }
macros and functions precompilation , runtime type enforcement is checked in a function whereas it is not checked in a macro. quote an example. codeblock on monday gnu compiler. when the same header files get included again, it creates problems if th eheader file has got
definitions. since this is going to create problem we can use ifndef preprocessor to avoid duplicate header file inclusions.
declaration and definition. with respect to variables. this is highly contr.... int i; stupid thing called mood of the compiler. Argument in interview bad thing if overdone but not done at all pathetic thing. when we talk about any kind of programming, the question do w eknow concept first and can we simulate scenarious with the "smallest" program possible. in companies production environment and development environment. a software in c needs to be built for running in linux. we are building the entire code in vc++ and we proving the proejct is working, later on you wan tto
move to linux becuase only then we get paid. syntaxes will not be same in gnu compiler and vc++ 20% changes, these 20% changes if we do it by using conditional compilation then recompiling code in different platforms becomes easier. explain preprocessor directives. 1. preprocessor compiler has to do this job even more compilation starts. 2. in this preprocessors, typical 2.1#include header 2.2macros 2.3conditional compilation, we have two set of compilers vc++ and gnu compiler we want some syntaxes to compiler only if we set it as gnu compiler and some syntaxes to compile only if we set as vc++ compiler and the way we do it by usign conditional compilation. #ifdef vc ....
Datastructures. 1. it is important from interview point , so dont do R&d by reading thick books and all you will out of this course by then. 2.Datastructures are asked in interview becuase that is way thru which they can club multiple questions into one. 3. we will covering, stack, queue, linked list ( singly linkedlist, ), story on graphs and trees ( forests are there ) 4. sorting algorithms. ( 4 sort algorithms and you will hope in interview among 4 , one will come) another problem in datastructues, starting with datastructures is the most pathetic thing in the world becuase we dont know basics, we shoudl start from mathematics.
Datastructures. what is definition of a datastructure. 1. it is about a collection of data 2. you decide on operations 3. decide how to store data. 1. LinkedList. -- growable array. 2. Stack 3. Queue 4. Dictionary ( Associative Array ) or Map or Hashtable ( very very important datastructure although may not be important from desd course point of view)
if you remove 1 then it becomes a data type. data type= content + operations
show common sense meaning in ds is 1. create a set of nodes inthe beginning and then use those nodes, if youneed more make it grow.
in terms of syntax, no big deal at all with any datastructure , all we will doing is. 1. start with null. 2. allocate memory 3. do pointer assigfnment 4. do pointer comparison. 5. remember now there is no configuous allocation. ---------------------------
which is your favourite datastructure ? ( land mine ) there isnothing favourite , it all depends.
depends example there are cases we need stack we linkedlist Algorithms sorting what ismost important thing for sorting? key thing is to know comparison criteria ( predicate function) deciding what will our natural sort. what all things we need during runtime sort.
searching.
3.2 remove 3.3 modify 3.4 reverse. 3.5 view all. 3.6 find out which is center of linkedlist 3.7 find out whether linkedlist is circular. 4. Story on Graphs and search mechansims in grpah, DFS , BFS -- psuedocode. traversal 5. story on different flavours of trees. why there are so many flavours. 6. BST diffrent kind of traversals, PreOrder, INorder, postOrder 7. big O notation 8. sorting, insertion, selection sort, merge sort and quicksort.
hello world. int k =4; int m =5; int *p = null; int **x = null; int j =3; p = &j; x = &p; *x = &k;
int *i = malloc(sizeof(int)); int *j = NULL; free(i); j = malloc(sizeof(int)); if( i == j) printf("ok"); else printf("not ok");
Stack.
in All datastrutures to build we use a word self referencial node. a struture which has got a pointer belonging to itself. example we have a Struture called A and A structure pointer is one of the members of this structure A. struct A { int i; struct A *ptr; };
LAB 1. DO THE CHARACTER DRUGS. Find words from a string which start with vowels tell each vowel how many words start with tell each vowel how many words contain the vowel. 2. at 4.30 stop taking drugs. 3. read C documentation standard. 4. prove you understood teststack.c
0. 3 to 5 people to come forward and summarize whole of last week. 1. feedback 2. more ways to show how to torture. 3. datastructures. tomorrow assignment make a 2 page summary about c documentation standard 2 page arial or time new roman font 10 size two a4 sheets. while summary keep in mind all these thingw hich put in 2 pages will be checked during assignmetn and also during exam. 1.concepts 2. drugs -- characters, datastructures, bitwise operators. 3 to 4 drugs on characters.
Feedback. data 1. totally new to this world what to do.** list me the topic on which you want so called revision.
dont compare yoursefl with others and let bp shoot. list the topics. 1. 2. 3. 4. main, what role does it play do you how to write user defined functions do you how to pass variables. array creation.
3. lab assistance ( cerelac ) 0. uncertainty should be ok while working in technical world. you have to learn syntax by yourself. any topic can be revised provided it is specific. syntax try to figure out by yourself put it in writing every 2 days once we will doubts any doubt in terms , any number of times we will "try" to address. we will try to do every alternate day 1 hour of doubt clearance. miracle thing is peer feedback.
4. speed ( get used to it) in terms of activities. 0. do you have a lilst of ocncepts covered 1. have your got your own examples for each of the concept 2 examples 3. c puzzles. 4. 2 more pdfs to read. 5. take drugs on ds, strings and bitwise operators seriously and prove that we can repeat it. *** we dont have a choice, interview so byhearting is a must. 6. indiabix ..... how 20 questions. gamble 7. your own summary document.
2. conditional compilation 3. functions execute we should know what how function terminates. 4. general story on datastructures. you understand importance of looking at other people program than our own program. CHAP6.LST, for each of the programs in the list, below each line write an explanation what is happening. make a soft copy. Datastructures collection operations store data. examples try to keep it simple as possible dont go into os , system side unnecessary ... stack - undo queue -- event handling linkedlist -- growable array
creating a node on need basis may not be a good idea hence we have think of creating some set of nodes in the beginning and using them and later on growing them on need basis.
show common sense of the canteen guy. in terms of syntax. 1. ptr 2. null 3. dynamic allocation 4. pointer comparison 5. pointer assignment. within next 4 days. by saturday, you have project linkedlist.project write a linkedlist with each of the scenario mentioned in LinkedListProblems.pdf ,should be coded andit should be runnable.
Sorting key things you need to comparison criteria. runtime sort and natural sort. by default you want to have some sort and some user defined action at runtime will trigger a new sort. BigONotation.pdf ---
there is a concept of double star we are using double star primairly to avoid using global pointers. avoid using contraversial statements in the interview. declaration and definition.
Datastructures. 1. time to ensure you learn byhearting in a better way. makeup for dead programs waste of time. take command line arguments and print each word how many time it occurs. string handling.
how relevant these topics from real life point of viewhighly debatable. command line arguments -->
1. add an element 2. remove an element 3. view all 4. check for circular 5. remove a node after knowing posiition. .....
we should see some ready datastructures. Vector, Map, Set -- these are ready made datastructures then we will compare this implementation with our own implementation we can make out inbuilt implementation is better. --------------------------
Queue LinkedList File Handling concepts. ----------------------------Enqueu -- add an element into the queue Dequeue - removing an element into the queue. WHEN YOU HAVE MANY IMPLEMENTATIONS THE BEST THING YOU CAN DO IS use headers ie absrtract__________________
take inspirational code and ensure that it is cleaned up properly when exit is selected after pushing or eq....
0. chapter6.lst -- attempt 3 programs. 1. command line argument drug. -- if you know command line it is enough if you dont do the drug it is ok.
2. 2 page summary on documentation. 3. stack, queue, linkedlist without seeing. 4. BigOnotation.pdf 5. LinkedListproblems.pdf 6. fix code of stack,queue and ensure it exits cleanly. remove operation in ds , big issue is how do you ensure that you dont cut the ds into two or have a chunk of heap without any non heap pointers pointing to it.
1. how you balance time in lab matters. fully drugged scary. 2. tomorrow is there is a test. open test prove me you know concept of pointers. prove you know header fiel concepts, preprocessor directives and storage classes 3. in the desktop assignment. 1. copy your old zip file 2. your keep your this assignment.zip 0. 1. 2. 3. double * file handling io formatting start with introduction to C++
expand IO? Input and Output what is IO? IO is movement of data from place A to place B. what is A or B , A or B can be memory or file. suppose we are taking data from console and moving to a file. memory to file. network programming memory to memory. many a times most of the devices we use are files, we may want to write something to the file, then we need think of IO. what are the steps involved when we do IO. when to use IO when not to use IO meaning of binary files and text files. some syntaxes in context of IO.
we want to have an dynamic array, whose size is mentioned in a configuration file called hi.ini size=4 int main() { read this file and get the size of dynamic array. int size = readFromFile(); int *x = malloc(sizeof(int)*size);
} File can used to store log information. when a program runs, it may get injured, it may die also but everything is ok , as long as the program does not die secretly. when is programming is experi... runtime
problems what needs to be done in a file it can write down, probably what happened which line was executed. when not to use a file. 1. when you strutured information or record based information dont use a file think of using a database. deviceid, devicename, status. why means storing information in is maintenable when compared to a file. struct Device { int deviceId; int status; char deviceName[10]; int usbSupported; } we create two variables of this structure v1
database
and v2. struct Device v1, v2; we have filledup values for v1 and v2 write to file v1 and v2. the problem with the approach is one day when structure changes. old data cannot be read.
what is binary IO and what is textIO. what is binary IO? binary needs interpretation recognizes data types what is Text IO
no interpretation. does not recognize data type. 3 in text mode it takes 1 byte 33 in text mode takes 2 bytes 333 in text mode takes 3 bytes 3333 in text mode takes 4 bytes. 3 in binary mode 1, 2 or 4 or 8
hello.txt write a program that reads all the contents of this file and prints each word how many time it occurs. clue you have to learn read line by line by a file. how to break a line into words. ( strtok )
syntaxes in IO is. 1. File Ptr, we have to get it somehow by using a some ready function of C. 2. while we use this function, it will ask for file opening mode, we can mention it 3. then use some global functions for writing, reading ,, in all these functions
we need to supply fileptr got in step1 4. once you finish reading or writing, figure out "how quickly" you can close the file. FilePtr x = fileopen("a.txt","binary"); char *y = readSomeData(x,100); closeFile(x); suppose somebody is asked to the following take an object called X which is 100degrees hot hold it for one second and drop it, and then run around the building and come back. suppose somebody is asked to the following take an object called X which is 100degrees hot hold it for one second , and then run around the building and come back.and drop it IO
1. couple of examples on how to use fp, some global function, some writing, some reading close the file. 2. some binary io programs. second drug with respect to IO is. create a 3 element int array initialize all elements with -1 show a menu as follows. 1. add 2. view all 0. exit. when user choses 1, ask for a number add the number into the array where the first poisiton is -1. when the user selects 0, program should exit after writing the contnets of the array to a file. when the program it should restore the contents , take care.
how does a c program work , more of story telling . during a typical C program 1. we write code. 2. preprocessor starts header files are included. macros are expanded. 3. compilation starts. 4. binary is provided which is in format of ELF( Extended Link Format). 5. our funtions are going to be linked 6 loading of program takes place 7. 4 memory regions of c Program. Data Segment global variables and local static variables are stored Code Segment function definitions
Stack Segment when a function is executed there is a stack frame is created. prelogue and epilogue for functions prelogue example local variales are created. just before functions get executed what needs to be done, prelogue in which line of function we are executing currently to track this we have something called as program counter. -------------------------------jargon sequence preprocessor compilation elf format link load execute execute 4 memory regions
C++ this is only module you will be using C++ in this course. after this no C++, high chance of sublimation. why touchC++ no projec tin world which uses only C today, it is always C and C++ OO based things is not hype today, it is a reality. expand OO? Object Oriented what is OO? OO is a mechanism thru which we can design software that is easy to maintain. easy maintain.
if were in 1980, we coudl tell OO is only talk no stuff, so let us avoid it but if we are thinking of project 1992, almost all the projects use OO design. in OO we can sure our code is much more easier to maintain when compared to SO. in a typical structured oriented environment what happens is we have to keep things either local or global. most of times in real life project we need a scope which is higher than local and lower than global, this scope a class gives in OO.
summarize --OO 1. it is not talking , we have to prove thru code that we are following OO.
we should enforce the following concepts. 1. abstraction --- interfaces. 2. encapsulation -- class 3. dependancy 4. association 4.1 composition 4.2 aggregation 5. inheritance. 6. packages.
freak point, big problem most of people suffer from two diseases. 1. OR disease. 2. tell me clearly (nothing exists) --contradictions , you got to figure moderation. quick summary 1. oo is not hype 2. history -- abstraction at work. --performance will get hit then issue is maintenance/ performance.
Encapsulation encapsulation is a mechanism thru which we access data in an organized way. hiding data - scary word
the way we do encapsulation in C++ is byusing a class. need is for a student dept person to get something from Admin Dept. C wants to get f1 or f2 of Admin Dept. two approaches. 1. C goes to Admin dept, and tells A or B he wants f1 and gets it. 2. C goes to Admin dept, starts searching for f1 and gets it. in aclass we bind data and functions that operate on that data in a logical way. In Design, what we got to know is the followiong. Desing we need enforce design, it wont be voluntarily complied with. class will give us access specifiers in terms of private and public
typically what we do keep data as private functions as public. once we do this, we can be sure that data is not accessible without the help of functions.
structure and class. structure of C++ and class of C++ no difference. structure of C, class of C++ structure of C cannot enforce encapsulation. class of C++ can enfroce encapsulation. 1. learn something about design, design there will always be contradictions. 2. oo is not hype we are prove oo is going to make things easier to maintain. 3. there is an order in learning oo. 4. encapsulation --- data present in the class and we want to access it in formal way via
functions. 5. once we start doing encapsulation the advantage we get is we can avoid junk from getting our data. class Device { private: int deviceId; public: void setDeviceId(int x) { if( x> 0) deviceId =x; }
} struct Device
{ }
int deviceId;
class and Object. 1. what is an Object Object is something that has got identity. it must have something unique to it. 2. class -- generic way of looking at an object. class is a template for an object. what comes first, class or Object.
Object. when it comes to C++ or Java, typically teh language is designed in such a way that we need to write a class first and only then create an object. when you encounter languages wehre we create only object and not a class be ok with it, beucase that is allowed in OO. 1 . encapsulation 2. class, object, object comes first. 3. once we tell object should have identity the meaning of this technically in the class to whcih object belongs in C++, must have non static variables. class Device { private: int deviceId; // non static variable static int companyId; // static variable
} only if the class has got non static variable then creating th eobject of class is worth. becuase non static variables are created one per object, hence they contribute to the identity ofthe object. C++ and C differences. 1. C is loosely typed, and C++ is strongly typed. data type enforcement is relatively better in C++ when compared to C. int *i = malloc(sizeof(int))) //this will compile in C will not compile in C++ until we typecast malloc to int *. 2. function calling in C is based only on function name, but in C++ it is based on functionname + input arguments. 3. C++ has got additional features like operator overloaidng, templates
4. C++ implement OO is relatively easier when compared to C. In the class when you have a private section it means outside the class it isnot accessible. when you public section it is accessible outsdie the class. whatever you see inside a class are declarations. variables global , local or non local. types nested types. you feel a type context is within other type. design needs to be enforced. struct Window { struct Cursor
{ } }
dont talk about cursor until you talk about window. usuallynesting structure under functions, extremely freaky thing we dont do it it all.
what is variable and what is a type what is a function. quick summary 1. work on test questions and focus on ds, if time permits io. 2. io
3. OO, it does not mean learn C++ now. object means something unique shoudl be there. in C++, the class must have non static variables else there is no point creating object. inside the class variables static -- variable has to explicitly defined by the user, this exists without the object also, it is shared by all objects of a particular class. non static. - memory is allocated when we create the object, per object one copy, hence identity
Heap Segment.
C++ intro.
so called plan is 1. practicals we need to get started with C++ 2. look at c basics ( how casting happens in C double x = 3/2; printf("%d",x); 3. revisit C++ ( inheritance ... 4. ds 5. closing ceremony. yesterday 1. io concepts 2. two drugs given io do it. C++ 1. design standard words what we scope there will always be contradictions and you need to figure out, how do this miracle called "moderation". 2. oo is no longer hype we got to learn it. in your course after this module you wont touch oo. but surely in interview you will touch oo. 3. there is an order of doing things. abstraction
encapsulation..... 4. just becuase a language is designed some way we cannot try to think the concept also is like this only. just becuase in C++ or java we have to create a class and then an object it does not mean everywhere first class willcome and then object. we should be ok with seeing objects without they belonging to any class. what is syntax, relax dont think about this. 5. object identity.== object should have something unique. in C++ langauge, it means the class to which object belongs to must have non static variables. object == instance non static variables == instance variables. typically local variables cannot be made as static or private in C++ here static we are talking from OO point of
view and not from storage class point of view. static keyword could be used in multiple places in some places it indicates storage class, in some places Oo concept, in some places linkage. static variables in the class. 1. for memory is allocated only when define them outside the class. 2. these can exist without an object. 3. these are shared across all the objects of a particular class. thumb rule is we never to prefer use static variables typically becuase in multi user scenarious we run into entertainment. many a time we want counters.
class X { static int i; int j; } int X::i =23; datatype classname::staticvariablename=somevalue; static and non static variables in C++ static and non static functions in C++ reference in C++ overloading namespace. default arguments inline functions.
static and non static functions. typically in OO we make all variables (we are surely talking about variables present in class, outside the functions present in the class ) of a class as private. what is a static function a function whcih exposes the static variable of the class to the outside world for changing or for accessing. static function typpically can be caled thru classname::functionname. static functions cannot access non static parts of the class. static functions cannot access this.
non static functions 1. exposes non static variables to functions outside the class. 2. need an object compulsorily 3. can access everything in the class.
1. C++ , write a stack and queue program using C++. in terms of concept. 1. static variables and non static variables
2. static functions and non static functions. one key difference between static and non static functions there is a keyword called this, this is accessible only in non static functions and not in static functions. make a summary about what is meaning of static and non static functions and variables in context of both C and C++. this. 1. this is implicit pointer. we dont create it, we need to use it. 2. it is present automatically inside the non static function of a class. 3. it points to the calling object. 4. its usage depends on the project (moral science word, use google and collect examples of this usage in OO ) when we have 10 objects of a class, then there will 10 copies of non static variables and only one copy of
static variable there will be only one copy of static or non static functions. concepts so far. 1. static and non static variables and functions 2. role of this pointer. give a syntax example on this pointer. suppose there is a local variable and instance variable with the same name, to differentiate local variable from the instance variable use this before the instance variable. reference in C++. reference in C, we are typically referring to pointers. what is pass by reference , what is pass by address in C? Both are same. but in C++, they are different. Becuase in C++ we have a separate concept caleld reference
what is a reference. reference is an alias for a variable. it is a renaming ceremony for a variable. int i =3; int &j = i; now j is an alias for i. reference itself is not a variable, reference "points to(this is english, dont go to pointers) "a variable.
int &i; here we are taking the address of i , scrap. it means i is a reference. when we create a reference we need to tell to which variable the refernce is created for. int &k;//wont work
what is common to pass by value, pass by address.? in both cases new variable is created. pass by value, actual variable pass by address, pointer variable is created. pass by reference, no new variable is being created, rather an alias for an existing variable is created. what is common to pass by address, pass by reference. we can make changes to the variable inside the function if done properly, usually it show it outside the function in the calling place. function overloading function name same input arguments are "different" f1(int x, int y);
f1(int z)
int main() { int *p = NULL; p = F1(); printf("%d",*p); } namespaces. 1. namespaces are used to avoid naming collisions. 2. naming conflicts becuase we are using third party libraries. 3. naming conflicts can be avoided by using namespaces, provided we keep namespace names atlesat decently. we will create confusion in namespaces also, ok computer will not fight with us. .... we are writing only our own code and we will
not use anybody else code, ok thenyou dont need namespaces, you dont need to do the project also.
if we tell we are using C++ code. key thigns 0. cpp extension 1. we shoudl references. 2. we shoudl use namespaces. 3 we use const 4. we can use templates. 5. we can use oo also provided we know oo. syntaxes for namespace. namespace name { variables function types. } namespacename::resourceName
inline Functions. favourite question of interview guys and we have some stupid answers for them and that will sell. Inline functions ensure that wherever we call the function, the function call is replaced with the lines of the function. there by it may result in the program executing "faster". inline void f1() { printf("hello"); } int main() { printf("hello");
printf("hello"); }
Default arguments default argument is a concept which makes the input arguments of a function optional. it has to be given from right to left. example void f1(int x,int y=5) { } f1(2,3); f1(2,7); f1(3); suppose called f3
suppose we want to make argument y optional. ie if person gives y argumetn we will use it. else we will assume a value for y.
difference between inline and macro,macro type enforcement is not there and inline functions enforcemnt is there. in default arguments we can do function overloading, but the problem is if we create confusion, then we need to enjoy the fun. void f1(int x,int y=3) { 1 } void f1(int x=3) { 4 }
f1(5);
summary 1. static, non static variables and functions 2. this pointer 3. namespace 4. references. 5. inline functions 6. default arguments. 7. function overloading. Const object const functions. 1. const function can be applied only on non static functions of a class. once a non static function of a class is made as const, it will
not be able to change the value of non static variable inside that function. suppose there is class A there is a non static variable in class A i. we have a function called f1. , f1 is non static function of class A. we can change value of i =3 or 4, but once you make the f1 function as const function void f1() const { printf("%d",i); i =3;// compilation error. } const functions cannot chagne teh state of the object. 1. 2. 3. 4. this references namespaces const functions.
header file ( designer) class MobilePhone { public: void setXNumber(int x); int getNumber() cosnt ; } headerimple.cpp void MobilePhone::setXNumber(int x) { }
1. continue with C++ 2. tomorrow put closing things on C. 2.1 bitwise operators 2.2 associativity 2.3 formatting functions. 3. saturday we will again come back to DS, tree, sorting algorithms C++ 0. diff between C and C++ cannot be object oriented, there are lot of other things. 1. static and non static variables and functions 2. namespaces. 2.1 references 3. this 4. inline functions, default arguments. 5. function overloading.
1. 2. 3. 4. 5. 6.
const object and const functions. mutable storage class. constructors and destructors. deep copy and shallow copy friend functions (fillers) exception handling
const functions cannot chagne the state of the object. const function cannot change the non static variables of a class. const function can be applied only on non static functions of a class. in lab exam you cannot use the same variablenames that has been shwon in datastructure code if you do , you fail.
const object an object whose state cannot be changed. const objects can call only const functions. suppose we have two objects d1 and d2. d1. someNonConstfunction(), assuming d1 is not a const object, d1 state can be changed this by this someNonConstFunction. d1. someconstfuntion, someconstfunction cannot change teh state of d1. tell me the most important reason why we should use pointer in C++? dynamic allocation.
concept cosnt funtion 1. it applies non static functions of a class. 2. it cannot change the value of the non static variables ie it cannot chagne teh state of the object. 3. it call only other const functions. const object. an object which can only const functions the state of the object cannot be changed once created why const objects are required, answer for security security moral science word. Secure Programming practice in C. mutable. mutable is a keyword.
mutable storage class in C++ should be used only on non static variables of a class. once a variable is mutable then a const function can change teh value of mutable variable. int f1() const { register int i; }
class A {
} } next question where to use mutable, dont know find out from google.
Constructors Destructors. what is a constructor. cosntructor is a function that gets called automatically by the system when we create the object. why do we need constructor, business logic need. conditionally create objects ( zoom out view) constructors. 1. it is a function, it gets called automatically when the object gets created. 2. it can be used to create objects
conditionally. 3. it can be used not to create an object of the class 4. typically in constructor we intialize non static variables. 5. we can also do dynamic allocation of non static variables in the constructor. 6. on any object typically constructors get called only once. challenge in it is how to convert english into technical stuff.
Destructor is function in the class that gets called when the object goes out of memory. when object goes out of memory depends on whether the object is on heap or on non heap. for non heap objects, depends on storage class. for heap, if youwant destructor to be called by the system, you need delete. what is purpose of destructor
to deallocate memory for the non static variables . in terms of syntax. destructor is only one per class.
what is difference between new and malloc free and delete new and delete are operators in C++ malloc and free are functions in C. in terms of behaviour new and malloc will show the differnce only when we talk about objects and not about primitives ( int, char or float ...) same is the case with free and delete
no difference until we about objects. stupid way of showing difference between new and malloc is like this. int *i =new int; int *j = (int*) malloc(sizeof(int)); free(i); delete i; suppose we have a class called A. A class has got a construtor and destructor. if we have a need to create the object of A on the heap A *x = (A*) malloc(sizeof(A)); // if there is constructor written in A class it wont be called. A *y =new A;//constructor will be called
1. const objects. 2. mutable 3. constructors and destructors 4. new and delete and its comparison with malloc and free.
copy constructor. 1. there is a need for you to create a object based on an existing object. A obj1; A obj2 = obj1; the compiler, bydefault provides you a copy constructor which copes values of the existing object non static variables to the new object non static variables. or the compiler by default copies the state of the existing object to the new object. copy constructor. 1. compiler by default provides.
state shoudl reflect existing object state. so we copy values from existing object instance variables to the new object instance variables, great everything is ok by default the C++ provides the class with default copy construtor. Flow 1. explain context of copy constructor. 2. compiler by default provides you one. 3. copy values --- shallow copy 4. if your instance variable is of pointer type, shallow copy results in runtime errors. 5. 4 forces to wrtie our own copy constructor.
saturday-- afternoon theory monday - morning theory , afternoon lab tuesday - full day lab threat .... wednesday -- full day theory. Thursday -- morning theory, afternoon lab Friday -- advent.... day e saturday - evaluation.
1. library making, header files, preprocessor directives 2. storage classes. 3. pointer concepts. 4. character logic building. 5. stack and queue basic versions. 6. write a linkedlist ( singly linked list)
add view all reverse remove find in between. find multiplication positions. add the elements in sorted way. black box from linkedlist problems.pdf
C++ 1. static and non static variables functions. 2. namespaces, 3. overloading. 4. pass by reference, pass by address, value. 5. const funtions, const objects, mutable. 5. constructors and destructors ( + copy constructor) next 5 days adventure 1. bitwise operators. 2. sorting ( bubble sort, insertion sort, quick sort) 3. Tree
pending topics which will not come in exam but will be completed formatting funtions priority of operators.
friend funtions. 1. to talk about friend functions we should talk about a class first.
2. class has to tell who will be its friend 3. once a function is a friend of a class, it can access all resources in the class, irrespective of whether it is private, public or protected. class A { friend void f1(); private: void f2() { printf("hi"); } }
int f4() {
X obj1; obj1.f3();
class B { } all itmeans B can access all resources of class A. but class A function cannot access resources of class B.
1.operator overloading is a mehcanism thru which we teach the existing operator how to deal with a user defined object. we have the operator int i=3; int j =5; int k = i+j; Device obj1; int j =5; int k = obj1 + j; +
overloaded. example ?:, .*, ::... 4 to 5 find out book or google. during operator overloading we cannot change number of operands. or associativity of the operator. operator overloading typically is a function call. when somebody says I did operator overloading that means they have written a function and system is calling it the system job is to just ensure that it calls your function, what should be done inside it is your business logic and system cannot help. some of the stupid operators to overload is +, -, *, some of the smart operators to overload is ==, =, > ,< , [] LinkedList l1;
summary 1. operator overloading existing oeprator + user defined object. 2. some operators cannot be overloaded ternary operator, and some operators have overloaded only
as member function = operator. 3. we cannot change inbuilt behavior of any operator. 4. some operators have to implemented as member functions becuase the owner of the class alone should decide what is meaning of that operator in context of the object of the class. 5. as far remaining operators we can have global functions or as member functions. remember member funtions always take one argumetn less than global functions in context of operator overloading. Drug. 1. create a class circle, put radius a private member overload operators =, and > and < and == implement == and < as global functions and implement = and > as member functions.
friend functions, friend classes hope is operator overloading is understood. Templates. nice feature in C++
you can write code in data type independent way. you can write a function or a class which is independent of data type. what is a template function template function is a function whose input argumetn is independent of data type. void f1(? x) x can be of any data type, then that means we need to figure out how to writea templatized function. templatized class. a class whose member variable , is data type independent. class A { private: ?x public: void f1(
} cout and cin. what is cout and cin. cout and cin are objects in C++ which are global. cout belongs to the class ostream --writing cin belongs to the class istream. -- reading. int i; cin >> i; here by using the object cin, we are reading from the input stream. >> ---> stream extraction operator. cout << i; << -- stream insertion operator. >> operator called C right shift
<< left shift. >> right shift has been overloaded with the object of istream , if we right shift operator with istream object like cin, we term the operator as stream extraction operator. ...
1. 2. 3. 4.
right shift stream extraction all the above none of the above.
iostream.h -- global variables, classes .. iostream -- everything inside namespace, classes, functions that are templatized.
syntaxes are like proper nowns, there is no point asking why? in computer science automatic means you cook or somebody should cook. 1. what is a template 2. what is template funtion 3. what is a template class.
What happens in Templates internally. 1. templates is a compile time concept. 2. compiler makes copies based on the data types we have used. 3. when templates are used with specialized functions, specialized functions get priority over templates. 4. when a template function is written and we dont call the function, how many copies of template function --- 0 5. when we call a templatized function wer
term it as instantiating a templatized function. 6. when we speak of templates say good bye to header , header implementation. mix both into 1 becuase C++ /C compiler is quite stupid. drug for you in templates. build a stack using templates.
Exception Handling. 1. it is way to deal with runtime errors. 2. example when new operator fails in C++, we get a bad alloc exception 3. Exception handling is very dumb in C++ 4. but what is most important is to know the concepts of Error handling in general.
only functions can cause errors and not classes. "Better be safe than sorry" or "Prevention is better than cure" some person X is walking on the road. probablity and possiblitity. Error handling needs lot of common sense 1. risk profile fo the project 2. can we be "rational" void f1() { printf("Hello"); int i=3; File *fp = fopen("a.txt","w"); } 4. dead and injured scenario. C++
Exception Handling
not done topics so far 7. Tree ( traversals, ) ( not done in the class) 8. bitwise operators
1. complete exception handling syntax. yesterday story 1. importance of collecting data. 2. as a programmer hiding bad news is most pathetic we can do. 3. a solutions that solves all problems is not a solution. File Handling in C in file handling the usual way of handling errors is by using -1. int i,j; int x = scanf("%d %d",&i,&j); if( x != 2) printf("failed"); else printf("ok"); what is advantage of Exception handling? we can do runtime error handling if we give this answer it is pathetic. person will tell, In C we can do error
handling, but we cannot do exception handling. purpose of exception handling 1. we can separate normal flow of code from error rectification flow. 2. we can deal with runtime errors. let us we are doing the followiong things. activate the modem connect the modem send data close modem. rosy flow, everything will work fine, no problems at all, this is too idealistic. we have to think what these lines will cause when it fails. typical C style of error handling
connect modem if(modem connected) { send data if(!send data) data could not be sent. else data sent disconnect modem. } else model could not be connected else modem cannot be activated. if we did this in C++ try {
}catch(modem not activated) { } catch(modem not connected) { } catch(could not send data) { } in the try block what we have is normal flow of code in the catch block what we have error rectification flow. how does the control shift from the try block to the catch block. to catch somebody should throw. in the try block some variable is created and thrown and only then control will come to the catch block. many a times in real life we should know how to simulate scenarios without having data. want to catch all exceptions how to catch catch(...) this is most pathetic thing we can ever use in our exception handling program in C++.
Exception spawning. Exception behaviour in construtors and destructors set_terminate function in C++ ( one more example for function pointer ) with that story on exception ends.
main calls f1. f1 calls f2 exception occurs in f2, it is not handled in f2. control comes to f1 lookin gfor a catch block and then it isnot handled in f1 also control comes to main, it is handled in main , then the corresponding catch block will get executed. this is exception spawning. in the main also it is not handled ok, the program tells the os slap it now.
when exceptions happen inside constructor not an issue you can catch hold of it, but if exception happen in destructor and let it escape from the destructor we are inviting trouble big time.
whenever an unhandled exception occurs in the program, the system will terminate the
program. this behavior cannot be changed. but the system is sympathetic to us, it tells before killing program, tell me, if you want some function to get executed, I can execute for you but then after that program will be killed. this function which tells the system which function to call is called set_terminate. compilation error try { }catch(...) { } catch(int &i) { } catch(char &j) {
summarize exception handling. 1. concepts of error handling 2. separation of error rectification and normal flow , we can deal with runtime errors. 3. syntax is try and catch, control shifts from try to catch because something is thown./ 4. we can multiple catches for a single try. 5. know exception spawning. f1 calls f2, exception occurs in f2, control comes to f1. 6. in constructors exceptions ok, in destructors ensure exception dont come out of the destructor if any exception happens then handle it inside the destrutor. 7. set_terminate another example of function pointer. 8. remeber catch ... and then put any specfic
catch block is a compilation error. what does the compiler provide to a class by default. 1. copy constructor*** 2. default constructor 3. destructor 4. overloaded assignment operator.*** rules in design. 1. tradeoff 2. abstraction 3. consistancy.
what will default constructor and default destructor do. have a look at proveoverloadedassignmentoperatorexists.cp p program and try to write a picture why we used this. C++ 1. exception handling.
2. copy constructor. 3. overloaded assignmetn operator ok, but then it may create problems hence be prepared to write your own one. how do you prevent a copy of the object from being created. 1. write yoru own copy construcctor and overloaded assignment operator in the private section of the class. the fact remains in the industry, lot of people are busy talking about oo than using oo. Inheritance. 1. if we dont know should use inheritance or should we not use inheritance, then we should not use inheritance. 2. I dont know should I use abstraction or not use abstraction then I should use abstraction. Inheritance, most favourite word for inheritance for many people this word called reusability. this is scrap.
what is advantage of inheritance. 1. extensability 2. substitutability. 3. reusability ( just to ensure our luck is good) fact remains that we cannot get 1 and 2, until we use inheritance. what is inheritance. it is a mechanism to create hierarchies in cs. without hierararchy in real life there will be anarchy.
Hierarchy is important in design. this in terms of code means that we need inheritance in terms of OO parlance. we should understand some terminologies. 1. during inheritance the acceptable
terminologies are 1. 2. 3. 4. base class ( suepr class) derived class ( sub class) immediate base class immediate derived class.
irritating word during inheritance, parent and child. class A class B inherits A class C inherits B A and B are base classes for C. B and C are derived classes of A is C a subclass of A? yes is C an immediate subclass of A? no
english meaning of inheritance. inheriance means you should get something exclusive. inheritance is all about base class or derived class, none of the above. inheritance is all about the derived class object. to call something as a base class the base class must have some non static variables.
class Device { public: void setDeviceId(int x); int getDeviceid(); private: int deviceId;
Martin fowler.
Extensability is add a feature into the base class. (projects change) dont make any changes in the derived class. the objects of the derived class will now be able to access the new feature added in the base class.
2. copy constructor and its variations, one more example on this. 3. inheritance 4. smart pointer today is end of C++
Nathan Myrhold 1. complete Inheritanance 2. smart pointer. 3. Introduce you to graphs and trees, BST , you have to byheart this code.
quick summarized. 1. exception handling concepts, syntax 2. how control shifts from try to catch 3. how not to deal with exceptions especially in destructors. 4. be ok with bad news , we should be the first person to give bad news always becuase we are "tiny" in the project process. 5. Inheritance --- it is a design concept. hieararchies these are very important. encapsulation ie data is being accessed in a organized way.
Inheritance. 1. extensability 1.1 we add a feature in the base class and all the derived class objects will be able to access the new feature added in the base class.
couple of things to byheart. 1. public dont tell inheritance. 2. dont use reusability as first feature of inheritance, use it for safety purpose
substitability is we can have a base class pointer and the base class pointer can point to either base class object or derived class object. A *temp =new A;
once you know inheritance, that means A *temp = ? ? can be filled with either an object of class A or its subclasses. ok we did substitutability what we can get with it, answer is simple nothing. overriding. the most stupid we can do in interview start with syntax, when question is about the concept.
overriding is a mehcanism thru which we hide the base class function from the derived class object. why do you want to do overriding. answer is base class fucntion may be insufficient for the derived class object or may be irrelevant to the derived class object
Overriding is like a knife. during overriding it is also possible to take meaningful functions of the base class and make it meaningless in the derived class.
class A void importantThing() { printf("assume doing important things"); } class B:public A void improtantThing() { printf("do useless things"); } when we want to do overridng the the person who wrote the base class , has to take a call what can be overridden what cannot be overridden. when we have a non virtual function in the base class and we show "skill" of overriding it, then the compiler will not give any compilation error. but the system will take revenge on us by ensuring it will never call the function we have written in the derived class.
be ok with constructors in the abstract class these would be used by the objects of dervied class.
class
A *x =new B; x can access f1 of B and f2 of A only typically in freak cases you can also access f1 of A. but surely what we caxnnot access is f3 of B B *y =new B; y can access f1 of B and f2 of A only typically in freak cases you can also access f1 of A. but surely what we can access is f3 of B Encapsulation ... Inheritance Ok we are doing inheritance, but then dont vio... encapsulation. class A { public:
seti() private: int i; } class b:public A { void f4() { setI(); } } main() { B obj1; obj1.setI(); obj1.f4(); }
list of topics 1. extensabilit 2. substit 3. overriding 4. RTP 5. limitation of RTP constructor behaviour during derived class object creation. what is typical behaviour. 1. constructor of base class will get called 2. constructor of derived class will get called above two points, is true as long we have no argument constructors in base class.
Runtime polymorphism. 1. during inheritance and overriding, what happens we are calling a function, which function is getting called depends on the type of object that is being created. 2. this type of object that is being created is known only at runtime. 3. hence this is caleld as runtime polymorphism. example. suppose we have a hieararchy Device, IODevice, StorageDevice. where Device is the base class and remaining two are derived classes. we have a Device class ptr. then we are invoking a method called Activate Device which is a virtual funtion of Device. when we invoke this function, which one will get called depends on type of the object that is being assigned to the Device ptr.
this is called as runtime polymorphism. During runtime polymorphism what we are doing is generalization, becuase we are looking everything from the point of the base class ptr. when we do this, we lose teh ability to access exclusive functions of the derived class. Device *x =new IODevice; if ther is function called f3 which is exclusive to IODevice and we wont be able to call this f3, by using the x pointer.
if the base class has got parametrized constructors then this will not get called implicitly during derived class object creation. call it explicitly in the derived class construtor. is a -- inheritance relationship tiger is a Animal IODevice is a Device has a " -- Associationship. Company has a Employee class Company Employee e1; class Employee
Destructor behavour is opposite of Constructor behaviour during inheritance. when a derived class object goes out of memory destructor of derived class will get called. then destrutor of base class will get called
1. usually during inheritance, destructor dervied class gets called and then destructor of base class. 2. but during runtime polymorphism we have a scenario where derived class is being held by a base class pointer. 3. during these circumstnaces only base class destructor will get called and not derived class destructor. 4. to prevent this problem,we need to make teh base class destructor as virtual. how to make constructor virtual you cant make it. how to make desdtructor put virtual keyword before destructor. Q) answer goes like this constructors are getting called based on the type of object being created.
destructors are getting called based on the pointer types we have. B *x =new B(); destructor delete x;//
Abstract class abstract class is a class designed only for inheritance. typically an abstract class forces something on the derived class. if the derived class does not agree to the condition opf the abstract class then abstract class will ensure derived class will become abstract. how do yoiu know what condition is abstract class forcing answer is look at
the pure virtual functions in the class (abstract functions) 3. we cannot create the object of abstract class becuase business logic wise it does not make sense. the question is not about syntax of how a function is made pure virtual, but why, reason is base class knows that a function is part of hierarchy, but how it is done depends on the specifc subclass.
couple of things of design all bad design begin with good intentions. ideas. Interface. 1 . standard == loose coupling == contract it should not change.
how to create an interface in C++ we create an interface with the help of class syntax. class Algorithm { public: virtual void virtual }
1. zoom in and zoom out 2. inheritance. after RTP constructor and destructor behaviour abstract classes and abstract methods.
to know about how a class will look like, it will always have function with body + some pure virtual functions.
Composition Aggregation.
interface.
it contains only pure virtual functions. some class has to realize the interface. Abstract class and its subclasses. an interface and its realizations. class A:public B like this in C++ we cannot tell whether this is inheritance or interface realization. we can tell taht only after we see what is B. class A {? }
a class having two super classes is multiple inheritance ( False) class A class B :public A class C :public B class Scrap class Junk class Waste:public Scrap, public Junk { } what is problem with multiple inheritance answer it is very very slow.
during multiple inheritance what happens we get into the trouble of multiple vtables, and multiple vptrs. vtable and vptr are terminologies which people like during interview so use it. Explain how runtime polymorphism happens "internally" and "in depth". how does runtime polymorphism happen when we create a class with a virtual function. when you have the virtual function the compiler will create a vtable per class in the heirarchy. vtable?
array of function pointers. address of function, virtual. and eachobject of the class gets a specific pointer inside the object this pointer is called vptr. this vptr is tied to the vtable of the class.
how does vtable and vptr story work during RTP. 1. per class one vtable, this contains the address of virtual functions present in the class. 2. per object a vptr is present, it points to the vtable of the corresponding class. 3. we have a base class pointer and it is pointing to some object X. 4. assuem the base class pointer now calls a virtual function. 5. system will come object X and use is vptr and reach the vtable of the corresponding class. 6. in vtable it will deference the function pointer, resulting in a function call.
we can prove two things. 1. vptr exists 2. virtual function call does happen thru function pointer.
class Z:public A, public B here Z is demonstrating mulitple inheritance False. go and check wether A and B is it a class or a interface, if it is a interface then it is just muliple interface realization. multiple inheritance and multiple interface realization are just english NO.
virtual inheritance. A B D C
what is protected. protected is accessible by the super class and by the subclass but not by objects of both the classes. protected is scrap. class A { protected void f1() { }
{ f1(); }
what to do in the lab. 1. make a list of doubts in C++ 2. whatever assignmetns you have done so far update that readme.txt and keep in the desktop as well your actsbackup folder. 3. practice some pocs on templates and ensure stack or queue is templatized.
inheritance need for virtual destructor. protected. scrap (very important from interview point of view) -- vtable.
1. List of doubts 2. story telling on Graphs and story telling on Trees. ( BST ) 3. all the questions will include that you need to write header, header implemention and .c operator overloading 1. operator as global function 2. operator as member function 3. number of operands an operator takes cannot change. 4. overload the >> operator for istream and prove it works in context of a stack for a pop. Stack s; cin >> s; // it should do a push operation cout << s;// it should do a pop operation.
Inheritance. 1. extensability 2. substitr 3. runtime polymorphism. 4. limitation of RTP 5. constructor and destructor behaviour .... 6. abstract class and abstract method freak topics interface. multiple inheritance. -- virtual inheritance.
dependancy and associationship. template concepts exception handling. Stack, queue ( templatized) .
what you will still have to byheart. 1. tree 2. three sorting bubble sort, insertion sort and merge sort.( most popular sort within the language ) 3. bitwise operators. doubts. 1. templates 2. copy constructor deep copy and shallow copy. 3. dependancy and association. 4. exception handling. 5. substutability 6. runtime polymorphism. 7. inheritance in terms of assignments, what is status.
1. 2. 3. 4. 5.
insert. ( randomly or in some order) remove view all find middle. reverse.
Trees. 1. we have a concept in maths Graphs. 2. Graph theory there are some dots and there some lines vertices and edges. 3. Graph theory a great theory , you have something called directed and undirected graphs. 4. connected graphs and disconnected graphs. 5. weighted graphs which is only logical. 6. cycles. Graph 1. how to tetll a story about graph. 2. how to search ina graph bfs and dfs. 3. Tree and talk about BST and then other trees why it is there.
what is a Tree? Tree is a connected Graph without cycles. or Tree is away thru whcih we can depict hierarchial structures .
Hieararchial structures. 1. Hieararchy along with brings in some trouble. No Hierarchy is bad. having too much of hierarchy is bad , how do you balance. that explains why we have various flavours of trees. statistics for individuals is hopeless. for individuals it is either 100% or 0. 1. BST 2. AVL tree 3. Red Black Tree. Trees are non linear datastructures.
int *ptr[3]; -- array of integer pointers int (*ptr)[3]; -- pointer to an integer array. ( fearture is very useful becuase one of the most commonly problems is array boundary violations, we can fix it by forcing functions to supply an arry of a specific size you expect. thereby array boundary violation can be avoided. problem is like this. 1. we know how to create an int array and how to pass it toa function. int x[3]; f1(x); void f1(int x[]) { //this function receives the x array . } but now the problem is we want this array to be of some specific size try to findout the syntax for passing to a function an array of int of some specific size.
parametrized constructors during inheritance copy constructor. 1. create a class, create an object and then prove you have a function whose input argument is type of the class to which objects belongs to and it is passed by value. you have class called A create an object of class A let us say y. then ensure y is passed to a function by value. that means now you need a copy constructor providedone of A class non static member is a pointer type. class A { public void setx(int y) { x = y; } public int getx() { return x; } private: int x;
class A { public: void setx(int y) { *x = y; } int getx() { return *x; } A() { x =new int; } A(A &x) { x =new int ; *x = x->getx() } ~A() { delete x; } private: int *x; } A obj2; obj2.setx(3); A obj1 = obj2; printf("%d",obj1.getx();
class A { public:
A() { x =new int; } void setx(int y) { x = y; } int getx() { return *x; } void operator=(A &z){ *x = z.getx();
private: };
int *x;
A *z = new A; A *m =new A; z = m;// this work becuase we did overload the operator = if( z == m)
c 3 key topics. 1. bitwise operator 2. formatting function which is just formality 3. casting rules 4. dynamic libraries and static libraries. 5. sorting -6. Big O notation. -- standard story to tell. 1. 2. 3. 4. 5. bitwise operators variable argument list casting rules. vector and map anonymous objects.
what we know datastructures as of now. variable argument List. 1. we can make input arguments to
the function, vary. 1. varaible argument list 2. bitwise operators, struct padding, bit fields . 3. formatting functions 4. casting rules. include cstdarg header. somefunction(int x, ...)
bitwise operators. 1. what is bitwise operators. 2. various operators 3. how to set a bit
4. how to unset a bit. 5. how to toggle a bit 6. how to know what a bit is set as. key thing with respect bitwise operators. XOR 110 011 000
1. bitwise operators ok what it does. 2. we got to know data in form of binary. 3. how to toggle bits.
two drugs for today 1. write a function that take variable list of characters and make a string out of it and return. 2. write a program which does the following. main menu
1. take a number 2. exit. take a number then show options ask a number. show options 1. set the bit 2. check the bit 3. toggle the bit 4. clear the bit 5. back to the main menu when 1 to 4 is entered ask for bit that needs to be set or check or toggled or cleared.
Unions
Union is a mechanism thru which you conserve memory. this is totally a scrap statement becuase in todays world it is highly debatable how much you conserve byusing a union. structure and union structure is aggreated structure union is exclusive type unlike the structure memory is allocated for the larger type and at anygiven point of type only one can be referred to. union TravelMode { int serialPort; int usbPort; };
int i; char *s = &i; *s S++ *s s++ bit fields. -int i =2; i=5+ i << 1; printf("%d",i); teach12.com greatcourses.com
(double) ++ i /2;
C 1. header files. 2. how to write a .c file 3. function prototypes 4. arrays, pointers(...). 5. structures 6. unions , bit wise operators, bit fields. 7. expression evaluation. 8. mutable and immutable string is over. 9. file io is over. 10. diff between macro and function. 11. storage classes. 12. preprocessor directives 13. command line arguments. 14. variable arguments. 15. memcpy and strcpy. strncmp --- strcmp
char empname[10]; char buffer[10]; int *x = buffer; *x=23; printf("%d",*x); find out what is placementnew in C++ and write a smallest program possible for doing it.
15. formatting is over. struct Device d; -- 40 struct Process p -- 20 char x[40]; we want advantage of the heap like dealloction and allocation.
but want to avoid the big disadvantage of heap ie , forget to deallocate at the same time we want overcome teh limitation of the stack.
Q) are strings important in real life? yes why human beings understand only strings.
char x[3];
printf("%s",x); what all thigns will come in the lab 100% in today class 1. bitwise operator 2. memcpy, strcpy, memcmp, strcmp, strcpy and strncpy
1. bitwise operators. 2. unions and we can use bit fields as kind of bitwise 3. when it comes to operators knowing predence a good idea, or we should () more frequently. 4.strpcy and memcpy does different things and we can appreciate it provided we dont abuse char always like a String. 5. moral science word is summarization we are dead with just data.
enum dynamic library and static library closing for c. Sorting algorithms
Static libraries a static library is one which becoems part of our application if we have a static library called x.lib, we are developing a project and after that we have generated the binary for the project and then we remove x.lib from the project still our project will work. new features are added into x.lib
we need to use the new x.lib and compile our application again and get anew build if this happen it is static library. (this will appear in the lab exam)
Dynamic libraries. which does not become part of our application when it comes to dynamic library 1. we have a lib file called x.dll. 2. we are using x.dll in our project.
3. we need to write code to load that in our project. 4. once the dynamic library changes we need to put the new dynamic library module in our project. 5. our project does not need recompilation.
Datastructures. 1. story about ds ( stack, linkedlist, queue) 2. story about graph and tree. 3. code. 3.1 stack, queue, linkedlist(logic) 3.2 stack, queue thru templatized stuff. 3.3 BST and how to insert, traverse
Anonymous objects in C++ VEctor and Map in STL. dynamic cast ie RTTI in C++ explicit constructor and conversion functions. story regarding Big O
syntax of anonymous objects in C++ will look like this. classname(supply some arguments) A(); Explicit constructor. a single argument construtor in the class acts like a conversion function to avoid this, we can make the constructor explicit. suppose we have a class called A. in the main program we have created and object of class A in the following
way. A obj3 =2; here 2 needs to be assinged to obj3 as when obj3 is created. what C++ will do , look for a constructor in A class which will take an int as an argument, if it is present, it will create an object based on the int and return that to obj3.
class A A() { A(3); } // obj1 A(int x) { //surely this is not called obj1 } int i;
suppose we have a char and we want to convert this into a class A object, the system will come to the class A
and loo kfor a constructor whose input argument is a char. and it will use this constructor to convert char to A class object. if you want to prevent constructor from acting like a conversion function then we need to make the constructor as explicit.
STL expansion Standard Template Library. this is ready made datastructure library available in C++ example we get a linkedlisdt, stack, Queue ready made here we dont need to write code, for creating them we need to write code for using them.
and you get some algorithms also along with it, find, sort.
create a list add to the list remove an element from modify the elemtn in the do view all. sort.
Design patterns.
http://www.oodesign.com and collect information on the following design patterns 1.Singleton 2. Iterator. 3. Observer. 4. decorator 5. factory 6. proxy. 7. Adapter. 1.Singleton many a times we want to create only one object of a class. class A { private: A() { } public: static A* get() {
if(temp !=
null ) return temp; else return new temp } private: static A *temp;
2. Iterator.
assignments 1. variable arguments. 2. bitwise operators****** 3. placement new operator in C 4. dynamic libraries and static libraries. 5. singleton 6. memcpy and strcpy.*****
class A { private: A() {} public: A& static get() { static A temp; return temp; } } A &temp = A::get(); Iterator is a design pattern that is used to traverse thru datastructures
1. sorting, graphs searching in a graph 2. wha is expected in the exam. 3. list of assignmetns what i plan to evaluate ( the coming monday evening ) 4. next what. 1. get the context. 2. three objectives. 2.1 more relevant in the job bench mark we can be better than 2 years expereienced 2.2 get thru the interview. 2.3 tomorrow adventure. technical things. 1. things are simple ok, but then certain things make sense only if logic building involved else they tool trivial. bitwise operators or bit fields ( union makes sense ) 2. importance of knowing mem functions. we dont want to treat char only like a string but we want to go about treating char like a byte. 3. libraries, dynamic libraries and static
libraries. 4. anonymous objects for fun we have to know when it gets created, when a function returns an object a typical anonymous object. 5. ready made datastructures there are something called design patterns.***** Vector and Map
Formally C is is over. -2. data is free, you can get it tonnes, but then what you do with it. -1. be ok with uncertainty. -- you have to build poc 0. getting conscious about the talk concept in two sentences example4 syntax. talk about best practice and worst practice. 1. try to complete c puzzles atleast two next within next 5 months
2. interview questions indiabix, career , cprograms.com ..... arrays char pointers bitwise operators. 3. each 5 programs drugs that we added yesterday. 1. bitwise operators 2. variable argument and string contenation based on characters passed. 3. dynamic library** and static library. how to get "good" marks in the exam? 1. strictly no copying if you do consequences will be terrible. 2. no poem writing. 3. you always save time by opening notepad in lab exam. 4. at some point you have to stop coding. in the folder 1. you will keep project files with .c dont store files in desktop. template stack
stack.h template<class x> class Stack { public : void push() } test.cpp #include "stack.h" int main() { Stack<int> s; s.push( }
{}
.h class A { public:
A(); A(A &x); void setx(int z); int getx(); private: int *x;
drugs. 1. overloading the stream insertion operator and stream extraction operator.
Stack s; s > 3; //push int x = s ;// pop void operator>(Stack &s, int x) {
memxx related functions 1. memcpy 2. memcmp 3. memset. 4. strtok gets option , no command line arguments in the exam. Assignment two more things get added.
1. overloading stream insertion and stream extraction for stack datastructure. 2. vector 3. map 4 . singleton design in C++ 5. factory design pattern in C++ in C++ when we are trying to initalize a variable in the construtor, we prefer to intialize the variable via member initalizers rather than thru assignmetn operator. class A { this
instead of
drugs vector 1. add --- ensure number is added only if it is unique 2. remove 4. view all 5. sort 0. exit
tree , Map internally will use Tree Datastruture. 1. put key and value 2. extract value 3. remove key and value specifying key 4. check for key whether it is present or not present. 5. run thru the map. using a char * as a string is a sign that we are in bc period in programming. done a program which prints each word how many times it occurs. 1. by using a map. Map key must be the word. value must be the number of occurences. compare the logic that you did the map with the logic if you did not use the map and put down the comparisons. IO
1. text io 2. binary io 3. fomratting functions find out equivalent of things in C++ , this is not an assignment try doing it voluntarily.
any sorting algorithms the story telling should go like this. 1. story telling about what is the sort is two lines. 2. talk about as though we are talking some logic 3. close the story with Big O notation for that
typically in sorting algorithms what we get is n log n algorithm which is best case.
in debugging, break point, step in step over is good after we have localized the problem, till then we have to go for logging.
Big O Notation story Quality 1. data driven. 2. we cannot take "refuge" under averages. 3. who is friend -- consistancy. Big O 1. Big o notation is an example how to measure efficiency of an algorithm relatively. 2. tradeoff we tell space wastage is ok, but time is important. 3. we are measuring things over number of size of the collection.
4. we are trying to measure things over best case worst case average case. ideally want an algorithm that works in all the 3 cases very well. ideally does not happen. Quick Sort -- worst case is not good Merge Sort. -- when compared to merge sort -- n log n
Datastructures. 1. stack (templatized) 2. queue (templatized) 3. linkedlist 4. Tree -- BST 5. Vector 6. Map
7. searching a value in a tree. finalds.pdf -- monday -- run thru it and let me know 1. 2. 3. 4. Linkedlist.pdf chap...pdf big o.pdf finalds.pdf
C 1. header file, dynamic library, static library 2. storage classes. 3. pointer concepts 4. structures 5. character processing 6. bitwise operators. 7. mempcy and strpcy. 8 . file io. C++ 1. static, non static functions, constructors, destructors. 2. operator overloading 3. templates. 4. inheritance, rtp, abstract class, interface,
dependancy, association. 5. exception handling. 6. references. 1. plan to take 10 to 15 days to evaluate assignments. folder name readme.txt 0. rollnumbers and names. 1. concept document , you should make it as points and not as paragraphs. 2. concept -- which .c file or .h or.cpp file to know the concept. by tuesday 19th March 2013 5.30 PM in your DESD\backup folder. single zip file. in case it is not there .... 90 1. exam marks 2. exam viva
1 to 44 evaluation will happen tomorrow friday. with respect to exam. 1 to 20 -- dont go for lunch stay for viva 20 to 44 , comeback after lunch, viva will get over. 45 to 88 we will do it on saturday. after 2.00 PM 1.summary skills. 2. making poc. 3. on each topic atleast 5 interview questions. 4. best practices and worst practices. 2 each topic. each of viva will recorded.
Averages.