Beispiel #1
0
void createReportSummary(vector<Donations> dArray, ofstream &fout)
{
	int total = 0;
	double dArraySize = dArray.size();
	// Accumulators for type totals
	int clothingTotal = 0; int movieTheaterTotal = 0; int miscTotal = 0; int foodTotal = 0;
		int softwareTotal = 0; int theaterTotal = 0; int booksTotal = 0; int musicTotal = 0;
	for(int i = 0; i < dArraySize; i++)
	{
		total += dArray[i].getValue();
		string dType = dArray[i].getCategory();
		// Add the Type's Amount to the appropriate accumulator
		if(dType == "Clothing") clothingTotal += dArray[i].getValue();
		else if(dType == "Movie Theater") movieTheaterTotal += dArray[i].getValue();
		else if(dType == "Misc") miscTotal += dArray[i].getValue();
		else if(dType == "Food Total") foodTotal += dArray[i].getValue();
		else if(dType == "Software") softwareTotal += dArray[i].getValue();
		else if(dType == "Theater") theaterTotal += dArray[i].getValue();
		else if(dType == "Books") booksTotal += dArray[i].getValue();
		else if(dType == "Music") musicTotal += dArray[i].getValue();
	}

	// Write summary report

	fout << right << setw(3) << addCommas(clothingTotal) 
							 << setw(3) << addCommas(movieTheaterTotal)
		                     << setw(3) << addCommas(miscTotal) 
							 << setw(3) << addCommas(foodTotal) 
							 << setw(3) << addCommas(softwareTotal)
		                     << setw(3) << addCommas(theaterTotal) 
							 << setw(3) << addCommas(booksTotal) 
							 << setw(3) << addCommas(musicTotal)
		                     << setw(3) << addCommas(total);
}
void createReportSummary(vector<Scholarship> sArray,  // Pass by value (copy) the entire array
						ofstream &fout)              // Pass the output file by reference
{
	int total = 0;                          // Accumulator for total amount
	int sArraySize = sArray.size();         // Get the size of the array
	// Accumulators for type totals
	int baseTotal = 0, baskTotal = 0, dTotal = 0, fTotal = 0, gTotal = 0, softTotal = 0,
		swimTotal = 0, tTotal = 0, vTotal = 0;
	
	// Loop through the array to accumulate the total amount of all scholarships
	for(int i = 0; i < sArraySize; i++)
	{
		total += sArray[i].getAmount();		// Add the Amount of each scholarship to the total
		string sType = sArray[i].getType(); // Get the type of scholarship for this record
		// Add the Type's Amount to the appropriate accumulator
		if(sType == "Baseball") baseTotal += sArray[i].getAmount();
		else if(sType == "Basketball") baskTotal += sArray[i].getAmount();
		else if(sType == "Diving") dTotal += sArray[i].getAmount();
		else if(sType == "Football") fTotal += sArray[i].getAmount();
		else if(sType == "Golf") gTotal += sArray[i].getAmount();
		else if(sType == "Softball") softTotal += sArray[i].getAmount();
		else if(sType == "Swimming") swimTotal += sArray[i].getAmount();
		else if(sType == "Track") tTotal += sArray[i].getAmount();
		else if(sType == "Volleyball") vTotal += sArray[i].getAmount();
	}

	// Write the summary report output line
	fout << "\n\nSummary Report \n" 
		 <<     "--------------\n"
		 << "        Total Number of Scholarships: " 
		 << right << setw(12) << sArraySize << endl
		 << "        Baseball:                    $ " 
		 << setw(11) << addCommas(baseTotal) << endl
		 << "        Basketball:                    " 
		 << setw(11) << addCommas(baskTotal) << endl
		 << "        Diving:                        " 
		 << setw(11) << addCommas(dTotal) << endl
		 << "        Football:                      " 
		 << setw(11) << addCommas(fTotal) << endl
		 << "        Golf:                          " 
		 << setw(11) << addCommas(gTotal) << endl
		 << "        Softball:                      " 
		 << setw(11) << addCommas(softTotal) << endl
		 << "        Swimming:                      " 
		 << setw(11) << addCommas(swimTotal) << endl
		 << "        Track:                         " 
		 << setw(11) << addCommas(tTotal) << endl
		 << "        Volleyball:                    " 
		 << setw(11) << addCommas(vTotal) << endl
		 << "        ===========================================\n"
		 << "        Total Scholarship Amount:    $ " 
		 << setw(11) << addCommas(total); 
}
Beispiel #3
0
void displaybal(double balance) {

	int negative = 0;
	char left[256];
	char right[256];
	char *token;
	
	if(balance <0 ) {
		negative = 1;
		balance = balance * (-1);
	} else if(balance >=0 ) {
		negative = 0;
	}	
	
	char* buf = nls_ftoa(balance,7,2);
	token = strtok(buf," .");
	int counttok = 0;
	while(token!=NULL){
		switch(counttok) {
			case 0: 
					strcpy(left,token);
					//cout<<"len="<<strlen(left);
					break;
			case 1: 
					strcpy(right,token);
					break;
		}
		token = strtok(NULL," .");
		counttok++;
	}
	int leftlen = strlen(left);
	int rightlen = strlen(right);
	int commacount	= addCommas(left);

	if(negative==1) {	
	
		if ( balance >= 10000000) {
			cout<<"(?,???,???.??\b ) ";
		} else {
			fprintf(stdout,"(");
			displaySpace(16-leftlen-rightlen-1-1-1-1-1-commacount);
			fprintf(stdout,"%s",left);
			fprintf(stdout,".");
			fprintf(stdout,"%s",right);
			fprintf(stdout,") ");
		}
	}
	
	if(negative==0) {
		if ( balance >= 10000000) {
			fprintf(stdout," ?,???,???.??  ");
		} else {
			displaySpace(16-leftlen-rightlen-1-1-1-1-commacount);
			fprintf(stdout,"%s",left);
			fprintf(stdout,".");
			fprintf(stdout,"%s",right);
			displaySpace(2);
		}
	}
}
void writeFile(Scholarship s,    // Pass in by value- no need to change string in main()
			   ofstream &fout)  // Also pass in the output file buffer by ref to write to
{
	static int lineCount = 60;
	if(lineCount == 60) // Ready for next page
	{
		fout << endl; // 
		createReportHeadings(fout);
		lineCount = 0;
	}
	fout << s.getID() <<  right << setw(10) << addCommas(s.getAmount()) 
		 << "    " << left <<  setw(12) << s.getType() 
		 << setw(10) << s.getLength() << right << setw(10) << s.getDate() 
		 << "   " << left <<  setw(15) << s.getFname() << s.getLname() << endl;
	lineCount++;
}
Beispiel #5
0
void displayAmount(struct record* temp) {

	char* sign = temp->sign;
	int rightlen = strlen(temp->rightamountString);
	int leftlen = strlen(temp->leftamountString);
	
	int commacount = 0;
	commacount = addCommas(temp->leftamountString);
	if(!strcmp(sign,"+")) {
	
	
		if ( temp->amount >= 10000000) {
			cout<<" ?,???,???.??  ";
		} else {	
			displaySpace(16-leftlen-rightlen-1-1-1-1-commacount);
			if(strlen(temp->rightamountString)>0) {
				displayLeft(temp->leftamountString);
				fprintf(stdout,".");
				fprintf(stdout,"%s",temp->rightamountString);
			}	
			if(strlen(temp->rightamountString)==0) {
				displayLeft(temp->leftamountString);
			}		
			displaySpace(2);
		}
	}

	if(!strcmp(sign,"-")) {
	
		if ( temp->amount >= 10000000) {
			cout<<"(?,???,???.??\b ) ";
		} else {	
			fprintf(stdout,"(");
			displaySpace(16-leftlen-rightlen-1-1-1-1-1-commacount);
			if(strlen(temp->rightamountString)>0) {
				displayLeft(temp->leftamountString);
				fprintf(stdout,".");
				fprintf(stdout,"%s",temp->rightamountString);
			}
			if(strlen(temp->rightamountString)==0) {
				displayLeft(temp->leftamountString);
			}		
			fprintf(stdout,")");
			displaySpace(1);
		}
	}
}
void milli_to_string(uint16_t v, char* buffer, uint8_t display) {
  char tempBuffer[20];
  int decimals;

  if (display == DISPLAY_MILLI) {
    uitoa(v, tempBuffer, 10);
    addCommas(tempBuffer, buffer);
  } else {
    if (display == DISPLAY_3DECIMALS) {
      decimals = 3;
    } else if (display == DISPLAY_2DECIMALS) {
      decimals = 2;
    } else if (display == DISPLAY_1DECIMALS) {
      decimals = 1;
    }
    uitoa(v % 1000, buffer, 10);
    padLeft(buffer, tempBuffer, decimals, '0');
    tempBuffer[decimals] = '\0';
    uitoa(v / 1000, buffer, 10);
    strcat(buffer, ".");
    strcat(buffer, tempBuffer);
  }
}