hi guys so we have a school activity, and we are instructed to make an inventory system. I managed to do the input part of the code however i cannot display the same way the picture below shows:
This is the code of my work:
#include <iostream>
#include <iomanip>
#include <cstring>
#include <windows.h>
#include <cstdlib>
#include <fstream>
using namespace std;
//global declaration
int i;
int j;
const int passctr=3;
struct inventory{
double price;
int stock;
int sold;
int left;
};
struct itemType {
inventory items;
string itemname;
string brand;
};
struct userType{
string name;
string password;
};
int main()
{
//declaration
int prodqty,brandqty;
int prodarr;
int qty;
itemType item[prodqty],display;
userType user;
for(i=0;i<passctr;i++)
{
cout<<"Try no."<<i+1<<endl;
string xpassword="pogisibry";
cout<<"PRODUCT INVENTORY SYSTEM"<<endl;
cout<<"Enter Username: ";
getline(cin,user.name);
cout<<"Enter Password: ";
getline(cin,user.password);
try
{
if(user.password!=xpassword)
{
throw user.password;
}
else
{
cout<<"Welcome user "<<user.name<<"!!!"<<endl;
break;
}
}
catch (string reenter)
{
cout<<"Wrong password!"<<endl
<<"Please re enter!"<<endl;
}
system("pause");
system("cls");
}
if (i==passctr)
{
cout<<"locking inventory system!"<<endl
<<"exiting the program...";
exit(1);
}
cout<<"Enter desired number of products: ";
cin>>prodqty;
for(i=0;i<prodqty;i++)
{
cin.ignore();
cout<<"Product ["<<i+1<<"]: ";
getline(cin,item[i].itemname);
cout<<"How many "<<item[i].itemname<<"? : ";
cin>>brandqty;
cout<<endl;
for(j=0;j<brandqty;j++)
{
cin.ignore();
cout<<item[i].itemname<<"["<<j+1<<"]: ";
getline(cin,item[j].brand);
cout<<endl;
cout<<"Price: Php ";
cin>>item[j].items.price;
cout<<"Stock: ";
cin>>item[j].items.stock;
cout<<"Sold: ";
cin>>item[j].items.sold;
}
}
cout<<"PROD NO. PRODUCT NAME PRICE STOCK SOLD LEFT"<<endl;
for(i=0;i<prodqty;i++)
{
cout<<left<<setw(13)<<"["<<i+1<<"]"
<<setw(12)<<item[i].itemname
<<setw(14)<<item[i].brand
<<endl;
for(j=0;j<brandqty;j++)
{
item[j].items.left=item[j].items.stock-item[j].items.sold;
cout<<left<<setw(10)<<item[j].items.price
<<setw(10)<<item[j].items.stock
<<setw(10)<<item[j].items.sold
<<setw(10)<<item[j].items.left
<<endl;
}
}
}
I want to fix the display just like on the image above.
I did some array but it did not display other items I input.
Related
I want to remove a particular student object for a given roll no. from a students list using erase operation in STL. Following are my class designs.
But the compiler shows the following error message at place where I used the erase function.
no instance of overloaded function "std::vector<_Tp, _Alloc>::erase [with _Tp=Student, _Alloc=std::allocator<Student>]" matches the argument list -- argument types are: (Student) -- object type is: std::vector<Student, std::allocator<Student>>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
class Student
{
int roll;
char *name;
int score;
public:
Student(int r=0)
{
roll=r;
}
void get_data()
{
cout<<"Enter roll : ";
cin>>roll;
cout<<"Enter name : ";
cin>>name;
cout<<"Score : ";
cin>>score;
}
void show_data()
{
cout<<"Roll : "<<roll<<endl;
cout<<"Name : "<<name<<endl;
cout<<"Score : "<<score<<endl;
}
int ret_score()
{
return score;
}
int ret_roll()
{
return roll;
}
};
class Student_array
{
public:
vector <Student> Student_array;
vector <Student>::iterator it;
void add_student()
{
Student s;
s.get_data();
Student_array.push_back(s);
}
void remove_student()
{
int roll;
cout<<"Enter roll no. of the student to be removed : ";
cin>>roll;
for(int i=0;i<Student_array.size();i++)
{
if(roll==Student_array[i].ret_roll())
{
Student_array.erase(Student_array[i]);
break;
}
}
cout<<"Roll no. not found enter a valid roll no.\n";
}
};
std::vector::erase() takes an iterator as input, not a Student object, eg:
void remove_student()
{
int roll;
cout << "Enter roll no. of the student to be removed : ";
cin >> roll;
for(int i = 0; i < Student_array.size(); ++i)
{
if (roll == Student_array[i].ret_roll())
{
Student_array.erase(Student_array.begin() + i);
return; // <-- not 'break'!
}
}
cout << "Roll no. not found enter a valid roll no.\n";
}
Alternatively, you can use std::find_if() to find the desired Student instead of using a manual loop, eg:
void remove_student()
{
int roll;
cout << "Enter roll no. of the student to be removed : ";
cin >> roll;
auto iter = std::find_if(Student_array.begin(), Student_array.end(),
[=](Student &s){ return s.ret_roll() == roll; }
);
if (iter != Student_array.end())
Student_array.erase(iter);
else
cout << "Roll no. not found enter a valid roll no.\n";
}
You must use iterator to erase an element
for (auto iter = Student_array.begin(); iter != Student_array.end(); ++iter)
{
if (roll != iter->ret_roll())
continue;
Student_array.erase(iter);
break;
}
When i execute the program and select option number 2 it reads the data from the file successfully but when i select the option number 2 for the second time , third time and so on... nothing comes up and it returns back to the menu.
I have tried so many times, same error comes every time. PLEASE HELP. Thanks to all in advance. love all.
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
//class for database functions
class group
{
private:
struct person {
char flag;
char empcode[5];
char name[10];
int age;
float sal;
}p;
public:
fstream file,t_file;
ifstream fin;
ofstream fout;
group();
void addrec();
void listrec();
void modirec();
void delrec();
void recovrec();
};
//main function
int main()
{
char choice;
group g;
do
{
system("cls");
cout<<"1.Add Records"<<endl;
cout<<"2.List Records"<<endl;
cout<<"3.Modify Records"<<endl;
cout<<"4.Delete A Record"<<endl;
cout<<"5.Recover Deleted Records"<<endl;
cout<<"6.Exit"<<endl;
cout<<"Your choice ?: ";
cin>>choice;
system("cls");
switch(choice)
{
case '1':
g.addrec();
break;
case '2':
g.listrec();
break;
case '3':
g.modirec();
break;
case '4':
g.delrec();
break;
case '5':
g.recovrec();
break;
case '6':
exit(0);
}
} while(choice!=6);
return 0;
}
//default constructor
group::group()
{
file.open("EMP.DAT",ios::in|ios::out|ios::binary);
p.flag=' ';
if(!file)
cerr<<"Unable to open file";
}
//Add records at the end
void group::addrec()
{
char ch;
cout<<"Do You Want To Erase Previous Records ?: ";
cin>>ch;
if(ch=='y'||ch=='Y')
remove("EMP.DAT");
fout.open("EMP.DAT",ios::binary);
fout.seekp(0L,ios::end);
system("cls");
do
{
cout<<"Enter Emp_Code, Name, age, Salary"<<endl;
cin>>p.empcode>>p.name>>p.age>>p.sal;
fout.write((char*)&p,sizeof(p));
cout<<"Add another record ?: ";
cin>>ch;
} while(ch=='y'||ch=='Y');
fout.close();
}
//list all the records
void group::listrec()
{
int j=0;
//position get pointer at beginning
//fin.open("EMP.DAT",ios::binary);
file.seekg(0L,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(p.flag!='*')
{
cout<<"\nRecord N. "<<++j;
cout<<"\nEmp Code: "<<p.empcode;
cout<<"\nName: "<<p.name;
cout<<"\nAge: "<<p.age;
cout<<"\nSalary: "<<p.sal<<endl;
}
}
cin.ignore();
getchar();
}
//modifies a given record from file
void group::modirec()
{
char code[5];
int count=0;
long int pos;
cout<<"Enter Emp Code";
cin>>code;
file.open("EMP.DAT",ios::in|ios::out|ios::binary);
file.seekg(0,ios::beg);
//search an employee
while(file.read((char*)&p,sizeof(p)))
{
//if record is found
if(strcmp(p.empcode,code)==0&&p.flag==' ')
{
//recieve new data
cout<<"Enter new Data: "<<endl;
cout<<"Enter Emp_Code, Name, age, Salary"<<endl;
cin>>p.empcode>>p.name>>p.age>>p.sal;
//position put pointer to overwrite record
pos=count*sizeof(p);
file.seekp(pos,ios::beg);
file.write((char*)&p,sizeof(p));
file.close();
cout<<endl<<"Press Any Key...";
getchar();
return;
}
count++;
}
file.close();
cout<<endl<<"No Employee In File With Code: "<<code;
cout<<endl<<"Press Any Key...";
getchar();
}
//marks a record for deletion
void group::delrec()
{
char code[5];
long int pos;
int count =0;
cout<<"Enter Emp Code";
cin>>code;
file.open("EMP.DAT",ios::in|ios::out|ios::binary);
//position pointer at beginning
file.seekg(0L,ios::beg);
//search an employee
while(file.read((char*)&p,sizeof(p)))
{
//if record is found
if(strcmp(p.empcode,code)==0&&p.flag==' ')
{
p.flag='*';
//position put pointer
pos=count*sizeof(p);
file.seekp(pos,ios::beg);
file.write((char*)&p,sizeof(p));
file.close();
return ;
}
count++;
}
cout<<endl<<"No Employee In File With Code: "<<code;
file.close();
cout<<endl<<"Press Any Key...";
getchar();
}
//unmarkmarks a record
void group::recovrec()
{
char code[5];
long int pos;
int count =0;
cout<<"Enter Emp Code";
cin>>code;
file.open("EMP.DAT",ios::in|ios::out|ios::binary);
//position pointer at beginning
file.seekg(0L,ios::beg);
//search an employee
while(file.read((char*)&p,sizeof(p)))
{
//if record is found
if(strcmp(p.empcode,code)==0&&p.flag=='*')
{
p.flag=' ';
//position put pointer
pos=count*sizeof(p);
file.seekp(pos,ios::beg);
file.write((char*)&p,sizeof(p));
file.close();
return ;
}
count++;
}
file.close();
cout<<endl<<"No Employee In File With Code: "<<code;
cout<<endl<<"Press Any Key...";
getchar();
}
Hey sorry for the previous Question
OK..My project is to create and run a database for a college using c++
I have to use USN which is a Unique Student Number to access the database :
So i wrote the following program :
#include<iostream>
# include<conio.h>
#include<iomanip>
#include<string.h>
#include<stdlib.h>
int checkinarray(char[],char*);
using namespace std;
class student
{
private :
int sem;
float cgpa;
char password[11];
char passwordtrial[11];
void readdata();
void checkpassword();
void createpassword();
public :
char name[50];
int roll;
void printdata();
char USN[11];
static int number;
void opendatabase();
void firsttime();
public:
student(char n[50]="NONE")
{
number++;
roll=number;
cout<<endl<<"New record under the name of "<<n<<" has been created !"<<endl;
cout<<"Roll number set for new student as : "<<roll<<endl;
cout<<"Use this Roll number for further usage"<<endl<<endl;
};
};
void student::opendatabase()
{
int ch;
cout<<"Enter your name:"<<endl;
cin>>name;
cout<<"Enter your password"<<endl;
cin>>passwordtrial;
if(!strcmp(passwordtrial,password))
{
cout<<"Do you want to read or write";
cin>>ch;
switch(ch)
{
case 0 :
readdata();
break;
case 1 :
printdata();
break;
}
}
else
cout<<"Try Again";
};
void student::readdata()
{
cout <<endl<<"Enter the name of the student : ";
cin >> name;
cout <<endl<<"Enter the semester of the student : ";
cin >> sem;
cout <<endl<<" Enter the cgpa of the student : ";
cin >> cgpa;
};
void student :: printdata()
{
cout << "The name is : " << name << endl;
cout << "The sem is : " << sem << endl;
cout << "The roll is : " << roll << endl;
cout << "The cgpa is : " << cgpa << endl;
}
void student::firsttime()
{
cout<<"Enter your name :";
cin>>name;
cout<<"Hey "<<name<<" Welcome to DBMS "<<endl;
createpassword();
};
void student::createpassword()
{
cout<<"Please enter your 6 character password.. : ";
cin>>password;
cout<<"Please Input your Data here.... :" ;
readdata();
};
int student::number=0;
int main()
{
enum status {existing,newacc,exit};
enum functi{read,update};
char entry1[40];
char entry[10];
char usn[15];
char a[1000][15];
char n[40];
int i,j=0,k;
int s=2;
cout<<endl<<"WELCOME TO COLLEGE NAME"<<endl<<"Press enter to access Database...";
getch();
cout<<endl<<"Welcome to the Main Page of our Database : "<<endl;
while(1)
{//User option
cout<<endl<<"Do you want to access an old entry : "<<endl<<"OR"<<"Create a NEW entry : ";
cin>>entry1;
if(!strcmp(entry1,"old"))
s=existing;
else if(!strcmp(entry1,"new"))
s=newacc;
else
s=exit;
switch(s)
{
case existing:
{
i=1;
break;
}
case newacc:
{ i=1;
cout<<endl<<"Enter your usn : "<<endl;
cin>>usn;
strcpy(a[j],usn);
j++;
strcpy(n,usn);
cout<<n;
student usn(n);
usn.firsttime(); //Start here!! use i to go to next loop or stay in this loop,,change name entry to usn
break;
}
default :{cout<<"Error Input";i=0;break;}
}
if(i)
continue;
cout<<endl<<"What do u want to do??"<<endl<<"Read Entries "<<endl<<"Update entries";
cin>>entry;
if(!strcmp(entry,"read"))
s=read;
else if(!strcmp(entry,"update"))
s=update;
else
s=exit;
cout<<endl<<"Enter your usn : "<<endl;
cin>>usn;
if(checkinarray(a[15],usn))
{
switch(s)
{
case read:{
usn.printdata();
break;
}
case update:{
usn.firsttime();
break;
}
default :
cout<<"Are you sure you want to exit?"<<endl<<"Press 0 to exit"<<endl<<"to back to menu press 1";
cin>>k;
break;
}
if(!k)
break;
}
else cout<<"Invalid Roll number try again!";
}
}
int checkinarray(char a[][15],char b[])
{
int len;
//Finding the length of the string :
len=(sizeof(a)/sizeof(a[0]));
//Checking Conditions for roll number:
for(int k=0;k<len;k++)
{
if(strcmp(a[k],b))
return 1;//stringcompare!!
}
return 0;
}
okay so when i run this i get the following error :
request for member 'printdata' in 'usn', which is of non-class type 'char [15]'
AND
request for member 'firsttime' in 'usn', which is of non-class type 'char [15]'
So please help me overcome this error by suggesting different ways to create and call objects based on user input
OP's problem can be reduced to the following example:
#include<iostream>
#include<string.h>
using namespace std;
class student
{
public:
student(char n[50])
{
}
};
int main()
{
char usn[15];
char n[40];
{
cin >> usn;
strcpy(n, usn);
student usn(n);
}
usn.printdata();
}
This is what is meant by a Minimal, Complete, and Verifiable example. Not everything, but everything needed to reproduce the problem. The beauty of the MCVE is it has reduced the problem to the point where all of it can fit on the screen and probably within the brain, making it easy to analyze and test.
Things to note:
There are two variables named usn
char usn[15];
is an automatic variable within main. It is visible only within main and will expire at the end of main
student usn(n);
is an automatic variable within an anonymous block within main. It is visible only within this block and will expire at the end of the block.
Annotating this block to better explain what is happening, we get
{
cin >> usn; // uses char usn[15];
strcpy(n, usn);
student usn(n); // declares a new variable named usn that replaces char usn[15];for the remainder of this block
} // student usn(n); ends right here and is destroyed.
usn.printdata(); //uses char usn[15]; which has no printdata method.
So how do we fix this?
student usn(n); must have a wider scope.
one of these two variables must change names because once student usn(n); has wider scope it will collide with char usn[15];
Lets give that a quick try.
int main()
{
char usn[15];
char n[40];
student stud(n);
{
cin >> usn;
strcpy(n, usn);
}
stud.printdata();
}
Isn't possible because there is no data in n with which we can make stud. At least not for this minimal example.
int main()
{
char usn[15];
char n[40];
student * stud;
{
cin >> usn;
strcpy(n, usn);
stud = new student(n);
}
stud->printdata();
delete stud;
}
Solves that by dynamically allocating stud so that it is no longer scoped by the braces. Unfortunately that does pick up some extra memory management woes. stud must be deleted. Added a delete, but what if printdata throws an exception and delete stud; is skipped?
int main()
{
char usn[15];
char n[40];
std::unique_ptr<student> stud;
{
cin >> usn;
strcpy(n, usn);
stud.reset(new student(n));
}
stud->printdata();
}
std::unique_ptr takes care of that. But... What about that whole database thing? Why not store stud in a list?
int main()
{
char usn[15];
char n[40];
std::vector<student> studs;
{
cin >> usn;
strcpy(n, usn);
studs.emplace_back(n); // or studs.push_back(student(n));
}
for (student & stud: studs)
{
stud.printdata();
}
}
std::vector solves both problems at once.
I'm doing an assignment which requires file handling in C++.Assignment is long enough to be posted here, but i have made a similar simple code to elaborate my question.The following code is not read all data from file it only read the last record
please help me to make it correct.
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string.h>
//class
class medicine{
int id;
char med_name[50];
int price;
int quantity;
char date[50];
public:
void data_entery(){
//int i;char na[50];int p;int q;char da[50];
cout<<"Enter id: ";
cin>>id;
cout<<"Enter name: ";
cin>>med_name;
cout<<"Enter price: ";
cin>>price;
cout<<"Enter quantity: ";
cin>>quantity;
cout<<"Enter exp_date: ";
cin>>date;
}
void display(){
cout<<this->id<<"\t "<<this->med_name<<"\t "<<this->price<<"\t"<<this- >quantity<<"\t "<<this->date;
}
}med[10];
using namespace std;
int main (){
//writing in file
ofstream wfile("medicines.txt",ios::app|ios::binary);
wfile.seekp(0,ios::end);
int rec=wfile.tellp()/sizeof(medicine);
cout<<"there are "<<rec<<" records";
med[rec].data_entery();
wfile.write(reinterpret_cast<char *>(&med),sizeof(medicine));
wfile.close();
//reading in file
ifstream rfile("medicines.txt",ios::in|ios::binary);
rfile.seekg(0,ios::end);
rec=rfile.tellg()/sizeof(medicine);
rfile.seekg(0,ios::beg);
cout<<"there are "<<rec<<" records";
for (int k=0;k<rec;k++){
med[k].display();
}
rfile.read(reinterpret_cast<char *>(&med),sizeof(med)*rec);
rfile.close();
getch();
return 0;
}
I am assuming that your file medicines.txt is initially empty.
What you have done wrong is that you have made 10 objects of the medicine class, but you are writing only one object to the file.
What you need to do here is:
for (int i=0; i < 10; i++) {
med[i].data_entery();
wfile.write(reinterpret_cast<char *>(&med),sizeof(medicine));
}
wfile.close();
Now you'll need to add 10 medicines, after details of each medicine has been added, that medicine will be written to the file.
I hope this helps.
Here is a better version of your code
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string.h>
using namespace std;
//class
class medicine
{
int id;
char med_name[50];
int price;
int quantity;
char date[50];
public:
void data_entery()
{
//int i;char na[50];int p;int q;char da[50];
cout<<"\nEnter id: ";
cin>>id;
cout<<"Enter name: ";
cin>>med_name;
cout<<"Enter price: ";
cin>>price;
cout<<"Enter quantity: ";
cin>>quantity;
cout<<"Enter exp_date: ";
cin>>date;
}
void display()
{
cout<<"\nID :"<<this->id<<"\nName :"<<this->med_name<<"\nPrice :"<<this->price<<"\nQuantity :"<<this->quantity<<"\nExp Date :"<<this->date<<"\n";
}
}med;
int main ()
{
//writing in file
ofstream wfile("medicines.txt",ios::app|ios::binary);
wfile.seekp(0,ios::end);
int rec=wfile.tellp()/sizeof(medicine);
cout<<"\nthere are "<<rec<<" records";
med.data_entery();
wfile.write(reinterpret_cast<char *>(&med),sizeof(medicine));
wfile.close();
//reading in file
ifstream rfile("medicines.txt",ios::in|ios::binary);
rfile.seekg(0,ios::end);
rec=rfile.tellg()/sizeof(medicine);
rfile.seekg(0,ios::beg);
cout<<"\nthere are "<<rec<<" records";
while(rfile.read(reinterpret_cast<char *>(&med),sizeof(med)))
{
med.display();
}
rfile.close();
getch();
return 0;
}
Now, when you are using files, you do not need to create an array of objects. Once you store the object into the file, you can just reuse that object. The data can be accessed from the File. That is what I have done in this code. I have edited this code in such a manner as to not change your method, instead just corrected the problems and also made your code a little better. In each run of this code, you enter the details of one record, and then the details of all the records are shown.
The good thing about this code is, you can enter as many records as you want. You are not restricted to 10 records like your original code.
Problem statement:
C++ program that reads a customer’s checking account information calculates his/her account balance.
menu based application should be
developed to perform the following
functionalities iteratively until the user request to quit the program:
1. Display, 2. Deposit, 3. Withdraw, 4. Quit.
This is what I have so far.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
//Main function
int main()
{
//Identify type variables
int x=0;
float amountinput,famount,sum;
string firstname, lastname,date,filename,input,ID,amount;
fstream file;
//Program loop
while(true)
{
//Main menu loop
do
{
cout<<"Enter the number of the option you would like carried out.\n";
cout<<"1. Summary\n";
cout<<"2. Deposit\n";
cout<<"3. Withdraw\n";
cout<<"4. Quit\n";
cin>>x;
}
while(!x);
//When Quit is input, break
if(x==4)
{
break;
}
//Summary display
if (x==1)
{
cout<<"You have selected option number 1. Summary.\n"<<endl;
cout<<"Enter your Cust_ID: ";
cin>>ID;
file.open("C:\\Users\\Raggulddon\\Desktop\\C++ supplement
\\Cust_"+ID+".dat", ios::in|ios::out|ios::app);
//IF not found error.
if(!file)
{
cout<<"Sorry your account could not be found\n";
}
//Else display all content.
else
{
cout<<endl<<file.rdbuf()<<"\n";
file.close();
}
}
//Deposit
else if(x==2)
{
cout<<"You have selected option number 2. Deposit.\n";
cout<<"Please enter you account ID: ";
cin>>ID;
file.open("C:\\Users\\Raggulddon\\Desktop\\C++ supplement
\\Cust_"+ID+".dat", ios::in|ios::out|ios::app);
if(!file)
{
cout<<"Sorry the requested account could not be located.\n";
}
else
{
file>>firstname>>lastname;
cout<<endl<<firstname<<" "<<lastname<<endl;
while(!file.eof())
{
file>>date>>amount;
//
//This is mainly where I am missing the lines of code..
//
float atof(string& amount);
cout<<date<<"\t\t"<<amount<<endl;
}
cin.get();cin.get();
cout<<"How much would you like to deposit today.";
cin>>amountinput;
cout<<endl;
file.close();
}
}
else if(x==3);
else if(x==4);
}
cin.get();cin.get(); //or system("PAUSE");
return 0;
}
A sample text file looks like this.
James Bond
01/01/12 200010
03/30/12 -40000
04/30/12 -40000
05/30/12 -40000
06/30/12 -40000
07/30/12 -40000
I have converted the date and amount into strings and have attempted
to convert it into a float and double, and add them up.
I have thought of separating the amounts but I can't manage to do that either.
I have also tried to make make amount a char type.
Any advice to lead me on the right path would be kindly appreciated.
Although it doesn't attempt to be a complete version of your program, here's a bit of code to read the supplied text file, using the first item (after the name) as an initial balance, and the rest as deposits (if they're positive) or withdrawals (if they're negative), reporting the amount of each transaction, and the balance after it's been applied.
#include <iostream>
#include <string>
#include <algorithm>
struct transaction {
std::string date;
double value;
friend std::istream &operator>>(std::istream &is, transaction &t) {
is >> t.date >> t.value;
return is;
}
operator double() { return value; }
};
int main(){
double value;
transaction t;
std::string name;
std::getline(std::cin, name);
std::cin >> t;
value = t;
while (std::cin >> t) {
std::cout << "Transaction: " << t.value;
value += t;
std::cout << "\tBalance: " << value << "\n";
}
std::cout << value;
}