Name: Samavia Zahid
Registration number: FA24b2 -SE-008
Subject: Programming Fundamentals
Assignment number 1
#include <iostream>
#include <string>
using namespace std;
struct Employee {
string name;
int cinc;
int sales[5][4];
};
void sortSales(Employee employees[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int totalSalesI = 0, totalSalesJ = 0;
for (int y = 0; y < 5; y++) {
for (int Q = 0; Q < 4; Q++) {
totalSalesI += employees[i].sales[y][Q];
for (int y = 0; y < 5; y++) {
for (int Q = 0; Q < 4; Q++) {
totalSalesJ += employees[j].sales[y][Q];
if (totalSalesI < totalSalesJ) {
Employee temp = employees[i];
employees[i] = employees[j];
employees[j] = temp;
void displayEmployeeData(Employee employees[], int n) {
for (int i = 0; i < n; i++) {
cout << "\nEmployee Name: " << employees[i].name
<< ", CINC: " << employees[i].cinc << endl;
cout << "Sales data 5 years and 4 quarters:\n";
for (int y = 0; y < 5; y++) {
cout << "Year " << (y + 1) << ": ";
for (int Q = 0; Q < 4; Q++) {
cout << "Q" << (Q + 1) << ": " << employees[i].sales[y][Q] << " ";
cout << endl;
int main() {
Employee employees[3];
for (int i = 0; i < 3; i++) {
cout << "Enter the name of employee " << i + 1 << ": ";
cin >> employees[i].name;
cout << "Enter the CINC of employee " << i + 1 << ": ";
cin >> employees[i].cinc;
for (int y = 0; y < 5; y++) {
for (int Q = 0; Q < 4; Q++) {
cout << "Enter sales for Year " << (y + 1) << ", Quarter " << (Q + 1) << ": ";
cin >> employees[i].sales[y][Q];
sortSales(employees, 3);
displayEmployeeData(employees, 3);
return 0;