2. Define a new "findDegreesByYearAndSubject" function that accepts 4 parameters: o An array of "Degree" object pointers (not objects) o Array's length o Search year o Search subject It will return a vector of Degree object pointers containing only pointers to the matched Degree objects in the given array. It will return an empty vector if there is no match found. Show how this function is being called and returning proper values.

LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
5th Edition
ISBN:9781337569798
Author:ECKERT
Publisher:ECKERT
Chapter7: Working With The Bash Shell
Section: Chapter Questions
Problem 7DE
icon
Related questions
Question

PLease! In c++

Important 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.
prior_midterm_cpp_as_practice (1 X
O File | C:/Users/myatk/Downloads/prior_midterm_cpp_as_practice%20(1).pdf
prior_midterm_cpp_as_practice (1).pdf
2 / 3
125%
+
-
- 1 -
2. Define a new "findDegreesByYearAndSubject" function that accepts 4
parameters:
o An
array
of "Degree" object pointers (not objects)
o Array's length
Search year
Search subject
It will return a vector of Degree object pointers containing only pointers to
the matched Degree objects in the given array.
It will return an empty vector if there is no match found.
Show how this function is being called and returning proper values.
3. Define a new "findLatestDegreesBySubject" function that accepts 3
parameters:
1:33 PM
Type here to search
2/16/2021
...
II
Transcribed Image Text:prior_midterm_cpp_as_practice (1 X O File | C:/Users/myatk/Downloads/prior_midterm_cpp_as_practice%20(1).pdf prior_midterm_cpp_as_practice (1).pdf 2 / 3 125% + - - 1 - 2. Define a new "findDegreesByYearAndSubject" function that accepts 4 parameters: o An array of "Degree" object pointers (not objects) o Array's length Search year Search subject It will return a vector of Degree object pointers containing only pointers to the matched Degree objects in the given array. It will return an empty vector if there is no match found. Show how this function is being called and returning proper values. 3. Define a new "findLatestDegreesBySubject" function that accepts 3 parameters: 1:33 PM Type here to search 2/16/2021 ... II
Expert Solution
Step 1: Code

#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(&degrees[i]);

        }

    }

    return return_degree;

}

int main()

{

    Degree *degrees;

    int length;

    cout << "\nEnter 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 year to be search: ";

    cin >> year;

    cout << "Enter 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();

    }

}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:
9781337569798
Author:
ECKERT
Publisher:
CENGAGE L