2017-03-31 11 views
0

私は各月と対象から販売された書籍の合計を見つけようとしています。これは私がこれまで持っていたものです。関数のパラメータを変更する方法や関数を呼び出す方法がわからない。私は主に知っている、関数を呼び出すためのパラメータが間違っています。結果は、表の下部と右側にも表示されます。2次元配列を使って合計、高値、低値を計算する

#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; 
} 
+0

これを試しましたか? ** cout << ''; ** –

+0

試してみて、ありがとう!私はまた、いくつかの余分なコードを一掃しました – brightthunder

答えて

0

「スペース」を出力する場合は、スペースを出力する必要があります。これは良いスタートです。

cout << ' '; 

あなたはsetwマニピュレータを使用しています。他のマニピュレータと組み合わせることで、かなりの柔軟性が得られます。このサイトをチェックしてください。 http://en.cppreference.com/w/cpp/io/manip/left。 std :: right、std :: leftは何を期待するかを行います。 std :: internalは面白いですが、限られています。上のすべてのサイトで、C++の基礎に関する素晴らしいリファレンスです。

関連する問題