Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include "Hardware.h"
- #include <iomanip>
- #include <string>
- using std::ofstream;
- using std::istream;
- using std::ios;
- using std::cerr;
- using std::endl;
- using std::cout;
- using std::cin;
- using std::ios;
- using std::setw;
- using std::string;
- using namespace std;
- int main()
- {
- int input;
- int ID;
- string Name;
- int Amount;
- double Price;
- void outputline(ostream&, const Hardware &);
- Hardware Empty;
- ofstream File("Hardware.dat", ios::binary);
- /*for (int i = 0; i < 100; i++)
- {
- File.write(reinterpret_cast<const char *> (&Empty), sizeof(Hardware));
- }*/
- cout << "If your want to add record press 1\n";
- cout << "If your want to view all records press 2\n";
- cin >> input;
- while (1)
- {
- if (input == 1)
- {
- while (input == 1)
- {
- cout << "Please enter record,Name,Amount and Price";
- cin >> ID;
- cin >> Name;
- cin >> Amount;
- cin >> Price;
- Empty.setID(ID);
- Empty.setName(Name);
- Empty.setAmount(Amount);
- Empty.setPrice(Price);
- File.seekp((Empty.getID()-1)*sizeof(Hardware));
- File.write(reinterpret_cast<const char *> (&Empty), sizeof(Hardware));
- system("cls");
- cout << "If your want to add record press 1\n";
- cout << "If your want to view all records press 2\n";
- cin >> input;
- }
- }
- //cin >> input;
- if (input == 2)
- {
- ifstream File("Hardware.dat", ios::app);
- while (File && !File.eof()) {
- outputline(cout, Empty);
- File.read(reinterpret_cast<char *>(&Empty),
- sizeof(Hardware));
- }
- cout << "If your want to add record press 1\n";
- cout << "If your want to view all records press 2\n";
- cin >> input;
- }
- }
- system("pause");
- return 0;
- }
- void outputline(ostream &output, const Hardware &ID)
- {
- {
- output << left << setw(10) << ID.getID()
- << setw(16) << ID.getName()
- << setw(11) << ID.getAmount()
- << setw(10) << setprecision(2) << right << fixed
- << showpoint << ID.getPrice() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement