Question: Design a program to take in divisions of the same company and sort them into North South East and west divisions and sort each of those divisions for the highest quarter and then find the highest of the highest quarters problem :: when finding the highest of the highest quarters it will not sort and i only get an error
My solution: <>
string *names = nullptr;
int *quarter = nullptr;
int *profit = nullptr;
Bussiness *divisions = nullptr;
Bussiness *divisions_2 = nullptr;
Bussiness *divisions_3 = nullptr;
Bussiness *divisions_4 = nullptr;
Bussiness *Highest_quarters = nullptr;
names = new string[4];
profit = new int[4];
quarter = new int[4];
divisions = new Bussiness[4];
divisions_2 = new Bussiness[4];
divisions_3 = new Bussiness[4];
divisions_4 = new Bussiness[4];
Highest_quarters = new Bussiness[4];
for (int x = 0; x < 4; x++) {
if (x == 0) {
cout << "please enter in for the North" << endl;
for (int i = 0; i < 4; i++) {
*(quarter + i) = i;
cout << "please enter in for quarter " << i + 1 << ": ";
cin >> *(profit + i);
*(divisions + i) = Bussiness("North", *(quarter + i), *(profit + i));
}
}
else if (x == 1) {
cout << "Please enter in for the south" << endl;
for (int i = 0; i < 4; i++) {
*(quarter + i) = i;
cout << "please enter in for quarter " << i + 1 << ": ";
cin >> *(profit + i);
*(divisions_2 + i) = Bussiness("South", *(quarter + i), *(profit + i));
}
}
else if (x == 2) {
cout << "Please enter in for the West" << endl;
for (int i = 0; i < 4; i++) {
*(quarter + i) = i;
cout << "please enter in for quarter " << i + 1 << ": ";
cin >> *(profit + i);
*(divisions_3 + i) = Bussiness("West", *(quarter + i), *(profit + i));
}
}
else {
cout << "Please enter in for the East" << endl;
for (int i = 0; i < 4; i++) {
*(quarter + i) = i;
cout << "please enter in for quarter " << i + 1 << ": ";
cin >> *(profit + i);
*(divisions_4 + i) = Bussiness("East", *(quarter + i), *(profit + i));
}
}
}
delete[] profit;
profit = nullptr;
delete[] quarter;
quarter = nullptr;
Bussiness sc;
sc.displayQuarters(divisions, 4);
sc.displayQuarters(divisions_2, 4);
sc.displayQuarters(divisions_3, 4);
sc.displayQuarters(divisions_4, 4);
sc.sort(divisions_2, 4);
sc.sort(divisions, 4);
sc.sort(divisions_3, 4);
sc.sort(divisions_4, 4);
string a = "";
int b = 0;
int c = 0;
for (int x = 0; x < 4; x++) {
string a = "";
int b = 0;
int c = 0;
if (x == 1) {
a = (divisions + 4)->getName();
b = (divisions + 4)->getQuarter();
c = (divisions + 4)->getProfit();
*(Highest_quarters + x) = Bussiness(a, b, c);
}
else if (x == 2) {
a = (divisions_2 + 4)->getName();
b = (divisions_2 + 4)->getQuarter();
c = (divisions_2 + 4)->getProfit();
*(Highest_quarters + x) = Bussiness(a, b, c);
}
else if (x == 3) {
a = (divisions_3 + 4)->getName();
b = (divisions_3 + 4)->getQuarter();
c = (divisions_3 + 4)->getProfit();
*(Highest_quarters + x)= Bussiness(a, b, c);
}
else if (x == 4) {
a = (divisions_4 + 4)->getName();
b = (divisions_4 + 4)->getQuarter();
c = (divisions_4 + 4)->getProfit();
*(Highest_quarters + x) = Bussiness(a, b, c);
}
}
sc.displayQuarters(Highest_quarters, 4);
sc.displayQuarters(divisions, 4);
sc.displayQuarters(divisions_2, 4);
sc.displayQuarters(divisions_3, 4);
sc.displayQuarters(divisions_4, 4);
sc.sort(Highest_quarters, 4);
sc.displayQuarters(Highest_quarters, 4);
delete[] divisions;
divisions = nullptr;
delete[] Highest_quarters;
Highest_quarters = nullptr;
system("pause");
return 0;
}
<>
class Bussiness {
private:
string name;
int quarter;
int profit;
public:
Bussiness() {
name = ' ';
quarter = 0;
profit = 0;
}
Bussiness(string a, int b, int c) {
name = a;
quarter = b;
profit = c;
}
void displayQuarters(Bussiness *, int);
void sort(Bussiness *studentScores, int students);
void sort_array(int *studentScores, int students);
void display_array(int *, int);
string getName() const { return name; }
int getQuarter() const { return quarter; }
int getProfit() const {
return profit;
}
};
<>
void Bussiness::displayQuarters(Bussiness *Divisions, int students) {
for (int i = 0; i < students; i++)
{
cout << (Divisions + i)->getName() << " ";
cout << (Divisions + i)->getQuarter() + 1 << " ";
cout << (Divisions + i)->getProfit() << " ";
cout << endl;
}}
void Bussiness::sort(Bussiness *studentScores, int students) {
Bussiness temp;
bool swap;
do
{
swap = false;
for (int count = 0; count < (students - 1); count++)
{
if ((studentScores + count)->getProfit() >(studentScores + 1 + count)->getProfit())
{
temp = *(studentScores + count);
*(studentScores + count) = *(studentScores + 1 + count);
*(studentScores + 1 + count) = temp;
swap = true;
}
}
} while (swap);}
Aucun commentaire:
Enregistrer un commentaire