Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

help me convert this code

Featured Replies

Can somone pleeeeeeeeeeeeeeeease help me change the following code from c++ to c..... :unsure:

# include <fstream>
# include <iostream>
#include <iomanip>


using namespace std;


class cust
{
private:

char *FirstNameId;
char *LastNameId;
int    num_of_recs;
int    ChkAcctId;
double ChkAcctBal;
double SavAcctBal;
int    PIN;


public:
void setFirstNameId  (char *FirstName)    {FirstNameId = strdup(FirstName);};
void setLastNameId  (char *LastName)    {LastNameId = strdup(LastName);};
void setChkActId     (int ChkId)           {ChkAcctId = ChkId;};
void setChkAcctBal   (double ChkBal)       {ChkAcctBal = ChkBal;};
void setSavAcctBal   (double SavBal)       {SavAcctBal = SavBal;};
void setPIN          (int PIN_num)         {PIN = PIN_num;};
void displayBalance  ();
void depos           (int selec, double depAmnt);
void withdrawl       (int selec, double withdrawalAmnt);
void transferFunds   (int transdirect, double transAmnt);
int  Cust_pin        ()                    {return PIN;};
const char* getFirstNameId()       {return FirstNameId;};
const char* getLastNameId()           {return LastNameId;};
int    getChkActId   ()                    {return ChkAcctId;};
double getChkAcctBal  ()       {return ChkAcctBal;};
double getSavAcctBal ()        {return SavAcctBal;};

};


void cust::displayBalance()
{
cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
cout <<endl<< "\t\t\tChecking Account Balance : $"<<ChkAcctBal<<endl;
cout << "\t\t\tSavings Account Balance  : $"<<SavAcctBal<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
return;
}


void cust::depos(int selec, double deposit)
{
if (selec == 2)
{
 ChkAcctBal = ChkAcctBal + deposit;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout << "\t\t\tDeposited to Checking: $" <<deposit<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}

if (selec == 1)
{
 SavAcctBal = SavAcctBal + deposit;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout << "\t\t\tDeposited to Savings: $"<<deposit<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
}



void cust::withdrawl(int selec, double withdrawalAmnt)
{

if (selec == 1 && (SavAcctBal - withdrawalAmnt >= 0) )
{
 SavAcctBal = SavAcctBal - withdrawalAmnt;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout <<endl<<"\t\t\tWithdrawal Successfull : $"<<withdrawalAmnt<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
else if (selec == 1 && (SavAcctBal - withdrawalAmnt < 0) )
{
 cout << "\t\t\tCannot Complete Transaction"<<endl<<endl;
 cout <<endl<< "\t\t\t    Insufficient Funds"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}

if (selec == 2 && (ChkAcctBal - withdrawalAmnt >= 0))
{
 ChkAcctBal = ChkAcctBal - withdrawalAmnt;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout <<endl<<"\t\t\tWithdrawal Successfull : $"<<withdrawalAmnt<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
else if (selec == 2 && (ChkAcctBal - withdrawalAmnt < 0))
{
 cout <<"\t\t\tCannot Complete Transaction"<<endl<<endl;
 cout <<endl<<"\t\t\t    Insufficient Funds"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
}


void cust::transferFunds (int transdirect, double transAmnt)
{
if ( transdirect == 1 && (SavAcctBal - transAmnt >= 0))
{
 SavAcctBal = SavAcctBal - transAmnt;
 ChkAcctBal = ChkAcctBal + transAmnt;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout << "\t\t\t     Transfer Successful"<<endl<<endl;
 cout << "\t\t\t$"<<transAmnt<<" Transferred into Checking"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
else if (transdirect == 1 && (SavAcctBal - transAmnt < 0))
{
 cout <<"\t\t\tCannot Complete Transaction"<<endl<<endl;
 cout <<"\t\t\t   Insufficient Funds"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
if ( transdirect == 2 && (ChkAcctBal - transAmnt >= 0))
{
 ChkAcctBal = ChkAcctBal - transAmnt;
 SavAcctBal = SavAcctBal + transAmnt;
 cout <<setprecision(2) <<setiosflags(ios::fixed | ios::showpoint);
 cout << "\t\t\t     Transfer Successful"<<endl<<endl;
 cout << "\t\t\t$"<<transAmnt<<" Transferred into Savings"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
else if ( transdirect == 2 && (ChkAcctBal - transAmnt < 0))
{
 cout << "\t\t\tCannot Complete Transaction"<<endl<<endl;
 cout << "\t\t\t    Insufficient Funds"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
}
}

//atm class definition
//#include <iostream.h>
//#include <fstream.h>
//#include <iomanip.h>

class atm
{
private:
int    pin;
int    transtype;
double amnt;
int    transDirec;
int    accnt;

public:
void   setpin();
int    getpin() {return pin;};
int    displayMenu();
int    getAcct();
double getAmnt();
int    getDirection();
void   clear();
void   incorrectPinDisp(int cntr);
char   ContinueDisp();
void   transCompleteDisp();
void   atmGoodbye();

};


void atm::setpin()
{
cout <<endl<<endl<<endl<<endl<<endl;
cout <<"\t\t\t------------------------"<<endl;
cout <<"\t\t\t-      Welcome To      -"<<endl;
cout <<"\t\t\t-      First Bank      -"<<endl;
cout <<"\t\t\t------------------------"<<endl<<endl;
cout <<"\t\t\tEnter your Pin Number: ";
cin  >>pin;
}

int atm::displayMenu()
{
int selection =  0;

while (selection > 5 || selection < 1)
{
 cout <<endl<< "\t\t\t1 - Display Balance"<<endl;
 cout << "\t\t\t2 - Deposit"<<endl;
 cout << "\t\t\t3 - Withdrawl"<<endl;
 cout << "\t\t\t4 - Transfer Funds"<<endl;
 cout << "\t\t\t5 - Exit"<<endl;
 cout << "\t\t\t--------------------"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
 cout << "\t\t\tSelect a Transaction: ";
 cin  >>selection;
 cout <<endl<<endl<<endl<<endl;

 if (selection == 1 || selection == 2 || selection == 3
 || selection == 4 || selection == 5)
 {
 }
 else
 {
 cout <<endl<< "\t\t\tInvalid Selection"<<endl;
 cout << "\t\t\tSelect 1 through 5 : ";
 cin  >> selection;
 }
}
transtype = selection;

return selection;

}


int atm::getAcct()
{

int    acnttype = 0;

while (acnttype < 1 || acnttype > 2)
{
cout <<endl<< "\t\t\t1 - Savings"<<endl;
cout << "\t\t\t2 - Checking"<<endl;
cout << "\t\t\t-------------"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
cout << "\t\t\tSelect Account : ";
cin  >>acnttype;
cin.ignore(100, '\n');

if (acnttype == 1 || acnttype == 2)
{
}
else
{
 cout <<endl<< "\t\t\tInvalid Selection"<<endl;
 cout << "\t\t\tEnter 1 or 2 : ";
 cin  >>acnttype;
 cin.ignore(100, '\n');
}
}
accnt = acnttype;

return acnttype;
}


double atm::getAmnt()
{
double amount = (float) 0.0;

cout <<"\t\t\tPlease Enter Transaction Amount"<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout << "\t\t\tAmount : $";
cin  >>amount;
amnt = amount;

return amount;
}

int atm::getDirection()
{
int direct = 0;
   
while (direct < 1 || direct > 2)
{
cout << "\t\t\t1 - Savings to Checking"<<endl<<endl;
cout << "\t\t\t2 - Checking to Savings"<<endl<<endl;
cout << "\t\t\t-----------------------"<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl;
cout << "\t\t\tEnter a Selection : ";
cin  >>direct;
cin.ignore(100, '\n');

if (direct == 1 || direct == 2)
{
}
else
{
 cout <<endl<< "Re-Enter selection 1 or 2"<<endl<<endl;
}
}
transDirec = direct;

return direct;
}

void atm::incorrectPinDisp(int cntr)
{
if (cntr < 3)
{   cout <<endl<<endl<<endl<<endl<<endl;
    cout <<"\t\t\t------------------------"<<endl;
    cout <<"\t\t\t-      Welcome To      -"<<endl;
    cout <<"\t\t\t-      First Bank      -"<<endl;
    cout <<"\t\t\t------------------------"<<endl<<endl;
 cout <<endl<< "\t\t    Incorrect PIN, Please Re-Enter :";
}
else
{
 cout << "\t\t\tYou Have Entered 3 Incorrect Pin Numbers\n"<<endl;
 cout << "\t\t\t        Please Contact Your Bank"<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl<<endl;
}
}

char atm::ContinueDisp()
{
char cont = 'Y';
cout <<endl<<"\t\t\tWould You Like Another Transaction? Y/N : ";
cin  >>cont;
cin.ignore(100,'\n');
return cont;
}

void atm::atmGoodbye()
{
atm::clear();
cout <<endl<<endl<<endl<<endl<<endl;
cout <<"\t\t\t------------------------"<<endl;
cout <<"\t\t\t-      Thank You       -"<<endl;
cout <<"\t\t\t-  For Banking With Us -"<<endl;
cout <<"\t\t\t-      First Bank      -"<<endl;
cout <<"\t\t\t------------------------"<<endl<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl;
}
 
void atm::clear()
{
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl
 <<endl<<endl<<endl<<endl<<endl;
}



void main()
{
int menuSelec        = 0;
int pinHolder        = 0;
int ArrayNum         = 1;
int cntr             = 1;
int selection        = 0;
int transferDirec    = 0;
   double depAmnt       = (float) 0.0;
   double withdrawlAmnt = (float) 0.0;
double transferAmnt  = (float) 0.0;
char ContSw          = 'Y';


//opens infile, checks if opened correctly.
//if open fails message is displayed.

ifstream custFile;
custFile.open("test.txt");
 if (!custFile)
 {
 cout << "Unable to Access Bank Records"<<endl;
 exit(1);
 };
 
//opens output file, checks if opened correctly.
//if opens fails message is displayed.

ofstream custUpdate;
custUpdate.open("recordUpdate.txt");
 if (!custUpdate)
 {
 cout << "Error Opening Outfile"<<endl;
 exit(1);
 };
 
int numrecs = 0;
custFile >> numrecs;
cust custArray[50];
atm atm;


char FirstName[25][80];

//char LastName[25];
int    ChkId;
double ChkBal;
double SavBal;
int    PIN_num;


int x = 0;    

while(!custFile.eof()){
 custFile>>FirstName[x]>>ChkId>>ChkBal>>SavBal>>PIN_num;

 x++;
}
// while (custFile >> FirstName>>ChkId>> ChkBal >> SavBal >>   PIN_num )
// {
//   custArray[x].setFirstNameId(FirstName[x]);
//   //custArray[x].setLastNameId(LastName[x]);
//   custArray[x].setChkActId(ChkId);
//   custArray[x].setChkAcctBal(ChkBal);
//   custArray[x].setSavAcctBal(SavBal);
//   custArray[x].setPIN(PIN_num);
//   x++;
 
// }


custFile.close();


atm.setpin();
atm.clear();
pinHolder = atm.getpin();
x = 0;

while (cntr < 4)
{
 for ( x = 0; x < numrecs; x++)
 {
 
 if (pinHolder  == custArray[x].Cust_pin())
   {
    ArrayNum = x;
    cntr = 4;
    break;

 }
 
 }
 
   if ( x == numrecs)
   {
 
   if (cntr < 3)
   {
   atm.incorrectPinDisp(cntr);
   cin >> pinHolder;
   atm.clear();
   cntr++;
   }
   else
   {
   atm.incorrectPinDisp(cntr);
   exit(0);
   }
 
  }

}


   do
{  
 if (toupper(ContSw) == 'Y')
 {
  menuSelec = atm.displayMenu();
 }
 else if (toupper(ContSw) == 'N' || menuSelec == 5)
 {
 atm.atmGoodbye();
 break;
 }

   switch (menuSelec)
   {
    case 1:
 atm.clear();
     custArray[ArrayNum].displayBalance();
 ContSw = atm.ContinueDisp();
 atm.clear();
 break;

    case 2:
 atm.clear();
     selection = atm.getAcct();
 atm.clear();
     depAmnt = atm.getAmnt();
 atm.clear();
     custArray[ArrayNum].depos( selection, depAmnt);
 ContSw = atm.ContinueDisp();
 atm.clear();
 break;

    case 3:
 atm.clear();
 selection = atm.getAcct();
 atm.clear();
     withdrawlAmnt = atm.getAmnt();
 atm.clear();
     custArray[ArrayNum].withdrawl( selection, withdrawlAmnt);
 ContSw = atm.ContinueDisp();
 atm.clear();
 break;

    case 4:
 atm.clear();
 transferDirec = atm.getDirection();
 atm.clear();
 transferAmnt = atm.getAmnt();
 atm.clear();
 custArray[ArrayNum].transferFunds (transferDirec, transferAmnt);
 ContSw = atm.ContinueDisp();
 atm.clear();
 break;
   
    case 5:
 atm.atmGoodbye();
   }
   
}while (menuSelec != 5);


if (toupper (ContSw) == 'N' || menuSelec == 5)
{

 custUpdate <<numrecs<<endl<<endl;

 for ( x = 0; x < numrecs; x++)
   
 { //for (y = 0;; y++){
   strcpy(FirstName[x],custArray[x].getFirstNameId());
   //LastName[x] = custArray[x].getLastNameId();
   ChkId = custArray[x].getChkActId();
   ChkBal= custArray[x].getChkAcctBal();
   SavBal = custArray[x].getSavAcctBal();
   PIN_num = custArray[x].Cust_pin();
   
   custUpdate <<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
   custUpdate <<FirstName << " "  << ChkId <<" "<<ChkBal
   <<" "<<SavBal<<" "<<PIN_num<<endl<<endl;
 }

 custUpdate.close();

}

}


  • Author

you mean this code can be directly compiled to C!!! name some of these compilers for me please...

why? because i need the code in pure C...

code get compiled to machine code, wether it is c++, or c a real compiling will take it to machine code, both c and c++ allow you to resue objects, all you need to do is compile it then load it and you can access the functions from c, c++, Java etc.

What do you want to do with the code, and I can tell you what you need to do with it.

  • Author

well...its an assignment i m supposed to do...for my Programming class. :blushing:

I have to give them the code!!!! and obviously it has to be in C....my lecturer is stupid but i suspect he can tell the difference between C and machine code :lol:

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.