Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<sstream>
  4. using namespace std;
  5.  
  6. /*
  7. R.M. 2016 HC
  8. */
  9.  
  10. struct payroll{
  11. string first_name;
  12. string last_name;
  13. float rate;
  14. float hours;
  15. float ot_rate;
  16. float ot_hours;
  17. float tax_rate;
  18.  
  19. float gross_pay;
  20. float taxes;
  21. float net_pay;
  22. } data[150];
  23.  
  24.  
  25.  
  26. int greet();
  27. int menu(int num);
  28. void new_file();
  29. void open_file();
  30. void rename_file();
  31. void delete_file();
  32. string space_this(string text, int space, int align);
  33. string space_this2(string text, int space, int align);
  34.  
  35. int main(){
  36.  
  37. greet();
  38.  
  39. // system("pause");
  40. return 0;
  41. }
  42.  
  43. int greet(){
  44. printf("Simple Payroll Program\t\tabc123\n\n");
  45. string username, password;
  46. cout<<"Username: ";cin>>username;
  47. cout<<"Password: ";cin>>password;
  48. cout<<endl;
  49. if(username=="abc" && password=="123"){menu(3);}
  50. }
  51.  
  52. int menu(int num){
  53. char choice;
  54. if(num==1){cout<<"[n] New File\n[o] Open File\n[r] Rename File\n[d] Delete File\n[z] Exit\n\n";}
  55. else if(num==3){cout<<" [n] New File\n [o] Open File\n [r] Rename File\n [d] Delete File\n [z] Exit\n\n";}
  56. else{printf("[n] New File [o] Open File [r] Rename File [d] Delete File [z] Exit\n");}
  57. cin>>choice;
  58. switch(choice){
  59. case 'n':
  60. system("cls");
  61. new_file();
  62. break;
  63. case 'o':
  64. system("cls");
  65. open_file();
  66. break;
  67. case 'r':
  68. system("cls");
  69. rename_file();
  70. break;
  71. case 'd':
  72. system("cls");
  73. delete_file();
  74. break;
  75. case 'z':
  76. break;
  77. return 0;
  78. default:
  79. system("cls");
  80. menu(1);
  81. break;
  82.  
  83. }
  84. }
  85.  
  86. void new_file(){
  87. string filename;
  88. int entries=0;
  89. cout<<"Enter Filename: ";cin>>filename;cout<<"\n";
  90. cout<<"Enter Number Of Entries: ";cin>>entries;
  91. system("cls");
  92.  
  93. float gross_total=0;
  94. float tax_total=0;
  95. float net_total=0;
  96. cout<<filename<<" "<<entries<<" entries\n\n";
  97. for(int i=0;i<entries;i++){
  98. cin.ignore();
  99. cout<<"#"<<i+1<<endl;
  100. cout<<"Enter First Name: ";getline(cin,data[i].first_name);
  101. cout<<"Enter Last Name: ";getline(cin,data[i].last_name);
  102. cout<<"Enter Rate: ";cin>>data[i].rate;
  103. cout<<"Enter Hours: ";cin>>data[i].hours;
  104. cout<<"Enter Overtime Rate: ";cin>>data[i].ot_rate;
  105. cout<<"Enter Overtime Hours: ";cin>>data[i].ot_hours;
  106. cout<<"Enter Tax Rate: ";cin>>data[i].tax_rate;
  107.  
  108. data[i].gross_pay = data[i].rate*data[i].hours + data[i].ot_rate*data[i].ot_hours;
  109. data[i].taxes = (data[i].tax_rate/100)*data[i].gross_pay;
  110. data[i].net_pay = data[i].gross_pay-data[i].taxes;
  111.  
  112. gross_total+=data[i].gross_pay;
  113. tax_total+=data[i].taxes;
  114. net_total+=data[i].net_pay;
  115.  
  116.  
  117. cout<<endl;
  118. }
  119. system("cls");
  120. cout<<filename<<"\n\n";
  121. ofstream payroll_file;
  122. payroll_file.open(filename.c_str());
  123. printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n","Employee","Rate","Hrs","OT","Hrs","Gross","Taxes","Net Pay");
  124. printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n","","","","","","","","");
  125.  
  126. payroll_file<<space_this("Employee",20,1)<<space_this("Rate",7,1)<<space_this("Hrs",4,1)<<space_this("OT",7,1);
  127. payroll_file<<space_this("Hrs",4,1)<<space_this("Gross",10,1)<<space_this("Taxes",9,1)<<space_this("Net Pay",10,1)<<"\n";
  128.  
  129. //convert int to string
  130. stringstream temp10, temp11, temp12;
  131. string gross_total_str, tax_total_str, net_total_str;
  132. temp10<<gross_total; temp10>>gross_total_str;
  133. temp11<<tax_total; temp11>>tax_total_str;
  134. temp12<<net_total; temp12>>net_total_str;
  135.  
  136. for(int i=0;i<entries;i++){
  137. stringstream temp, temp2, temp3, temp4, temp5, temp6, temp7;
  138. string rate_str, rate_hrs_str, ot_rate_str, ot_hrs_str, gross_str, taxes_str, net_str;
  139.  
  140. temp<<data[i].rate; temp>>rate_str; temp2<<data[i].hours; temp2>>rate_hrs_str;
  141. temp3<<data[i].ot_rate; temp3>>ot_rate_str; temp4<<data[i].ot_hours; temp4>>ot_hrs_str;
  142. temp5<<data[i].gross_pay; temp5>>gross_str; temp6<<data[i].taxes; temp6>>taxes_str;
  143. temp7<<data[i].net_pay; temp7>>net_str;
  144.  
  145.  
  146. cout<<space_this(data[i].first_name+" "+data[i].last_name,20,1);
  147. cout<<space_this(rate_str,7,2);
  148. cout<<space_this(rate_hrs_str,4,2);
  149. cout<<space_this(ot_rate_str,7,2);
  150. cout<<space_this(ot_hrs_str,4,2);
  151. cout<<space_this(gross_str,10,2);
  152. cout<<space_this(taxes_str,9,2);
  153. cout<<space_this(net_str,10,2);
  154. cout<<endl;
  155.  
  156. payroll_file<<space_this(data[i].first_name+" "+data[i].last_name,20,1);
  157. payroll_file<<space_this(rate_str,7,2);
  158. payroll_file<<space_this(rate_hrs_str,4,2);
  159. payroll_file<<space_this(ot_rate_str,7,2);
  160. payroll_file<<space_this(ot_hrs_str,4,2);
  161. payroll_file<<space_this(gross_str,10,2);
  162. payroll_file<<space_this(taxes_str,9,2);
  163. payroll_file<<space_this(net_str,10,2);
  164. payroll_file<<"\n";
  165.  
  166. }
  167. printf("%-20s|%-7s|%-4s|%-7s|%-4s|%-10s|%-9s|%-10s|\n\n","","","","","","","","");
  168. printf("%-20s %-7s %-4s %12s|%10.2f|%9.2f|%10.2f|\n","","","","Total: ",gross_total,tax_total,net_total);
  169. cout<<endl;
  170. payroll_file<<space_this2("",20,1)<<space_this2("",7,1)<<space_this2("",4,1)<<space_this("Total: ",12,2);
  171. payroll_file<<space_this(gross_total_str,10,2)<<space_this(tax_total_str,9,2)<<space_this(net_total_str,10,2)<<"\n";
  172. payroll_file.close();
  173. cout<<endl;
  174. menu(2);
  175.  
  176.  
  177. }
  178.  
  179. void open_file(){
  180. string contents[125];
  181. int lines=0;
  182. string filename;
  183. cout<<"Enter Filename: ";cin>>filename;
  184. cout<<endl;
  185. if(!rename(filename.c_str(),filename.c_str())){
  186. string content;
  187. ifstream openfile (filename.c_str());
  188. if(openfile.is_open()){
  189. while(getline(openfile,content)){
  190. cout<<content<<endl;
  191. ++lines;
  192. }
  193. for(int i=0;i<lines;i++){
  194. getline(openfile,contents[i]);
  195. }
  196. for(int i=0;i<10;i++){cout<<contents[i];}
  197. }
  198. openfile.close();
  199. } else {cout<<"File Not Found\n\n";}
  200. cout<<endl;
  201. menu(2);
  202. }
  203.  
  204. void rename_file(){
  205. string filename, new_filename;
  206. cout<<"Enter Filename: ";cin>>filename;
  207. cout<<"Enter New Filename: ";cin>>new_filename;
  208. if(!rename(filename.c_str(),new_filename.c_str())){
  209. cout<<"File Renamed\n\n";
  210. } else {cout<<"File Not Found\n\n";}
  211. menu(2);
  212. }
  213.  
  214. void delete_file(){
  215. string filename;
  216. cout<<"Enter Filename: ";cin>>filename;
  217. if(!rename(filename.c_str(),filename.c_str())){
  218. remove(filename.c_str());
  219. cout<<"File Deleted\n\n";
  220. } else {cout<<"File Not Found\n\n";}
  221. menu(2);
  222. }
  223.  
  224. string space_this(string text, int space, int align){
  225. string spaces="";
  226. for(int i=0;i<(space-text.length());i++){spaces+=" ";}
  227. if(align==1){return text+spaces+"|";} else {return spaces+text+"|";}
  228. }
  229.  
  230. string space_this2(string text, int space, int align){
  231. string spaces="";
  232. for(int i=0;i<(space-text.length());i++){spaces+=" ";}
  233. if(align==1){return text+spaces+" ";} else {return spaces+text+" ";}
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement