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 133 134 135 136
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct LandDetails { // declaring a struct
string Surname, OtherNames, LandNum,KraPin,OwnerIdCard, address,LandCounty, LandDist, LandDiv, Landloc, LandSubloc;
} entry;
LandDetails Fill_struct (LandDetails &entry); //prototype---------inputs user data
void PrintEnteredDetails (LandDetails &enter);//prototype-----------displays entered data
void write_file (ofstream &openFile); //prototype -----------writes entered data to a text file of csv format
int main (){
ofstream openFile ("Land Registry.txt", ios::app);
LandDetails create;
Fill_struct (create);
PrintEnteredDetails (create);
write_file (openFile);
system ("cls");
return 0;
}
LandDetails Fill_struct (LandDetails &entry){
cout<<"Welcome to the new lands management information system\n\n";
{
cout<<"Enter Surname \n";
getline (cin,entry.Surname);
cout<<"Enter other names\n";
getline (cin,entry.OtherNames);
cout<<"Enter Land number\n";
getline (cin,entry.LandNum);
cout<<"Enter owner KRA pin\n";
getline (cin,entry.KraPin);
cout<<"Enter Owner id card number\n";
getline (cin, entry.OwnerIdCard);
cout<<"Enter owner address\n";
getline (cin, entry.address);
cout<<"Enter Land county\n";
getline (cin, entry.LandCounty);
cout<<"Enter Land district\n";
getline (cin, entry.LandDist);
cout<<"Enter Land division\n";
getline (cin, entry.LandDiv);
cout<<"Enter land location\n";
getline (cin, entry.Landloc);
cout<<"Enter Land sub-location\n";
getline (cin, entry.LandSubloc);
return entry;
}
}
void PrintEnteredDetails (LandDetails &enter){
cout<<"______________________________________________________________________________"<<"\n";
cout<<"You have entered the following details:\n\n";
cout<<"Surname:"<<enter.Surname<<setw(3)<<" "<<"OtherNames:"<<enter.OtherNames<<setw(3)<<" "<<"Owner Id number:"<<enter.OwnerIdCard<<"\n";
cout<<"Land number:"<<enter.LandNum<<setw(3)<<" "<<"KRA pin:"<<enter.KraPin<<"\n";
cout<<"Postal address:"<<enter.address<<setw(3)<<" "<<"County:"<<enter.LandCounty<<"\n";
cout<<"District:"<<enter.LandDist<<setw(3)<<" "<<"Division:"<<enter.LandDiv<<"\n";
cout<<"Location:"<<enter.Landloc<<setw(3)<<" "<<"Sub-location:"<<enter.LandSubloc<<"\n";
cout<<"______________________________________________________________________________"<<"\n";
}
void write_file (ofstream &openFile) {
//int i=0, no_of_members = 10;
if (!openFile ){
cout<<"Land register coud not be opened !";
return;
}
else
{
//for (i=0; i<no_of_members; i++)
openFile<<entry.Surname<<","<<entry.OtherNames<<","<<entry. LandNum<<","<<
entry.KraPin<<","<<entry.OwnerIdCard<<","<< entry.address<<","<<
entry.LandCounty<<","<< entry.LandDist<<","<< entry. LandDiv<<","<<
entry. Landloc<<","<<entry.LandSubloc<<endl;
}
cout <<"All members data have been successfully saved"<<endl;
openFile.close ();
}
|