Design & Implement a C- program that can handle salesmen records of ABC
Company. Each salesman has unique 4-digit id #, name, salary, monthly sale &
commission (commission is computed depending on value of monthly sale). Net
income of a salesman is salary plus commission. Make maximum use of user
defined Functions.
Conditions for calculating commission are as follows:
➢ Commission is 20% of monthly sale, if sale is equal to or greater than 15,000.
➢ Commission is 15% of monthly sale, if sale is equal to or greater than 10,000
and less than 15,000.
➢ Commission is 10% of monthly sale, if sale is equal to or greater than 8,000
and less than 10,000.
➢ Commission is 5% of monthly sale, if sale is equal to or greater than 5,000 and
less than 8,000.
➢ No Commission, if sale is less than 5,000.
�
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int id;
char name[20];
double salary;
double sale;
} Salesman;
void read_record(Salesman* person);
double get_commision(double sale);
double get_net_income(Salesman* person);
void print_record(Salesman* person);
int main()
{
Salesman* records;
int n;
int i;
printf("Enter tha amount of persons in the company: ");
scanf_s("%d", &n);
records = (Salesman*)malloc(n * sizeof(Salesman));
for (i = 0; i < n; i++)
{
read_record(&records[i]);
}
printf("\n\nABC Company\n\n");
for (i = 0; i < n; i++)
{
print_record(&records[i]);
printf("-------------------------\n\n");
}
free(records);
return 0;
}
void read_record(Salesman* person)
{
printf("Enter salesman id: ");
scanf_s("%d", &person->id);
printf("Enter a name: ");
scanf_s("%s", &person->name);
printf("Enter a salary: ");
scanf_s("%lf", &person->salary);
printf("Enter a monthly sale: ");
scanf_s("%lf", &person->sale);
printf("\n");
}
double get_commision(double sale)
{
if (sale >= 15000)
{
return 0.2;
}
if (sale >= 10000)
{
return 0.15;
}
if (sale >= 8000)
{
return 0.1;
}
if (sale >= 5000)
{
return 0.05;
}
return 0;
}
double get_net_income(Salesman* person)
{
double total = person->salary;
total += person->sale * get_commision(person->sale);
return total;
}
void print_record(Salesman* person)
{
double income = get_net_income(person);
printf("ID: %04d\n", person->id);
printf("Name: %s\n", person->name);
printf("Monthly sale: $%.2lf\n", person->sale);
printf("Total income: $%.2lf\n", income);
}
Comments
Leave a comment