can you help me to answer these questions with example Chapter 7 - Vectors Do yo
ID: 3843783 • Letter: C
Question
can you help me to answer these questions with example
Chapter 7 - Vectors Do you know how to define an STL Vector, how to populate and access its elements?
Chapter 9 - Pointers Do you know how to dynamically allocate and release memory?
Do you know how to access a value using a pointer variable?
Do you know how to pass pointers to functions and return them from functions?
Do you understand how pointers relate to arrays?
Chapter 10 - C-Strings and String Objects How are they similar?
How are they different?
The character testing functions (isdigit, isalpha, islower, isupper, isspace, etc)
The character conversion functions (tolower, toupper) c-string library functions and string object methods
Chapter 11 - Structures
How to define a structure
How to access a structure variable's members Arrays of structures and array as a member of a structure.
Chapter 13 - Object-oriented programming
How to define a class and its members
What is the difference between private and public members of a class in terms of accessibility
What members are accessible within the class implementation only and which ones are accessible through the objects of that class
inline method definition vs defining methods outside the class definition
What is the difference between a class and an object?
Can you implement a class from a UML diagram?
Explanation / Answer
1) We can define the vector as below
std::vector<int> vec;
//populating values
vec.assign(5,10) //this will assign 10 to 5 ints
//accessing elements
std::vector<int>::iterator i;
i=vec.begin()+1;
2) int *p = new int(5) //using new keyword we are asking operating system to dynamically reserve some memory space and if is able to fulfil the request , returns the address of that memory.
delete p; //here we are returning the memory allocated to pointer back to operating system.
4) We can define structure as below
struct A{
char a;
int b;
.....
}a;
to access its members we use (.) member access operator
like in main function
int main()
{
struct A a1;
strcpy(a1.a,"X");
return 0;
}
5) We can define class and its members as below
class A{
int a;
double b;
}
private members are not accessible outside class and only its object can access it.
private members ate accessible within class implementation only.
class is a wrapper of related fields and their behaviour whereas object is an instance of that class using which we can access data members and functions of the class.
method defined outside class are just declared inside class and defined outside class where inline method are defined within the class.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.