C++ Program to calculate the profit sharing ratio


Given with an array of amount invested by multiple person and another array containing the time period for which money is invested by corresponding person and the task is to generate the profit sharing ratio.

What is Profit Sharing Ratio

In a partnership firm, profits and losses are shared between the partners depending upon the capital invested by them in the business. On the basis of that capital investment percentage we calculate the profit sharing ratio which shows the amount of profit which is to be given to each partner of a business.

Formula − Partner 1 = capital invested * time period    

 Partner 2 = capital invested * time period     

Partner 3 = capital invested * time period       

Partner 4 = capital invested * time period .       .      

Person n = capital invested * time period 

Profit Sharing Ratio = Partner 1 : Partner 2: Partner 3

Example

Input-: amount[] = { 1000, 2000, 2000 }
   time[] = { 2, 3, 4 }
Output-: profit sharing ratio 1 : 3 : 4
Input-: amount[] = {5000, 6000, 1000}
   time[] = {6, 6, 12}
Output-: profit sharing ratio 5 : 6 :2

Approach we will be using to solve the given problem

  • Take the input as an array of capital invested by multiple partners and another array for time period for which they have invested the capital
  • Multiply the capital of one partner with his corresponding time period and repeat the same  with other partners
  • Calculate the ratio of multiplied values
  • Display the final result

ALGORITHM

Start
step 1-> declare function to calculate GCD
   int GCD(int arr[], int size)
   declare int i
   Declare int result = arr[0]
   Loop For i = 1 and i < size and i++
      set result = __gcd(arr[i], result)
   End
   return result
step 2-> declare function to calculate profit sharing ratio
   void cal_ratio(int amount[], int time[], int size)
   declare int i, arr[size]
   Loop For i = 0 and i < size and i++
      set arr[i] = amount[i] * time[i]
   End
   declare int ratio = GCD(arr, size)
   Loop For i = 0 and i < size - 1 and i++
      print arr[i] / ratio
   End
   print  arr[i] / ratio
Step 3-> In main()
   declare int amount[] = { 1000, 2000, 2000 }
   declare int time[] = { 2, 3, 4 }
   calculate int size = sizeof(amount) / sizeof(amount[0])
   call cal_ratio(amount, time, size)
Stop

Example

#include <bits/stdc++.h>
using namespace std;
//calculate GCD
int GCD(int arr[], int size) {
    int i;
    int result = arr[0];
    for (i = 1; i < size; i++)
        result = __gcd(arr[i], result);
  return result;
}
//calculate profit sharing ratio
void cal_ratio(int amount[], int time[], int size) {
    int i, arr[size];
    for (i = 0; i < size; i++)
        arr[i] = amount[i] * time[i];
    int ratio = GCD(arr, size);
    for (i = 0; i < size - 1; i++)
        cout << arr[i] / ratio << " : ";
    cout << arr[i] / ratio;
}
int main() {
    int amount[] = { 1000, 2000, 2000 };
    int time[] = { 2, 3, 4 }
    int size = sizeof(amount) / sizeof(amount[0]);
    cout<<"profit sharing ratio ";
    cal_ratio(amount, time, size);
    return 0;
}

Output

profit sharing ratio 1 : 3 : 4

Updated on: 20-Nov-2019

199 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements