Professional Documents
Culture Documents
Page 1/4
Explain
3/(logn) + 5n/(logn) + 2/n < Cn/logn for every integer n > n0
d. n (2i2 + 9) is O( n3 )
Explain
n (2i2 + 9)< n (2i2 + 9) di = 2n3/3 + 9n < Cn3 for every integer n > n0
Problem 3: (20pts)
2. (10pts) Write the C++ code to perform the following operations of the deque Q1:
insertFirst(5), insertLast(2), insertLast(7), insertFirst(3), removeFirst(), removeLast(),
insertLast(1), removeFirst(), removeLast().
Q1.push_front(5);
Q1.push_back(2);
Q1.push_back(7);
Q1.push_front(3);
Q1.pop_front();
Q1.pop_back();
Q1.push_back(1);
Q1.pop_front();
Q1.pop_back();
Page 2/4
Contact_phone_number
2. (5pts) Write C++ code for a constructor of the class Contacts to initialize a new variable of
Contacts with the default information as below:
Contact _name = “NO NAME”
Contact _email = “NO EMAIL”
Contact _phone_number = 0
Books::Contacts()
{
Contact_name = "NO NAME";
Contact_email = "NO EMAIL";
Contact_phone_number = 0;
}
3. (5pts) Write C++ code for a constructor of the class Contacts to initialize a new variable of
Contacts with the information of name, email, and phone number.
Books:: Contacts(string new_name, string new_email, unsigned int new_phone_number)
{
Contact_name = new_name;
Contact_email = new_email;
Contact_phone_number = new_phone_number;
4. (5pts) Write an operator overloading of the class Contacts that compares two contacts and
return true if two contacts have the same phone number.
bool Contacts::operator==(Contacts a)
{
return (Contact_phone_number == a. Contact_phone_number);
}
Page 3/4
Problem 5: (20pts) Give the C++ program below:
#include <iostream>
#include <list>
using namespace std;
void main() {
list <char> L1;
list <char>::iterator p;
1. (10pts) Write C+ code to push the following characters into the list L1: ‘s’, ‘t’, ‘u’, ‘d’,
‘e’, ‘n’, ‘t’.
L1.push_back('s');
L1.push_back('t');
L1.push_ back ('u');
L1.push_ back ('d');
L1.push_back('e');
L1.push_ back ('n');
L1.push_ back ('t');
2. (5pts) Write C++ instructions to insert the character ‘z’ at the position of the character ‘u’
in the list L1.
p=L1.begin();
p++;
p++;
L1.insert(p, ‘z’);
3. (5pts) Write C++ code to show all members of the list L! on the screen by using the
Iterator p.
for (p = L1.begin( ); p != L1.end( ); p++ )
cout << " " << *Iter;
Lecturer
Page 4/4