该程序实质上是用C ++编写的程序,该程序使用结构数组。您最多读取50条记录,对它们进行排序,然后显示记录。我的排序根本不是问题。它是我的输出。为什么我在输出中得到奇怪的数字和符号。请忽略ofstream。将其从outFile更改为cout,以使自己更轻松。
//Author: Jeffrey Washington
// Project 13
// Date Due: 4-10-19
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
//Structure for record
struct RecordTemplate
{
int itemNumber;
int casesOnHand;
int caseCapacity;
float itemPr;
int monthCreated;
int dayCreated;
int yearCreated;
int monthModified;
int dayModified;
int yearModified;
int minInventory;
char description[20];
};
// Function Prototypes
void bubbleSort(RecordTemplate arrayNumbers[], unsigned short int&);
//Main program
int main()
{
unsigned short int amountOfRecords = 49; // The amount of records items im dealing with.
RecordTemplate record[amountOfRecords]; // Creates 50 item inventory slots.
int counter = 0; // Loop counter
//Input/Output files
ifstream inFile; // Input file
// Opening File and checking to see if it opens.
inFile.open("inventory_data12_2019.txt");
if(!inFile)
{
cout << "File will not open. Please try again." << endl;
return 0;
}
// First part of the output
ofstream outFile;
outFile.open("results.txt");
cout << setw(60) << "Inventory Report" << endl;
cout << setw(70) << "Items Printed in Ascending Order" << endl << endl;
cout << left << setw(11) << "Item" << setw(20) << "Item" << setw(15) << "Cases" << setw(10) << "Stock*" << setw(15) << "Date" << setw(15) << "Date" << setw(20) << "Min" << endl;
cout << left << setw(11) << "Number" << setw(20) << "Description" << setw(15) << "In stock" << setw(10) << "Value" << setw(15) << "Created" << setw(15) << "Modified" << setw(20) << "Inv. Amount" << endl;
//Gathering input
while (inFile >> record[counter].itemNumber)
{
if (counter > amountOfRecords)
break;
else
{
inFile >> record[counter].description >> record[counter].casesOnHand
>> record[counter].caseCapacity >> record[counter].itemPr >> record[counter].monthCreated
>> record[counter].dayCreated >> record[counter].yearCreated >> record[counter].monthModified
>> record[counter].dayModified >> record[counter].yearModified >> record[counter].minInventory;
counter++;
}
}
// Bubble Sort
bubbleSort(record, amountOfRecords);
// Output
int count = 0; // Lounter for outputoop c
while(count < amountOfRecords)
{
if (count > amountOfRecords)
break;
else
{
cout << record[count].itemNumber << " " << record[count].description << " "
<< record[count].caseCapacity << " " << record[count].itemPr << " " << record[count].monthCreated
<< "," << record[count].dayCreated << "," << record[count].yearCreated << " " << record[count].monthModified
<< "," << record[count].dayModified << "," << record[count].yearModified << " " << record[count].minInventory << endl;
count++;
}
}
return 0; // End program
}
//Bubble Sort
void bubbleSort(RecordTemplate arrayNumbers[], unsigned short int &num_elements)
{
bool swap;
RecordTemplate temp;
do
{
swap = false;
for(int t = 0; t < num_elements - 1; t++)
{
if(arrayNumbers[t].itemNumber > arrayNumbers[t + 1].itemNumber)
{
temp = arrayNumbers[t];
arrayNumbers[t] = arrayNumbers[t + 1];
arrayNumbers[t + 1] = temp;
swap = true;
}
}
}
while(swap);
}
链接到输出:numpy.isnan