can anybody answer these questions for me? Chapter 7 - Vectors Do you know how t
ID: 3843730 • Letter: C
Question
can anybody answer these questions for me?
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
Chapter 7 - Vectors Do you know how to define an STL Vector, how to populate and access its elements?
Answer :
vector<int> intVec;
intVec.push_back(3);
intVec.push_back(2);
intVec.push_back(1);
for(int x=0; x<intVec.size(); x++)
{
cout<<intVec[x]<<" ";
//outputs 3 2 1
}
Chapter 9 - Pointers Do you know how to dynamically allocate and release memory?
Answer :
// Pointer initialized with null
double* doublePTR = NULL;
// Request memory for the variable
doublePTR = new double;
// Store value at allocated address
*doublePTR = 29494.99;
//outputs the value of pointer
cout << "Value of doublePTR : " << *doublePTR << endl;
// free up the memory.
delete doublePTR;
Do you know how to access a value using a pointer variable?
Answer: in the above example *doublePTR is used to access the value
Do you know how to pass pointers to functions and return them from functions?
Answer:
//pass pointer to functions
setInput( &input );
//return them from functions
*input=33;
Do you understand how pointers relate to arrays?
Answer:
float arr[5]={1,2,3,4,5};
float *ptr;
cout << "Displaying values using arrays: " << endl;
for (int i = 0; i < 5; ++i)
{
cout << "arr[" << i << "] = " << arr[i] << endl;
}
// ptr = &arr[0]
ptr = arr;
cout<<" Displaying values using pointers: "<< endl;
for (int i = 0; i < 5; ++i)
{
cout << "ptr + " << i << " = "<< *(ptr + i) << endl;
}
Note: For the Remaining question please post as different question
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.