1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include<iostream>
#include<fstream>
#include"file.h"
#include<string>
#include<sstream>
#include"Vector.h"
using namespace std;
int get_file_size(ifstream& in);
void output(int& choice);
int month_input();
void specific_month(const int length,Vector<ex> Tx,int user_month,ex E);
int main()
{
ifstream in;
//finidng file size
const int length=get_file_size(in);
Vector<ex>Tx(length);
int day,month,year,shares;
double price;
string code,activity,line;
int choice, user_month;
cout<<"Helloo0"<<endl;
in.open("share-data.txt");
ex E;
for(int i=0;i<length;i++)
{
getline(in,line,'/');
stringstream(line)>>day;
getline(in,line,'/');
stringstream(line)>>month;
getline(in,line,',');
stringstream(line)>>year;
getline(in,line,',');
stringstream(line)>>code;
getline(in,line,',');
stringstream(line)>>activity;
getline(in,line,',');
stringstream(line)>>shares;
getline(in,line);
stringstream(line)>>price;
E.set_all(day,month,year,code,activity,shares,price);
cout<<i<<endl;
Tx.insert(E);
}
output(choice);
if(choice==2)
user_month=month_input();
else
{
cout<<"Thanks for using the program.Bye-Bye\n";
system("pause");
return -1;
}
specific_month(length,Tx,user_month,E);
in.close();
system("pause");
return 0;
}
int get_file_size(ifstream& in)
{
in.open("share-data.txt");
int temp;
int size=0;
while(!in.eof())
{
in.ignore(100,'\n');
in>>temp;
size++;
}
in.close();
return size;
cout<<"Size of the file is: "<<size<<endl;
}
void output(int& choice)
{
cout<<"1. Total capital gain of the year\n";
cout<<"2. Total shares bought for the given month\n";
cout<<"3. Exit the program\n";
cout<<"Please enter your choice: ";
cin>>choice;
while(choice<1 || choice>3)
{
cout<<"\nERROR:Invalid choice entered "<<endl;
cout<<"Please enter your choice(1/2/3): ";
cin>>choice;
}
cout<<endl;
}
int month_input()
{
int user_month;
cout<<"Please choose the month you want to know shares bought and amount spend\n";
cout<<"Month Number\n";
cout<<"January 1 \n";
cout<<"Febrauary 2 \n";
cout<<"March 3 \n";
cout<<"April 4 \n";
cout<<"May 5 \n";
cout<<"June 6 \n";
cout<<"July 7 \n";
cout<<"August 8 \n";
cout<<"September 9 \n";
cout<<"October 10 \n";
cout<<"November 11 \n";
cout<<"Decemebr 12 \n";
cout<<"\nPlease enter the month number: ";
cin>>user_month;
while(user_month<1||user_month>12)
{
cout<<"ERROR: Invalid month number!!\n";
cout<<"Please enter the month number again: ";
cin>>user_month;
}
cout<<endl;
return user_month;
}
void specific_month(const int length,Vector<ex> Tx,int user_month,ex E)
{
int month_shares=0;
double month_spent=0;
bool found=false;
for(int i=0;i<length;i++)
{
if(user_month==Tx.retrieve(i,E).date1.get_month() && Tx.retrieve(i,E).get_activity()=="buy")
{
month_shares+=Tx.retrieve(i,E).get_share();
month_spent+=Tx.retrieve(i,E).get_price();
found=true;
}
}
if(found)
{
cout<<"Total share bought for the month "<<user_month<<" is "<<month_shares<<" shares"<<endl;
cout<<"Amount spend for the month "<<user_month<<" $ "<<month_spent<<endl;
}
else
cout<<"No such activites"<<endl;
}
|