Download presentation
Presentation is loading. Please wait.
1
Eine By: Avinash Reddy 09/29/2016
2
Concept Current Applications, gives a unstructured way of Sharing pictures with bit of vagueness often do not fully relate the experience of a day Our social networking application allows a user to share an entire experience of a process or theme of an activity, rather than vague snaps Putting a intrinsic structure to share an process of what users wish to do Set and assign Themes for a day
3
Intrinsic Productivity
Social Application Intrinsic Productivity Eine
4
Theme + Time + Photos Eine
5
Assign + Time + Photos Eine
7
Project Requirements Web Development iOS App Development
8
Conclusion Sharing the entire process of what you actively wish to do is very important. Also being social, should have a intrinsic by-product of improving our lifestyle.
9
Thank You
10
CS410 – Software Engineering Lecture #9: C++ Basics III
Today’s Topics Storage classes The operators new and delete The scope resolution operator Nested classes Static and const members The “this” pointer Constructors and destructors September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
11
CS410 – Software Engineering Lecture #9: C++ Basics III
Storage Classes Every variable and function in the C++ kernel language has two attributes: type and storage class. The four storage classes are automatic, external, register, and static. Variables are assigned a storage class by placing the corresponding keyword before the type specifier. Examples: auto int a, b, c; extern float f = 7.22; September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
12
CS410 – Software Engineering Lecture #9: C++ Basics III
The Storage Class auto Variables declared within function blocks are by default automatic. Therefore, automatic is the most common of the four storage classes. Automatic variables can be acted on within the scope of the enclosing block. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
13
The Storage Class extern
If we want to transmit information across blocks and functions, we can use external variables. When a variable is declared outside a function at the file level, storage is assigned to it permanently, and its storage class keyword is extern. Such a variable is considered to be global to all functions declared after it. The keyword extern is used to tell the compiler, “Look for it elsewhere, either in this file or in another one.” September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
14
The Storage Class register
The storage class register tells the compiler that the associated variable should be stored in high-speed memory registers. This is not always possible. Increases time efficiency of manipulating this variable. Optimizing compilers assign register storage classes by themselves. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
15
The Storage Class static
Static variables retain their previous value when their block is re-entered. Static functions are visible only within the file in which they are defined. Therefore, the static storage class provides a privacy mechanism that is very important for program modularity. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
16
The Operators new and delete
The unary operators new and delete are available to manipulate free store. They are more convenient than the C functions malloc(), calloc(), and free(). Free store is a system-provided memory pool for objects whose lifetime is directly managed by the programmer. This adds responsibility to the programmer and can easily lead to problems such as memory leaks. On the other hand, manipulating free store is an efficient and flexible way to handle data structures such as trees and lists. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
17
The Operators new and delete
The programmer creates an object using new, and destroys the object using delete. The operator new is typically used in the following forms: new type-name new type-name initializer new type-name [expression] In each case, there are at least two effects: An appropriate amount of store is allocated from free store to contain the named type. The base address of the object is returned as the value of the new expression. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
18
The Operators new and delete
Example: … int *p, *q; p = new int(5); q = new int[10]; In this code, the pointer variable p is assigned the address of the store obtained, The location pointed at by p is initialized to the value 5, the pointer variable q is assigned the base address of an int array of size 10. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
19
The Operators new and delete
Notice the following things: When memory is unavailable, the operator new can either throw a bad_alloc exception or return the value 0. If no initializer is provided, the content of the allocated memory is undefined. Arrays cannot be initialized using the new operator. Objects created by the new operator always need to be destroyed by the delete operator as soon as they are not used by the program any more. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
20
The Operators new and delete
The operator delete destroys an object created by new. This returns its allocated storage to free store for reuse. The operator delete is used in the following forms: delete expression delete [] expression The first form is used when the corresponding new expression has not allocated an array. The second form (empty brackets) is used when the original allocation was an array. The return type of delete is void (no return value). September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
21
The Operators new and delete
Example: Dynamic allocation of an array int main() { int *data; int size; cout << “\nEnter array size: “; cin >> size; assert(size > 0); data = new int[size]; assert(data != 0); for (int j = 0; j < size; j++) cout << (data[j] = j) << ‘\n’; delete [] data; return 0; } Starting the program: Enter array size: 4 1 2 3 September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
22
The Scope Resolution Operator
The concept of classes adds new scope rules to those of the kernel language. You remember that one point of classes is to provide an encapsulation technique. It makes sense that all names declared within a class be treated within their own scope as distinct from external names, function names, and other class names. This creates the need for the scope resolution operator. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
23
The Scope Resolution Operator
The scope resolution operator is the highest-precedence operator in the C++ language. It comes in two forms: ::j (unary operator – refers to external scope) MyClass::j (binary operator – refers to class scope) Its unary form is used to access a name that has external scope and has been hidden by local or class scope. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
24
The Scope Resolution Operator
Example: int count = 0; void how_many(double w[], double x, int &count) { for (int i = 0; i < N; i++) count += (w[i] == x); // local count ++ ::count; // global count tracks calls } September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
25
The Scope Resolution Operator
To better understand this program fragment, we change the parameter int &count to int &cnt: int count = 0; void how_many(double w[], double x, int &cnt) { for (int i = 0; i < N; i++) cnt += (w[i] == x); // local count ++count; // global count tracks calls } September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
26
The Scope Resolution Operator
Binary scope resolution is used to clarify names that are reused within classes. For example, we need scope resolution to define member functions: class Student { public: void PrintName(); private: string studentName; }; void Student::PrintName() { cout << studentName; } September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
27
CS410 – Software Engineering Lecture #9: C++ Basics III
Nested Classes Like blocks and namespaces, classes are scopes and can nest. Nesting allows local hiding of names and local allocation of resources. This is often desirable when a class is needed as part of the implementation of a larger construct. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
28
CS410 – Software Engineering Lecture #9: C++ Basics III
Nested Classes Example: char c; // external scope ::c class X // outer class declaration X:: { public: char c; // X::c class Y // inner class declaration X::Y:: void foo(char e) { X t; ::c = t.X::c = c = e; } private: char c; // X::Y::c }; t.X::c is the same as t.c September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
29
static and const Members
Using the modifier static in declaring a data member means that the data member is independent of any given class variable. The data member is part of the class but separate from any single class object. You remember that nonstatic data members are created for each instance of the class. Using static data allows class data to be scoped to the class but still require only one object for its storage. Without static data members, data required by all instances of a class would have to be global. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
30
static and const Members
Since static members are independent of a particular instance, they can be accessed in the form class-name :: identifier Example: class Point { public: static int how_many; }; Point::how_many = 0; … ++Point::how_many; September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
31
static and const Members
A static member function has the modifier static precede the return type inside the class declaration. Example: class Foo { static int foo_function(); }; int Foo::foo_function() … } September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
32
static and const Members
A data member declared with the const modifier cannot be modified after initialization. syntactically, a const member function has the modifier follow the argument list inside the class declaration. Example: class Foo { int foo_function() const; }; int Foo::foo_function() const {} September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
33
static and const Members
The const and static member function implementation can be understood terms of this pointer access. An ordinary member function is invoked as x.fcn(i, j, k). It has an explicit argument list i, j, k and an implicit argument list that includes the members of x (accessible through the this pointer). A static member function does not get the implicit arguments. A const member function cannot modify its implicit arguments. September 29, 2016 CS410 – Software Engineering Lecture #9: C++ Basics III
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.