Re: basics uses of vectors for an A/R basic program
Code:
while(TORD)
{
Torder Torders;
TORD is a constant is the while condition is always true.
Torder is a struct within the struct transactions - so use
Code:
transactions::Torder Torders;
Code:
total = Torders.price[i] * Torders.quantity[i];
member variables price and quantity are not defined as arrays so cannot be accessed via a subscript.
Re: basics uses of vectors for an A/R basic program
Hi, I'm back lol... I've made some corrections that have been given, but of course I'm still having issues
I'm getting an error message and I'm not sure how to fix it
Code:
C:\Users\Gavin\Desktop\Data Structures\abc hardware project 1\10.20.2015 hardware 22.cpp|60|error: cannot bind 'std::basic_istream<char>' lvalue to 'std::basic_istream<char>&&'|
please see below of what I have so far, Thank you so much!!
Code:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const char TORD = 'O';
const char TPAY = 'P';
struct master
{
master() : custNumber(0), custName(""), balance(0.0) {}
int custNumber;
string custName;
double balance;
};
struct transactions
{
struct Torder
{
Torder() : desc(""), quantity(), price() {}
string desc;
int quantity[];
double price[];
};
struct Tpayment
{
Tpayment() : payment(0.0) {}
double payment;
};
transactions() : transactionType(' '), custNumber(0), transNumber(0), pay(), order() {}
char transactionType;
int custNumber;
int transNumber;
Tpayment pay;
Torder order;
};
istream& operator >>(istream& is, master& m)
{
return (is >> m.custNumber >> m.custName >> m.balance);
}
ostream& operator <<(ostream& os, const master& ms)
{
return (os << ms.custNumber << " " << ms.custName << " " << ms.balance);
}
istream& operator >>(istream& is, transactions& t)
{
if (is >> t.transactionType >> t.custNumber >> t.transNumber)
switch (t.transactionType) {
case TORD:
is >> t.order.desc >> t.order.quantity >> t.order.price;
break;
case TPAY:
is >> t.pay.payment;
break;
default:
//deal with bad transaction type
break;
}
return is;
}
ostream& operator <<(ostream& os, const transactions& ts)
{
os << ts.transNumber << " " << ts.transactionType << " " << ts.custNumber << " ";
switch (ts.transactionType) {
case TORD:
os << ts.order.desc << " " << ts.order.price << " " << ts.order.quantity;
break;
case TPAY:
os << ts.pay.payment;
break;
default:
os << "bad type" << endl;
break;
}
return os;
}
void order_Balance(double&, double&); //add two functions
void payment_Balance(double&, double&);
int main()
{
const string mfn = "master.txt";
const string tfn = "trans.txt";
ifstream mfs(mfn);
ifstream tfs(tfn);
if (!mfs.is_open()) {
cerr << "Cannot open master file " << mfn << endl;
return 1;
}
if (!tfs.is_open()) {
cerr << "Cannot open trans file " << tfn << endl;
return 2;
}
vector<master> vm;
master ms;
while (mfs >> ms)
vm.push_back(ms);
vector<transactions> vt;
transactions ts;
while (tfs >> ts)
vt.push_back(ts);
for (const auto& m : vm)
cout << m << endl;
for (const auto& t : vt)
cout << t << endl;
cout<<ms.custName<<"\t"<<ms.custNumber<<endl<<endl;
cout<<"\t\t\t"<<ms.balance<<endl<<endl;
for(int i=0; i<vm.size(); i++)
{
transactions:: Torder Torders;
double total;
total=Torders.price[i]*Torders.quantity[i];
cout<<transactions.transNumber[i]<<"t"<<Torders.desc[i]<<"\t$"<<total<<endl;
order_balance(total, ms.balance);
Transactions::Tpayment Tpayments;
cout<<transactions.TransNumber[i]<<Tpayments.Tpayment[i]<<"\t$"<<Tpayments.payment[i]<<endl;
payment_Balance(Tpayments.Tpayment[i],new_Balance)
cout<<"\t\t\tBalance Due"<<"\t$"<<New_Balance;
}
}
void order_Balance(double& order, double& previous)
{
double x;
x=order + previous;
return x;
}
void payment_Balance(double&order, double& previous)
{
double y;
y=previous - order;
return y;
}
Re: basics uses of vectors for an A/R basic program
Code:
int quantity[];
double price[];
You are trying to make quantity and price arrays, but you need to specify the size of the array at compile time. If you don't know the size of the array at compile time then you need to use some other data-structure (eg vector).
However, quantity and price are not required to be arrays as for each instance of Torder they only have one value.
Code:
transactions:: Torder Torders;
double total;
total=Torders.price[i]*Torders.quantity[i];
even assuming price and quantity have been declared correctly as arrays, this code cannot possibly be correct as no values have been set for .price and .quantity before the values are used in the calculation.
Is this a homework assignment?
Re: basics uses of vectors for an A/R basic program
Yes , this is actually for a class assignment, the problem for me that I work during the day and I take classes at night, i work long hours so my time is very limited, my school offerd tutoring but the times that they have it I'm at work. They do have a weekend tutor but I'm also taking a weekend class, so basically that's why I'm on here... I'm not sure if it's ok or not, but if it's not if you can direct to a online tutor or someplace that xan help me I would be much obliged... you guys are amazing and i am grateful for all that I've learned hear. Thank you
Re: basics uses of vectors for an A/R basic program
OK. First things first. What I suggest is before you undertake any more 'off the cuff' coding you first produce a design for the program. What are the inputs, what are the outputs, what data structures are needed (most of this is already there) and then what logic is required to produce the required output. If you had no computer how would you do this manually? Once you have the design then you translate the design into a program and produce the code. Then you test and debug the code against the design. What you really shouldn't do is to start coding without first having put in the effort to produce the design. So IMO this is what I suggest you now do. Produce the design first and then write the code from the design.
Re: basics uses of vectors for an A/R basic program
OK, I went back to the drawing board with this and I made a lot of changes. I was able to get it to run, well kind of. I'm having issues with my logic. I know it's probably something simple but I'm not seeing it. I have a lot to learn I know. please give me any suggestions of what I need to get it to run correctly. Thanks.
Code:
#include <fstream>
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
struct master
{
int custNumber;
string custName;
double balance;
master() : custNumber(0),custName(""), balance(0.0) {}
};
struct Torder
{
string desc;
int quantity;
double price;
Torder() : desc(""), quantity(), price(0.0) {}
};
struct Tpayment
{
double payment;
Tpayment() : payment(0.0) {}
};
struct transactions
{
char transactionType;
int custNumber;
int transNumber;
Tpayment pay;
Torder order;
transactions() : transactionType(' '), custNumber(0), transNumber(0), pay(), order() {}
};
double orderAmount(int&, double&);
double paymentAmount(double&, double&);
int main()
{
ifstream masterFile;
ifstream transFile;
master masterRecord[7];
transactions transactionRecord[40];
double ordered;
const int SIZE=35;
int i=0;
masterFile.open("master.txt");
transFile.open("trans.txt");
while (i<7)
{
transFile>>transactionRecord[i].transactionType;
masterFile>>masterRecord[i].custNumber;
masterFile>>masterRecord[i].custName;
masterFile>>masterRecord[i].balance;
cout<<masterRecord[i].custName<<" "<<"\t"<<masterRecord[i].custNumber<<endl<<endl;
cout<<"\t"<<"Previous Balance"<<" $"<<masterRecord[i].balance<<endl<<endl;
for(int j=0; j<SIZE; j++)
{
if (transactionRecord[j].transactionType=='O')
{
transFile>>transactionRecord[j].custNumber;
transFile>>transactionRecord[j].transNumber;
transFile>>transactionRecord[j].order.desc;
transFile>>transactionRecord[j].order.quantity;
transFile>>transactionRecord[j].order.price;
cout<<transactionRecord[j].transNumber<<" "<<transactionRecord[j].order.desc<<" $"
<<orderAmount(transactionRecord[j].order.quantity,transactionRecord[j].order.price)<<endl<<endl;
//ordered=orderAmount;
}
else if(transactionRecord[j].transactionType=='P')
{
transFile>>transactionRecord[j].custNumber;
transFile>>transactionRecord[j].transNumber;
transFile>>transactionRecord[j].pay.payment;
paymentAmount(ordered, transactionRecord[j].pay.payment);
cout<<transactionRecord[j].transNumber<<" "<<"Payment $"<<transactionRecord[j].pay.payment<<endl<<endl;
};
};
cout<<"\n\n new Balance Due ";cout<<"\n\n";
i++;
};
masterFile.close();
transFile.close();
return 0;
}
double orderAmount(int& quantity, double& price)
{
return quantity* price;
}
double paymentAmount(double& order,double& previous)
{
return order - previous;
}
also the paymentAmount function
Code:
double paymentAmount(double& order,double& previous)
{
return order - previous;
}
isn't running correctly. I'm a beginner what's the simplest way from it to run correctly. thanks again