could use help getting my code to work. Here is the code so far:
Main.cpp
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "VMC.h"
using namespace std;
int main(){
system("cls");
bool run=true;
do{
int Option;
cout << "----------------------Address Book-----------------------------" << endl;
cout << "\n";
cout << "Choose an option" << endl;
cout << "1) Add Contact" << endl;
cout << "2) Edit Contact" << endl;
cout << "3) Delete Contact" << endl;
cout << "4) View All Contacts" << endl;
cout << "6) Exit" << endl << endl;
cout << "Choose an option: ";
cin >> Option;
cin.ignore();
switch (Option){
case 1:
Vmc.addPerson();
break;
case 2:
Vmc.editPerson();
break;
case 3:
Vmc.deletePerson();
break;
case 4:
Vmc.viewPerson();
break;
case 6:
run = false;
break;
default:
cout << "Please Choose between 1 to 6" <<endl;
int main();
}
} while(run);
cout << "End of Program";
}
VMC.h
class Vmc
{
private:
std::string Fname;
std::string Lname;
std::string Address1;
std::string Phone;
public:
Vmc (string Fname,string Lname,string Address1,string Phone);
void addPerson();
void viewPerson();
void searchPerson();
void editPerson();
void deletePerson();
};
#endif
VMC.cpp
#include <iostream>
int Vmc::addPerson()
{
cout << "Enter First Name: ";
getline(cin, Fname);
cout << "Enter Last Name: ";
getline(cin, Lname);
cout << "Enter Address: ";
getline(cin, Address1);
cout << "Enter Contact Number: ";
getline(cin, Phone);
}
int Vmc::viewPerson()
{
system("cls");
cout << endl;
system ("pause");
system ("cls");
}
int Vmc::editPerson()
{
system("cls");
int choice;
double counter, number;
string Fname, Lname, Address1, Phone, Fname2, Lname2, Address2, Phone2, choice2,choice3;
ifstream edit("address.txt");
ofstream temp("Temp.txt", ios::app);
cout << "Please type the Entry number that you wish to delete: ";
cin >> choice;
cout << endl;
while (edit >> counter >> Fname2 >> Lname2>> Address2 >> Phone2){
if (counter==choice){
cout << counter << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Phone2 << endl<<endl;
cout << "Is this the contact that you wish to delete? (y or n) ";
cin >> choice3;
cout << endl;
}
if (choice3=="n") {
main();
}
if (counter<choice){
temp << counter << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Contact2 << endl;
}
if (counter > choice){
temp << counter - 1 << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Contact2 << endl;
}
}
edit.close();
temp.close();
if (remove("address.txt")==0){
cout << "Succesful Removing File" << endl;
}else{
cout << "Error removing"<< endl;
}
if(rename("Temp.txt", "address.txt")==0){
cout << "Succesful Renaming file"<< endl;
}else{
cout << "Error renaming"<<endl;
}
system("pause");
system("cls");
}
}
int Vmc::deletePerson()
{
system("cls");
int choice;
double counter, number;
string Fname, Lname, Address, Phone, Fname2, Lname2, Address2, Phone2, choice2,choice3;
ifstream edit("address.txt");
ofstream temp("Temp.txt", ios::app);
cout << "Please type the Entry number that you wish to delete: ";
cin >> choice;
cout << endl;
while (edit >> counter >> Fname2 >> Lname2>> Address2 >> Phone2){
if (counter==choice){
cout << counter << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Phone2 << endl<<endl;
cout << "Is this the contact that you wish to delete? (y or n) ";
cin >> choice3;
cout << endl;
}
if (choice3=="n") {
main();
}
if (counter<choice){
temp << counter << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Phone2 << endl;
}
if (counter > choice){
temp << counter - 1 << " " << Fname2 << " "<< Lname2 << " " << Address2 << " " << Phone2 << endl;
}
}
edit.close();
temp.close();
if (remove("address.txt")==0){
cout << "Succesful Removing File" << endl;
}else{
cout << "Error removing"<< endl;
}
if(rename("Temp.txt", "address.txt")==0){
cout << "Succesful Renaming file"<< endl;
}else{
cout << "Error renaming"<<endl;
}
system("pause");
system("cls");
}
}
What I have tried:
I am trying to use classes and header files to generate a list of entries.