PLease! In c++
#include <iostream>
#include <vector>
using namespace std;
class Degree
{
int year;
string subject;
public:
Degree(int y, string s)
{
year = y;
subject = s;
}
int getYear()
{
return year;
}
string getSubject()
{
return subject;
}
void setYear(int y)
{
year = y;
}
void setSubject(string s)
{
subject = s;
}
void print()
{
cout << "\n\nYEAR: " << getYear();
cout << "\tSUBJECT: " << getSubject();
}
};
vector<Degree *> findDegreesByYearAndSubject(Degree *degrees, int length, int year, string subject)
{
vector<Degree *> return_degree;
for (int i = 0; i < length; i++)
{
if (degrees[i].getYear() == year && degrees[i].getSubject() == subject)
{
return_degree.push_back(°rees[i]);
}
}
return return_degree;
}
int main()
{
Degree *degrees;
int length;
cout << "\nPlease Enter the size: ";
cin >> length;
degrees = (Degree *)malloc(length * sizeof(Degree));
int year;
string subject;
int i = 0;
while (i < length)
{
cout << "\nEnter the year: ";
cin >> year;
cout << "Enter the subject: ";
cin >> subject;
degrees[i].setYear(year);
degrees[i].setSubject(subject);
++i;
}
cout << "\nEnter the year to be search: ";
cin >> year;
cout << "Enter the subject to be search: ";
cin >> subject;
vector<Degree *> result = findDegreesByYearAndSubject(degrees, length, year, subject);
cout<<"\n\nRESULTS:";
for(int i = 0; i < result.size(); i++){
result[i]->print();
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- In C++, if a member of a class is private, we cannot access it outside the class, but what if the member variable is protected?arrow_forwardA function is not a member of the class, but has access to the private members of the class. This type of function can be used in C++ to operators. Write your answer here.arrow_forwardC++ coding project just need some help getting the code thank you!arrow_forward
- What are the three tasks you must do for classes that include member variables that are pointers?arrow_forwardImportant requirements for all questions: • All data members must be declared as “private” • No global variable is allowed to be declared and used • Methods within the class and the requested functions cannot have “cin” or “cout” but it should make use of parameters and return value instead. • “cin” and “cout” should be done in main() or any testing functions • Make sure that you clearly show how the C++ class, its methods and all the functions are being called at least twice and print out its return value and its results properly.arrow_forwardC++ Code Step 1: Preparation For the moment, "comment out" the following under-construction code: In dynamicarray.h: All function prototypes except the constructors and destructor. Keep the member variables (but we will be replacing them shortly). In dynamicarray.cpp: All function implementations except the constructors and destructor. You should also remove (not just comment out) INITIAL_CAP, and replace it with a hard-coded 10 inside the default constructor. This will also eventually go away. In main: Comment out all the code inside the RunPart1Tests function between the linesbool pass = true; and return pass; • Also in main: Comment out all the code in the main function starting with the "Equality comparison" comment and just before the "return 0;" line. Step 2: Replacing member data and the two constructors You're going to replace the current member data (arr, len, and capacity) with a single vector of integers. Remember that vectors keep track of their own size and capacity, so…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education