Home accounting
Classes | Macros | Functions | Variables
main.cpp File Reference

The main file. Contains the whole program. More...

#include <fstream>
#include <string>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iomanip>

Classes

struct  record
 The struct is used for storage of every element of record. More...
 

Macros

#define ACCOUNTING_OK   0
 
#define ACCOUNTING_IO_ERROR   1
 

Functions

bool ReadLines ()
 The function reads the number of non-empty lines in the input file - that means lines containing records. More...
 
bool BaseStructure (record *budget)
 The function fulfills a table of structures based on the input. More...
 
bool CountLines (int m, record *budget)
 The function checks if given month is present in the input file. Also, it counts number of records containing particular month. More...
 
void MonthStructure (int m, record *budget, record *month)
 The function creates a table of structures that consists of records of particular month. Also, it counts budget. More...
 
void WriteMonth (int month)
 Writing to .html file. More...
 
void Sort (record *month)
 The function sorts the records of particular month by amount of money. More...
 
void WriteByOrder (record *month)
 Writing to .html file. More...
 
void WriteSum (string period)
 Writing to .html file. More...
 
void Hello ()
 Writing to a console. More...
 
string Convert (int number)
 The function converts the integer value to a string type. More...
 
void WriteBegin ()
 Writing to .html file. More...
 
void WriteEnd ()
 Writing to .html file. More...
 
void Zero (int tab[])
 The function clears the given table. More...
 
int main ()
 The main function. Calls other functions, performing the operations. More...
 

Variables

int r = 0
 
int lines = 0
 
string line
 
ifstream file1
 
ofstream file2
 
string input = "Input.csv"
 
string output = "Output.html"
 
string names [] = {"salary", "food", "household", "health", "entertainment", "clothing", "transport", "other"}
 
const int n = (sizeof(names) / sizeof(names[0]))
 
int values_month [n]
 
int values_year [n]
 
int income_month
 
int income_year
 
int expenses_month
 
int expenses_year = 0
 

Detailed Description

The main file. Contains the whole program.

Function Documentation

bool BaseStructure ( record budget)

The function fulfills a table of structures based on the input.

The table of structures contains all records listed in the file.

Returns
1 if file opened successfully, 0 if file open failed.
string Convert ( int  number)

The function converts the integer value to a string type.

Parameters
numberThe integer type to be converted.
Returns
Converted string.
bool CountLines ( int  m,
record budget 
)

The function checks if given month is present in the input file. Also, it counts number of records containing particular month.

Every record of table of structures 'budget' is checked to see if the date is consistent with the checked month. If so, the variable "lines" is incremented.

Parameters
mThe month to be checked.
budgetThe table of structures containing all records.
Returns
1 if the checked month is present in the input file, 0 if not present.
void Hello ( )

Writing to a console.

The function writes the welcome words to the user.

int main ( )

The main function. Calls other functions, performing the operations.

Returns
0 if the program ends with a success.
void MonthStructure ( int  m,
record budget,
record month 
)

The function creates a table of structures that consists of records of particular month. Also, it counts budget.

Every record of table of structures 'budget' is checked to see if the date is consistent with the checked month. If so, it is being rewritten to the table of structures 'month'. Sum of every category is counted, along with total income and expenditure values.

Parameters
mThe month given.
budgetThe table of structures containing all records.
monthThe table of structures containing records of given month.
bool ReadLines ( )

The function reads the number of non-empty lines in the input file - that means lines containing records.

Returns
1 if file opened successfully, 0 if file open failed.
void Sort ( record month)

The function sorts the records of particular month by amount of money.

Sorting process is performed for all records of the month, to be later easily displayed in order, starting from the highest amount, till the smallest amount.

Parameters
monthThe table of structures containing records of given month.
void WriteBegin ( )

Writing to .html file.

The function writes the beginning of the file and sets its parameters.

void WriteByOrder ( record month)

Writing to .html file.

The function writes all the records, previously sorted, to the output file in a separate table.

Parameters
monthThe table of structures containing records of given month.
void WriteEnd ( )

Writing to .html file.

The function closes the output file.

void WriteMonth ( int  month)

Writing to .html file.

The function writes the name of the month that is present in the records.

Parameters
monthThe month to be written.
void WriteSum ( string  period)

Writing to .html file.

The function writes the sums of all categories, to the output file in a separate table.

Parameters
periodThe month given/the whole year.
void Zero ( int  tab[])

The function clears the given table.

The function assigns zeros to every element of table.

Parameters
tab[]The table to be cleared.

Variable Documentation

int expenses_year = 0

storing total finances of month/year

ifstream file1

inputing from file

ofstream file2

output to file

string input = "Input.csv"

input file name

string line

temporary storing of read lines

int lines = 0

rows with record of particular month

const int n = (sizeof(names) / sizeof(names[0]))

number of categories

string names[] = {"salary", "food", "household", "health", "entertainment", "clothing", "transport", "other"}

storing categories' names

string output = "Output.html"

output file name

int r = 0

not-empty rows of input file

int values_month[n]

storing months' categories' values (one by another)

int values_year[n]

storing year's categories' values