0
매월과 주제별로 판매 된 책의 합계를 찾으려고합니다. 이것은 내가 지금까지 가지고있는 것이다. 함수 매개 변수를 변경하거나 함수를 호출하는 방법을 잘 모르겠습니다. 내가 본, 함수를 호출하기위한 매개 변수가 잘못되었습니다. 결과는 또한 테이블의 하단과 우측에 표시되어야합니다.두 번째 배열을 사용하여 전체, 높음 및 낮음을 계산하십시오.
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
typedef int Sales[108];
int sales[6][12];
static const int rows = 12;
static const int cols = 6;
int findhighestmath(int[][6], int);
int findhighestcs(int[][6], int);
int findhighestphy(int[][6], int);
int findlowestmath(int[][6], int);
int total(int[][6], int);
void descendmonth(int[][6], int);
void descendsubject(int[][6], int);
int searching(int[][6], int, int);
int totalmath(int[][6], int);
int main()
{
ifstream inFile;
int sales[12][6];
int numberofbooks = 0, sum = 0, highestmath = 0, math = 0, highestcs= 0,cs = 0;
int totalbooks = 0, found, TotalMath = 0, TotalCS = 0, highestphy;
int overalltotal = 0, highest = 0, lowest = 0;
string months;
string subject;
string Month[12] = { "January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December" };
string category[6] = { "Math", "CS", "Phy", "Chem", "Bio", "Geo" };
//Used for finding total books sold
inFile.open("sale.dat");
while (!inFile.eof())
{
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 6; j++)
{
sales[i][j] = 0;
inFile >> sales[i][j];
}
cout << endl;
}
}
inFile.close();
//Totals up all books
for (int k = 0; k < 12; k++)
{
for (int l = 0; l < 6; l++)
{
sum = sum + sales[k][l];
}
}
numberofbooks = sum;
cout << setw(40) << "Book Sale Analysis" << endl;
cout << setw(40) << "The book store sold a total of " << numberofbooks << " books."
<< endl;
cout << endl;
cout << setw(7) << "Month" << setw(7) << "Math" << setw(7) << "CS" << setw(7) << "Phy" << setw(7) << "Chem"
<< setw(7) << "Bio" << setw(7) << "Geo" << setw(9) << "Total" << setw(7)
<< "High" << setw(7) << "Low" << endl;
//Used for displaying a table of books sold
inFile.open("sale.dat");
while (!inFile.eof())
{
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 6; j++)
{
sales[i][j] = 0;
inFile >> sales[i][j];
cout << setw(7) << sales[i][j] << " ";
}
cout << endl;
}
}
inFile.close();
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 6; j++)
{
math = math + sales[i][j];
}
}
//Total, high, and low outputs for subjects
cout << endl;
TotalMath = totalmath(sales, math);
cout << "Total" << setw(5) << TotalMath <<endl;
highestmath = findhighestmath(sales, math);
cout << "High" << setw(5) << highestmath;
highestcs = findhighestcs(sales, cs);
cout << setw(5) << highestcs << endl;
highestphy = findhighestphy(sales, numberofbooks);
cout << setw(5) << highestphy;
lowest = findlowestmath(sales, math);
cout << "Low" << setw(5) << lowest << endl;
//Sorted analysis
cout << endl;
cout << "Sorting month in ascending order of total sale" << endl;
cout << endl;
cout << "Sorting book category in ascending order of total sale" << endl;
//Search month and book sales using binary search
found = searching(sales, numberofbooks, totalbooks);
cout << months << endl;
cout << subject << endl;
cout << "The total sale is " << found << endl;
return 0;
}
//Function finds highest sale value for math
int findhighestmath(int arr[][6], int b)
{
int highestsale = arr[0][0];
for (int i = 0; i < b; i++)
{
for (int j = 0; j<b; j++)
{
if (arr[i][j]>highestsale)
{
arr[i][j];
highestsale = arr[i][j];
}
}
}
return highestsale;
}
int findhighestcs(int arr[][6], int b)
{
int highestsale = 0;
for (int i = 0; i < b; i++)
{
for (int j = 0; j < b; j++)
{
if (arr[i][j]>highestsale)
{
arr[i][j];
highestsale = arr[i][j];
}
}
}
return highestsale;
}
int findhighestphy(int arr[][6], int b)
{
int highestsale = 0;
for (int i = 0; i < b; i++)
{
for (int j = 0; j < b; j++)
{
if (arr[i][j]>highestsale)
{
arr[i][j];
highestsale = arr[i][j];
}
}
}
return highestsale;
}
//Function finds lowest sale value
int findlowestmath(int arr[][6], int b)
{
int lowestsale = 0;
for (int i = 0; i < b; i++)
{
for (int j = 0; j < b; j++)
{
if (arr[i][j] < lowestsale)
{
arr[i][j];
lowestsale = arr[i][j];
}
}
}
return lowestsale;
}
int totalmath(int arr[][6], int total)
{
for (int row = 0; row < 12; row++)
{
for (int col = 0; col < 1; col++)
{
arr[row][col];
total = arr[row][col];
}
}
return total;
}
시도해 보셨습니까? ** cout << ''; ** –
시도해 봤어, 고마워! 나 또한 아래쪽에 몇 가지 추가 코드를 없앴습니다. – brightthunder