задача 4.Печалби от домашното
01. Pointers and References – Homework Exercises
Write C++ code for solving the tasks on the following pages.
Code should compile under the C++03 or the C++11 standard.
Submit your solutions here: https://judge.softuni.bg/Contests/1150/01-Pointers-and-References-Homework
Any code files that are part of the task are provided under the folder Skeleton.
Please follow the exact instructions on uploading the solutions for each task.
Task 4 – Profits
You are given program in an ProfitsMain.cpp, as well as a Company.h and ProfitCalculator.h file, that read info about companies – name, id, revenue and costs, followed by info about profit calculations per company – company id followed by a tax percentage – and generates a report with the profit for each company in the input.
The report must contain exactly as many lines as there are companies, and each line should contain the name of the company on that line in the input, followed by a space, a '=', another space, and an integer value representing the profits of the company, e.g. a line of the output for a company called TheCompany with a profit of 42000 should look like this:
TheCompany = 42000
To generate the report, ProfitsMain.cpp uses a function named getProfitReport from a file named ProfitReport.h. The getProfitReport function receives 3 parameters:
A pointer to the first company in an array of companies
A pointer to the last company (inclusive) in an array of companies
An std::map, which maps company ids to ProfitCalculators
The getProfitReport should use the appropriate ProfitCalculator from the map (i.e. the ProfitCalculator in the entry with a key matching the id of the company) to calculate each company’s profit.
The getProfitReport returns a string, containing the report for the provided companies, calculated through the provided ProfitCalculators, as described above.
Your task is to study the code in ProfitsMain.cpp, then create a file called ProfitReport.h (which ProfitsMain.cpp includes) containing the definition of the getProfitReport function, written in such a way that ProfitsMain.cpp compiles successfully and works as described above.
След, много неуспешни опити, моля някой за съвет как да върна с getProfitReport, тази информация, да кажем че оппечатвам името на "компанията и = " в самата функция, как да върна печалбата, за всяка компания? Референция няма да ми помогне.
Разбира се моят ProfitReport.h, не е верен, много се помъчих, моля знаещите за подсказка! Аз не мога да се справя, без помощ!
ProfitReport.h - https://pastebin.com/5X18x5ZQ
Company.h - https://pastebin.com/sg9znX3U
ProfitsMain.cpp - https://pastebin.com/x3JhFfig
ProfitCalculator.h - https://pastebin.com/cVb1Gfb7
input
acme 424242420 : 43000 1000
softuni_foundation 20140414 : 0 0
itjoro 878968302 : 100 25
end
878968302 0
424242420 10
20140414 30
end
output
acme = 37800
softuni_foundation = 0
itjoro = 75
Като гледам кода в ProfitReport.h общо взето си го направила, само че вместо return на 15-ти ред трябва да изчислиш profit-а и да го добавиш към резултатния стринг. След това продължаваш цикъла със следващата компания.
Използвам темата за да задам следния въпрос (с повишена трудност)
Ако направим profitCalculatorByCompany константен параметър (const) във функцията getProfitReport, защо не можем да достъпим калкулатора на фирмата по индекс (id-то на фирмата)?
(pCompany е пойнтер към Company).
@kolioi - Този въпрос към всички ли е, или само към колегите, които карат тази инстанция на курса? :)
Това е задачка-закачка :) Въпроса е към всички. Аз знам отговора, но нека колегите да помислят малко :)