Edit & Delete function
Apr 29, 2015 at 10:41pm UTC
Hello everyone, My final project of the year is due tomorrow and i need to get this project finished and i am having trouble getting a delete and edit function for my code, could someone give me some assistance please
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
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
//declare variables
void Add();
void Edit();
void Display();
void Delete();
struct Inventory
{
char name[35], address[25];
int number;
int age;
int choice;
};
int main()
{
int choice;
do
{
cout << "MENU" << endl;
cout<<"1) Add a Phone Record " <<endl;
cout<<"2) Display Phone Records " <<endl;
cout<<"3) Edit a Phone Record " <<endl;
cout<<"4) Delete a Phone Record" <<endl;
cout<<"5) Search a Phone Record" <<endl;
cout<<"6) Exit " <<endl<<endl;
cout<<"Please choose option:" ;
cin >> choice;
switch (choice)// change into an if else statement then turn into a function
{
case 1:
Add();
break ; //Add record
case 2:
Display();
break ; //Display record
case 3:
Edit();
break ; //Edit Record
case 4:
Delete();
break ; //Delete record
default :
cout << "Invalid Selection" << endl;
}
}
while
(choice <= 4);
system("PAUSE" );
return 0;
}
//Add function
void Add()
{
system("CLS" ); //clears screen
fstream fout;
const int size = 3;
char ch;
int i = 0;
fout.open("Records.txt" , ios::out);
Inventory inv;
do
{
cout << "Enter Name: " << endl;
cin.ignore();
cin >> inv.name;
cout << "Enter Address: " << endl;
cin >> inv.address;
cout << "Enter Number: " << endl;
cin >> inv.number;
cout << "Enter Age: " << endl;
cin.ignore();
cin >> inv.age;
//write record to file
fout.write(reinterpret_cast <char *>(&inv), sizeof (inv));
cout << "Do you want to add another record? " << endl;
cin >> ch;
}
while
(ch == 'Y' && 1 < 4);
//close the file
fout.close();
}
//"Display" function
void Display()
{
fstream fout;
fout.open("Records.txt" , ios::in);
Inventory inv;
fout.read(reinterpret_cast <char *> (&inv), sizeof (inv));
while (!fout.eof())
{
cout << "\nName\t: " ;
cout << inv.name;
cout << "\nAddress\t: " ;
cout << inv.address;
cout << "\nNumber\t: " ;
cout << inv.number;
cout << "\nAge\t: " ;
cout << inv.age;
fout.read(reinterpret_cast <char *> (&inv), sizeof (inv));
}
//close the file
fout.close();
}
void Edit()
{
}
void Delete()
Topic archived. No new replies allowed.