0% found this document useful (0 votes)
2 views

Oop Assignment 1-1

The document contains a C++ program that defines an 'Employee' structure with attributes for name, CINC, and sales data. It includes functions to sort employees based on their total sales over five years and four quarters, and to display their data. The main function gathers input for three employees, sorts them, and displays their information.

Uploaded by

zahraakram51
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Oop Assignment 1-1

The document contains a C++ program that defines an 'Employee' structure with attributes for name, CINC, and sales data. It includes functions to sort employees based on their total sales over five years and four quarters, and to display their data. The main function gathers input for three employees, sorts them, and displays their information.

Uploaded by

zahraakram51
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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;

You might also like