Complete the Missing Functions - Part 1

  • Status: Closed
  • Hadiah: $10
  • Penyertaan diterima: 1
  • Pemenang: rayktrz

Keterangan Peraduan

Compilation code : g++ -std=c++11 -Wall -Werror *.cpp

Deliverables : Complete solution zipped with [url removed, login to view]

The first working solution will be the winner
The winner will be awarded the Part 2

The contestant has to complete the following functions

[url removed, login to view] : Line 50
--
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
float WSUStudent::getCumulativeGPA() const
{
float result = 0.0f;

// Todo calculate the cumulative GPA by averaging
// the grades obtained from the student's enrollments

return result;
}

[url removed, login to view] : Line 50
--
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
float WSUStudent::getCumulativeGPA() const
{
float result = 0.0f;

// Todo calculate the cumulative GPA by averaging
// the grades obtained from the student's enrollments

return result;
}

----

[url removed, login to view] : Line 140
--
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void WSUCourse::removeCourse(std::string identifier)
{
auto course = WSUCourse::getCourseWithIdentifier(identifier);

if(nullptr != course)
{
// Delete all enrollments involving the course
auto enrollments = course->getEnrollments();
for(auto it = [url removed, login to view]();
it != [url removed, login to view]();
++it)
{
delete WSUEnrollment::findEnrollment(
(*it)->getStudent(), (*it)->getCourse());
}

// Todo: (What should we do with m_description? If we delete
// it, there might be other courses that will be left with a
// pointer to deleted memory. But, if we don't delete it and
// there are no other courses with the same description, we
// will have a leak!
// DO SOMETHING WITH m_description

[url removed, login to view](course);
delete course;
}
}

===

Other information :

====

Make sure you can compile and execute the files in the contest before you start adding or modifying anything. Compile the project by cd-ing to the folder where you uncompressed and placed the assignment files and executing the following command:

g++ -std=c++11 -Wall -Werror *.cpp

The default name of the executable program created by the compiler is a.out. You can execute the compiled program by typing ./[url removed, login to view] at the command prompt. The leading ./ is required because the current directory is not (and should not be) in the search path the shell uses to find executable programs.

The purpose of this homework is to encourage uderstanding of manual memory management difficulties:

1) Contestant understands why rules for deleting memory are complcated when multiple pointers to the the same memory exist.
2) Contestant understands how and why to use std::shared_ptr

Part 1) Locate the // Todo: comment in the version of [url removed, login to view] provided in the .zip file attached to this contest. Understand why it isn't so simple to just delete memory refernced by m_description if descriptions can be shared among multiple WSUCourse instances and possibly other places as well.

Part 2) Modify WSUCourse.h, [url removed, login to view] and [url removed, login to view] to use std::shared_ptr as appropriate to make sure descriptions are not deleted while any pointer to the description exists but are deleted after the last pointer to the description ceases to exist.

Good Luck

Kemahiran-kemahiran Cadangan

Maklum balas Majikan

“Great freelancer, right as I thought!! I\'ll probably hiring him for related work! Thank You!!”

Gambar Profil VeteranLK, Sri Lanka.

Penyertaan teratas dari peraduan ini

Lihat Penyertaan Lain

Papan Penerangan Awam

  • idleswell
    idleswell
    • 2 tahun yang lalu

    Any programmer who would accept this work for US$10 would have to be incompetent! #increaseprize

    • 2 tahun yang lalu
    1. abdroid
      abdroid
      • 2 tahun yang lalu

      +1

      • 2 tahun yang lalu
    2. dollshell22
      dollshell22
      • 2 tahun yang lalu

      1000% right

      • 2 tahun yang lalu
  • rayktrz
    rayktrz
    • 2 tahun yang lalu

    The std::shared_ptr exercise is good for the $10 - any current c++ programmer should be able to do this! But if you want the cummulativeGPA done as well then you need to include some detail from an earlier homework (adding grades) and #increaseprize

    • 2 tahun yang lalu
    1. VeteranLK
      Pemegang Peraduan
      • 2 tahun yang lalu

      Will be provided

      • 2 tahun yang lalu
  • SahibYar
    SahibYar
    • 2 tahun yang lalu

    prize is low. #increaseprize

    • 2 tahun yang lalu
  • idleswell
    idleswell
    • 2 tahun yang lalu

    #increaseprize

    • 2 tahun yang lalu
  • MatiasPereyraArg
    MatiasPereyraArg
    • 2 tahun yang lalu

    Certainly, it is a bit more complex than $10
    #increaseprize

    • 2 tahun yang lalu
  • zabolotniipavel
    zabolotniipavel
    • 2 tahun yang lalu

    Hi. I would recommend you to post your work as a project, not as a contest.

    • 2 tahun yang lalu
  • mahershahmeer
    mahershahmeer
    • 2 tahun yang lalu

    #increaseprize

    • 2 tahun yang lalu
  • mahershahmeer
    mahershahmeer
    • 2 tahun yang lalu

    $10 isn't enough. Post your Project as $30 at least.

    • 2 tahun yang lalu

Tunjukkan lebih banyak komen

Bagaimana mula dengan peraduan

  • Papar peraduan anda

    Papar Peraduan Anda Cepat dan senang

  • Dapatkan bertan-tan penyertaan

    Dapatkan Bertan-tan Penyertaan Dari seluruh dunia

  • Anugerahkan penyertaan terbaik

    Anugerahkan penyertaan terbaik Muat turun fail-fail - Senang!

Papar Peraduan Sekarang atau Sertai kami Hari Ini!