Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume you have a company X that has 5 shareholders. Write a program that allows

ID: 3532899 • Letter: A

Question

Assume you have a company X that has 5 shareholders. Write a program that allows the user to enter the last

names of shareholders, their share amounts. The program should then output each shareholders name,

his/her share amount, and the percentage of his/her share of the companys capital. Your program should

also output the name of the shareholder with the largest share.

Your program should have three arrays: names, shares, and sharesPercentage, of size 5.

Your program should also have at least the following functions:

1. getInputs: it takes names and shares arrays as parameters and populates them with inputs from the

user.

2. computeSharesTotalAmount: It takes shares array as a parameter and returns the total amount of

shares to the caller (i.e., the main function).

3. computeSharesPercentage: It takes sharesPercentage array as a parameter and populates it with the

percentage of share of the capital for each shareholder.

4. getShareholderWithLargestShare: It takes names and shares arrays as parameters and returns the

name of the person with the largest share.

5. outputResults: It takes names and shares arrays, total shares amount, and the name of shareholder

with the largest share. It then outputs the results to the screen.

A sample output is:

Shareholder Share Amount % of Total Votes

Alex 100000 10.00

John 250000 25.00

Peterson 50000 05.00

Sara 325000 32.50

Tiffany 275000 27.50

Total 1000000

The shareholder with the largest share amount is Sara.

Explanation / Answer

#include<stdio.h>
#include<iostream.h>
#include<conio.h>

void getInput(char &name[][], char &share[]){

for(int i=0;i<5;i++){
count<<" Enter Name of share holder : ";
gets(name[i]);
count<<" Enter Share of share holder : ";
cin>>share[i];
}

}


int computeSharesTotalAmount(int *share){

int sum=0;
for(int i=0;i<5;i++)
sum = sum + share[i];

return sum;

}


void computeSharePercentage(int *share,float *sharePercentage){

for(int i=0;i<5;i++)
sharePercentage[i]=(share[i]/computeShareTotalAmount(share))*100;


}


char *getShareholderWithLargestSHare(char **names,int *share){

int largest = -1;
int sh=share[0];

for(int i=0;i<5;i++)
{
if(share[i]>sh){
sh = share[i];
largest = i;
}
}

return name[i];

}

void outputResults(char **name,int *share, float *sharePercentage){

cout<<" Share Holder Share Amount % of Total Votes ";
for(int i=0;i<5;i++){

puts(name[i]);
cout<<" "<<share[i]<<" "<<sharePercentage[i]<<endl;

}

}

void main(){

char name[5][25];
int share[5];
float sharePercentage [5];

getInputs(name,share);

computeSharesTotalAmount(share);

computeSharePercentage(share,sharePercentage);

getShareholderWithLargestSHare(names,share);

outputResults(name,share,sharePercentage);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote