#include<iostream> int main(){ int red, *green, *blue; red=27; green=&red; blue=new int; *green=28; int& yellow=*blue; *blue=29; yellow=30; std::cout<< red+(*green)+(*blue)+yellow<<std::endl; delete blue; return 0; }
// myProgram.cpp // compile with // c++ myProgram.cpp -o mP -std=c++11 // execute with // ./mP #include<iostream> class Bag{ private: int capacity; public: Bag(int = 0); void setCapacity(int = 0); int getCapacity(); }; Bag::Bag(int c){ capacity=c; } void Bag::setCapacity(int c){ capacity=c; } int Bag::getCapacity(){ capacity += 4; return capacity; } int main(){ Bag b; int totalSum=7; for(int i=0;i<3;++i){ totalSum += b.getCapacity(); } std::cout<<totalSum<<std::endl; return 0; }
#include<iostream> class Frog{ public: Frog(); ~Frog(); }; Frog::Frog(){ std::cout<<"AA"; } Frog::~Frog(){ std::cout<<"AAA"; } int main(){ Frog x; Frog* y; Frog* z; y=new Frog; for(long i = 0;i < 36;++i){ if( ((i > 5) && (i < 8)) || ((i > 17) && (i < 21)) ){ z = new Frog; } } Frog q; std::cout<<"\n"; return 0; }
Important notice: In this problem you will be asked to declare a class and implement only few of its methods. Do not implement all of the methods. You would spend a lot of time doing so and you will not earn extra credit for that!
You must use the keyword const
whenever possible.
The class University
should have the private attribute allDepartments
which is the pointer to the head of a list. Each list node should contain the attribute nameOfDepartment
of type std::string
and a pointer to another list that contains courses in the department.
The public methods should include: addDepartment
that adds a department to the university; addCourseToDepartment
that adds the course to the department (the names of course and department should be supplied as arguments); printAllCoursesFromTheDepartment
that prints all courses in the specified department (the name of the department should be an argument of the method); printAll
that prints all departments and all courses.
In addtion, provide the declarations for the default constructor, copy constructor, move constructor, copy assignment, move assignment and the destructor.
Create implementations for the move constructor, copy assignment, and destructor.
SN
are nodes of a stack. The declaration of the class is
class SN{ public: double content; SN* aNext; };Create a function
mergeTwoSortedStacks
that has the following declaration
SN* mergeTwoSortedStacks(SN* a1, SN* a2)The two arguments of the function
a1
and a2
are the addresses of the top elements of two stacks whose terms are sorted in a non-decreasing order (hence the smallest elements in each of the stacks are on the top). The function should achieve the following outcomes:
a1
and a2
. push
and pop
. You may assume that they are implemented in the usual way. However, if you need any other stack function, then you need to implement it.