ความพยามในการสร้างโปรเเกรมบันทึกรายรับรายจ่าย ที่สามารถเซฟข้อมูลได้ ของผมด้วย c++ (ยังไม่เสร็จช่วยด้วย)

คือผมกำลังศึกษา c++ อยู่ เลยคิดโจทย์สร้างโปรเเกรมรายจ่ายประจำวันเเบบเซฟได้ ไว้ใช้เอง  เเละผมก็ติดปัญหาไม่รู้ว่าจะให้มันเซฟได้ยังไง เมื่อวานถามเเล้ว มีคนเเนะนำให้ใช้ json ครับเเต่ทำไม่เป็น ผมเลยลองเปิดหนังสืออ่าน เเละได้ลองนำ #include<fstream> มาใช้ เป็นการเก็บข้อมูลในโปรเเกรมลงไฟล์ .txt ก็ถือว่าพัฒนาขึ้นมาหน่อย เเต่มันก็เซฟไม่ได้อยู่ดี พอทำอีกรอบข้อมูลเก่าก็หายหมด สรุปคำถามที่ผมอยากถามคือ
1.มีวิธีการดัดเเปลง เเบบให้ข้อมูล input ทุกรอบที่ใส่ในโปรเเกรม บันทึกอยู่ในไฟล์ ด้วยการใช้ fstream หรืออย่างอื่นได้ไหม
2.หรือเเนะนำวิธีอื่นๆก็ได้ครับ ผมมีเป้าหมายอยากจะบันทึกข้อมูล ด้วย โปรเเกรม c++ ที่ตัวเองสร้างตอนนี้
3.มีวิธีเพิ่ม เวลา ในโปรเเกรมไหมครับ เเบบให้ระบบบันทึกไว้ว่า input ข้อมูลนั้นตอนเวลาไหน มีcode ไหนที่ทำได้ไหม 
4.ระบบการเซฟ input หรือ โหลดข้อมูล ใน c++ มันทำยังไงกันเเน่ครับ
ผมอธิบายเข้าใจยากหน่อยเพราะผมมือใหม่ ขอบคุณทุกท่านนะครับ ผมจะ เเปะ code ไว้ ผมทำเเบบเป็นเเนว atm อะครับ เป้าหมายตอนนี้คือหาวิธีบันทึกข้อมูล input ทั้งหมดให้ได้

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void line();
int main()
{
  int option,choice,choicee,choiceee;
  float currentmoney ,deposit,depositcurrentmoney,withdraw,moneyleft,dwcmoney,depositafterwithdrawmoney,depositafterwithdraw;
  string name;
  
  ofstream writefile;
  writefile.open("bank.txt");
  
  
  line();
  cout<<"          HELLO ER"<<endl;
  cout<<"Please enter your name mother er"<<endl<<endl;
  cout<<":";
  cin>>name;
  writefile<<"Name :"<<name<<endl;
  
  cout<<"Welcome to money saving program Mr.:"<<name<<endl;
  cout<<"First add your current money :";
  cin>>currentmoney;
  cout<<"Please select option you want"<<endl;
  cout<<"1.Check your current money"<<endl;
  cout<<"2.Deposit your money"<<endl;
  cout<<"3.withdraw your money"<<endl;
  cout<<"4.Exit the program"<<endl;
  line();
  cout<<"Enter your option :";
  cin>>option;
    switch(option)
    {
      case 1:
        cout<<"Your current money is :"<<currentmoney<<endl;
        cout<<"1.Deposit your money"<<endl;
        cout<<"2.withdraw your money"<<endl;
        cout<<"3.Exit the program"<<endl;
        cout<<"Choose option you want :";
        cin>>choice;
        void line();
        switch(choice){
          case 1:
          cout<<"Amount money you want to deposit :";
          cin>>deposit;
          depositcurrentmoney = currentmoney+deposit;
          cout<<"Your current money is :"<<depositcurrentmoney<<endl;
          
          writefile<<"check and deposit money"<<endl;
          writefile<<"Current money :"<<depositcurrentmoney<<endl;
          writefile<<"Amount money you just deposit :"<<deposit<<endl;
          writefile<<"Money you have before deposit :"<<currentmoney<<endl;
          
          break;
          case 2:
          cout<<"Amout money you want to withdraw :";
          cin>>withdraw;
          moneyleft = currentmoney-withdraw;
          cout<<"Your current money is :"<<moneyleft<<endl;
          
          writefile<<"check and withdraw money"<<endl;
          writefile<<"Current money :"<<moneyleft<<endl;
          writefile<<"Amount money you just withdraw :"<<withdraw<<endl;
          writefile<<"Money you have before withdraw :"<<currentmoney<<endl;
      
          break;
          case 3:
          cout<<"Program close"<<endl;
          writefile<<"check and close program"<<endl;
          writefile<<"Current money :"<<currentmoney<<endl;
          break;
        }    
      break;
      case 2:
        cout<<"Amount money you want to deposit :";
        cin>>deposit;
        depositcurrentmoney = currentmoney+deposit;
        cout<<"Your current money is :"<<depositcurrentmoney<<endl;
        cout<<"1.Check your current money"<<endl;
        cout<<"2.withdraw your money"<<endl;
        cout<<"3.Exit the program"<<endl;
        cout<<"Choose option you want :";
        cin>>choicee;
        switch(choicee)
        {
          case 1:
          cout<<"Your current money is :"<<depositcurrentmoney<<endl;
          
          writefile<<"Deposit and check money"<<endl;
          writefile<<"Current money :"<<depositcurrentmoney<<endl;
          writefile<<"money before deposit :"<<currentmoney<<endl;
          writefile<<"money you just deposit:"<<deposit<<endl;
          
          break;
          case 2:
          cout<<"Amout money you want to withdraw :";
          cin>>withdraw;
          dwcmoney=depositcurrentmoney-withdraw;
          cout<<"Your current money is :"<<dwcmoney<<endl;
          
          writefile<<"Deposit and withdraw money"<<endl;
          writefile<<"Current money :"<<dwcmoney<<endl;
          writefile<<"Amount money you just deposit :"<<deposit<<endl;
          writefile<<"Amount money you just withdraw :"<<withdraw<<endl;
          writefile<<"Money you have before deposit and withdraw :"<<currentmoney<<endl;
          
          break;
          case 3:
          cout<<"program Close"<<endl;
          
          writefile<<"Deposit and exit program "<<endl;
          writefile<<"Current money"<<depositcurrentmoney<<endl;
          writefile<<"Money you have before deposit :"<<currentmoney<<endl;
          
          return 0;
        }
      break;
      case 3:
        cout<<"Amout money you want to withdraw :";
        cin>>withdraw;
        moneyleft = currentmoney-withdraw;
        cout<<"Your current money is :"<<moneyleft<<endl;
        cout<<"1.Check your current money"<<endl;
        cout<<"2.Deposit your money"<<endl;
        cout<<"3.Exit the program"<<endl;
        cout<<"Choose option you want :";
        cin>>choiceee;
        switch(choiceee){
          case 1:
          cout<<"Your current money is :"<<moneyleft<<endl;
          
          writefile<<"withdraw and check money"<<endl;
          writefile<<"Current money :"<<moneyleft<<endl;
          writefile<<"Money you have before withdraw :"<<currentmoney<<endl;
          writefile<<"Amount money you just withdraw :"<<withdraw<<endl;
          
          break;
          case 2:
          cout<<"Amout money you want to deposit :";
          cin>>depositafterwithdraw;
          depositafterwithdrawmoney=moneyleft+depositafterwithdraw;
          cout<<"Your current money is :"<<depositafterwithdrawmoney<<endl;
          
          writefile<<"withdraw and deposit"<<endl;
          writefile<<"Current money :"<<depositafterwithdrawmoney<<endl;
          writefile<<"Money before withdraw and deposit :"<<currentmoney<<endl;
          writefile<<"withdraw money :"<<withdraw<<endl;
          writefile<<"deposit money :"<<depositafterwithdraw;
          
          break;
          case 3:
          cout<<"Program close"<<endl;
          
          writefile<<"Withdraw and close program"<<endl;
          writefile<<"Current money :"<<moneyleft<<endl;
          writefile<<"Amount money you just withdraw :"<<withdraw<<endl;
          
          return 0;
      
        }
        break;
      case 4:
        cout<<"Program Close"<<endl;
        
        writefile<<"Close program"<<endl;
        writefile<<"Current money :"<<currentmoney<<endl;
        
        return 0;
        break;
    }
    
  return 0;
}
void line()
{
  cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
}
แก้ไขข้อความเมื่อ
คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 1
ศึกษาเรื่อง serialization ครับ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่