Objctivs: Function tmplats, function ovrloading, oprator ovrloading Must be don
ID: 3589124 • Letter: O
Question
Objctivs: Function tmplats, function ovrloading, oprator ovrloading
Must be don in C++ !! do all please
1.Giv an xampl of two ovrloadd functions with diffrnt numbr of paramtrs.
2.Giv an xampl of two ovrloadd functions with sam numbr of paramtrs, but diffrnt paramtr typs.
3.Giv an xampl of two ovrloadd functions with sam numbr of paramtrs, sam paramtr typs, but in diffrnt ordrs.
4. Writ a function tmplat which sarchs for a valu in an STL squnc containr (vctor). Th function tmplat taks a containr and a valu, and should rturn tru if th valu is found and fals othrwis.
5. Ovrload th comparison (==) oprator for th Airplan class blow to compar th modl data mmbr in th function tmplat abov to a spcific valu (i.., Skylark). [Hint1: This comparison is not btwn twoAirplan objcts, but rathr a comparison btwn an objct’s data mmbr and a valu. Hint2: Considr using th compilr to vrify th answr.]
class Airplan {
privat:
string mak; // Cssna, Pipr, tc.
string modl; // Skylark, Cub, tc.
int topSpd;
public:
void stMak(string mk);
void stModl(string mdl);
void stTopSpd(int tspd);
};
6.Dclar a vctor of 10 Airplans (you may assum that a dfault constructor xists and would b usd).
7.Assum th vctor in 6 is now fully populatd with Airplan objcts. Writ a valid function call to th function tmplat dfind in 4, passing in th vctor you cratd.
8.xplain th diffrncs btwn th following two comparison statmnts involving pointrs:
Studnt *p, *q;
// Assum objcts ar constructd and ths pointrs ach point to valid objcts
a. (5 pts) p == q
b. (5 pts) *p == *q
Giv th statmnts to crat on vctor of intgrs and on vctor of strings, and to insrt 3 distinct valus into ach of ths vctors.
Explanation / Answer
1)
Declaration of functions
void draw(int x1, int x2);
void draw(int x1, int x2, int x3);
definition example of the above function.
void draw(int x1, int x2)
{
}
void draw(int x1, int x2, int x3)
{
}
2)
void foo(int x,int y) ; //this takes two argument and parameter types are different ie int
void foo(float x,float y); //this takes two argument and parameter types are different ie float
void foo(char *str,float x); //this takes two argument and parameter types are different ie char * and int
3)
void fo(int x, float y);
void fo(float x, int y);
4)
template <class T>
bool searchContainer(vector<T> vec, T value) {
for (int i = 0; i < vec.size(); i++)
{
if (value == vec[i])
return true;
}
return false;
}
5)
first declare bool Airplan::operator == (Airplan &obj); in class of Airplan and then define it as below.
bool Airplan::operator == (Airplan &obj)
{
if (obj.modl == this->modl)
{
return true;
}
else
return false;
}
6)
vector<Airplan>* vec1 = new vector<Airplan>[10];
7)
Airplan obj;
if (searchContainer<Airplan>(*vec1, obj))
{
cout << "model found " << endl;
}
else
{
cout << "model found " << endl;
}
8 )
a. (5 pts) p == q
above statement compares the address of p and address of q are equal.
b. (5 pts) *p == *q
above statement compares the content of address pointed by p and content of address pointed by q are equal.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.