Question
A main() function is given below. Based on this function, your task is to write complete code required to run the main() function successfully and
A main() function is given below. Based on this function, your task is to write complete code required to run the main() function successfully and produce the exact output given. You are not allowed to return any memory handler in your code.
For your ease, a file containg main() function is uploaded on the portal.
Remember:
int main() {
IntegerList list1; int number = 12; int i = 1;
while (i <= number) {
1. You cannot change anything in the main() function and should produce the exact output given.
2. If your code will not be able to compile, you will not be awarded more than 50% marks even if you have written the whole code.
3. Submit the screenshot of your output as well. It carries marks.
//making empty default IntegerList of 100 size
list1.insert(i);//inserting elements into list1 by incrementing its indexes like 0 //1,2,3,4 and so on. For eg. 1st time insertion will insert at index 0, //then index 1 and so on
i++; }
cout << "list1 ";
print(list1);
cout << "The number of elements in list1 = " << list1.getCount() << endl;
IntegerList list2(list1, 2, 9);//should copy the elements of list1 from position 2 to 9 cout << "list2 is a copy of list1 from position 2 to 9 ";
print(list2);
cout << "The number of elements in list2 = " << list2.getCount() << endl;
IntegerList list3;
cout << "list3 is a constant IntegerList ";
cout << "The number of elements in list3 = " << list3.getCount() << endl;
list1.clear(); //should set the values of list1 to zeros and its count to zero cout << "After clearing list1 ";
print(list1);
IntegerList list4(10);//should make an empty IntegerList of size 10(passed as a parameter) cout << "list4 is an empty IntegerList of size 10 ";
print(list4);
list4.insert(55); list4.insert(56); list4.insert(57); list4.insert(58);
//inserting elements into list4 //inserting elements into list4 //inserting elements into list4 //inserting elements into list4 cout << "After inserting elements in list4 "; print(list4);
IntegerList list5;
list5 = list2 + list4; //list5 should have both the elements of list2 and list4 cout << "list5 contains both the elements of list2 and list4 ";
print(list5);
list5[0] = list5[0] + 1;//it should give compile time error if list5 is constant
//For eg: const IntegerList list5
cout << "After adding 1 to the elmenent at 0 index of list5 "; print(list5);
cout << "print(list5++); "; print(list5++); //post-increment
cout << "print(++list5) "; print(++list5); //pre-increment cout << "print(--list5) "; print(--list5); //pre-decrement
cout << "print(list5--) "; print(list5--); //post-decrement
cout << "list6 is a copy of list5 ";
IntegerList list6 = list5;//list6 is a copy of list5 print(list6);
cout << "print(list5++) "; print(list5++);
cout << "Comparing list5 and list6 are equal or not? ";
if (list6 == list5) // to compare all the elements of IntegerLists {
cout << "As you can see Both the IntegerLists list5 and list6 are equal "; cout << "list5: ";
print(list5);
cout << "list6: ";
print(list6);
else
{
}
}
cout << "As you can see Both the IntegerLists list5 and list6 are not equal "; cout << "list5: ";
print(list5);
cout << "list6: ";
print(list6);
cout << "list4 after assignment: "; (list4 = list5) = list6; print(list4);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started