C++ 计费管理系统

C++ 计费管理系统

C++编写的超市计费项目 – 这个C++超市计费系统是一个简单的控制台程序,没有任何图形界面。通过这个项目,您将学习如何使用流类和管理C++编程语言中的文件。

什么是超市账单

超市计费系统旨在帮助超市计算和显示发票,以提供更快速、更有效的客户服务。这个软件解决方案的用户界面既高效又用户友好,有助于员工进行客户服务和账单计算。

为什么超市需要计费系统

由于计费软件是各类杂货店企业的最佳选择之一,他们可以使他们的资金有条不紊。一个好的计费程序可以保持准确的财务记录,消除人为的数据输入错误。

超市计费系统有哪些功能

通过确保计费系统透明,并为购买的商品准确标明价格,超市计费系统有助于保持顾客和店铺管理之间良好的关系。它促进并保证了消费者的支付。

导入必要的库

作为第一步,要确定我们的软件需要哪些C++库。这些将在演示开始时给出。我们使用 #include 从库中导入头文件,iostream 是我们的应用程序所需的第一个库。我们将使用这个库来使用C++基本输入和输出管理我们的超市计费项目。

程序分解

# include < iostream >
# include < process.h >
# include < fstream >
# include < stdlib.h >

我们将导入所有必要的库来避免任何类型的错误。

class head
{
    char Iname [ 50 ] [ 50 ] ;
public :
    int totalitems ;
    float Qty [ 3 ] ;
    float price [ 3 ] ;
    int vatprice [ 3 ] ;
    int tprice [ 3 ] ;
    void input ( ) ;
    void output ( ) ;
} ;

在上述代码中,我们创建了一个名为head的类,它有成员函数name、total items、quantity、price、input和output。

class vat : public head
{
    float vats ;
public :
    void vatcal ( ) ;
    void outputs ( ) ;
    void sum ( ) ;
} ;

在上面的代码片段中,我们派生了一个从类head继承的类vat。

void head : : input ( )
{
    system ( " CLS " ) ;
    cout << " \ nEnter number of items = " ;
    cin >> totalitems ;
    for ( int i = 0 ; i < totalitems ; i + + )
    {
        cout << " \ n Enter name of item " << i + 1 << " : " ;
        cin >> Iname [ i ] ;
        cout << " Enter quantity : " ;
        cin >> Qty [ i ] ;
        cout << " Enter price of item " << i + 1 << " : " ;
        cin >> price [ i ] ;
        tprice [ i ] = Qty [ i ] * price [ i ] ;
    }
}

在上述场景中,它将负责输入,如添加物品的数量、物品的名称、输入物品的数量和价格。

void head : : output ( )
{
    int a ;
    ifstream infile ( " COUNT . TXT " ) ;
    infile >> a ;
    ofstream outfile ( " COUNT . TXT " ) ;
    a + = 1 ;
    outfile << a ;
    outfile . close ( ) ;
    { ofstream outfile ( " HIS . TXT " , ios : : app ) ;
    outfile << endl << " Bill No . : " << a << endl ;
    outfile << " ------------------------------------------------------------------------ " << endl ;
cout << " \ n " ;
    cout << " Name of Item \ t Quantity Price Total Price \ n " ;
    for ( int i = 0 ; i < totalitems ; i + + )
    {
        outfile << " Name : " << Iname [ i ] << " Qty : " << Qty [ i ] << " Price : " << tprice [ i ] << endl ;
        cout << Iname [ i ] << " \ t \ t " << Qty [ i ] << " \ t " << price [ i ] << " \ t " << tprice [ i ] << ' \ n ' ;
    }
    outfile << " ------------------------------------------------------------------------ " << endl ;
    outfile . close ( ) ;
    }
}

上面的代码片段负责显示用户输入的项目。

void vat : : vatcal ( )
{
    input ( ) ;
    for ( int i = 0 ; i < totalitems ; i + + )
    {
        if ( price [ i ] < = 100.00 )
        {
            vatprice [ i ] = tprice [ i ] + ( 0.03 * tprice [ i ] ) ;
        }
        else
        {
            vatprice [ i ] = tprice [ i ] + ( 0.1 * tprice [ i ] ) ;
        }
    }
} void vat : : vatcal ( )
{
    input ( ) ;
    for ( int i = 0 ; i < totalitems ; i + + )
    {
        if ( price [ i ] < = 100.00 )
        {
            vatprice [ i ] = tprice [ i ] + ( 0.03 * tprice [ i ] ) ;
        }
        else
        {
            vatprice [ i ] = tprice [ i ] + ( 0.1 * tprice [ i ] ) ;
        }
    }
}

上述代码用于计算用户输入的物品数量。

void vat : : outputs ( )
{
    output ( ) ;

    float cash = 0 , sum = 0 , qty = 0 , sumt = 0 ;

    for ( int i = 0 ; i < totalitems ; i + + )
    {
           sumt + = tprice [ i ] ;
         sum + = vatprice [ i ] ;
         qty + = Qty [ i ] ;
    }
    cout << " \ n Total : " ; 
    cout << " \ n ------------------------------------------------------------------------------ " ;
    cout << " \ n \ t Quantity = " << qty << " \ t \ t Sum = " << sumt << " \ tWith Vat : " << sum ;
    cout << " \ n------------------------------------------------------------------------------ " ;

pay :

    cout << " \ n \ n \ t \ t \ t **** PAYMENT SUMMARY **** \ n " ;
    cout << " \ n \ t \ t \ t Total cash given : " ;
    cin >> cash ;

    if ( cash > = sum )
        cout << " \ n \ t \ t \ t Total cash repaid : " << cash-sum << ' \ n ' ;

    else
    {   cout << " \ n \ t \ t \ t Cash given is less than total amount!!! " ;

    goto pay ;
    }
}

上面的代码用于显示用户输入的物品的计算价格。

int passwords ( )
{

    char p1 , p2 , p3 ;

    cout << " \ n  \ n \ n \ n \ n \ n \ t \ t \ t ENTER THE PASSWORD : " ;

    cin >> p1 ;
    cout << " * " ;
    cin >> p2 ;
    cout << " * " ;
    cin >> p3 ;
    cout << " * " ;

    if ( ( p1 == ' s ' || p1 == ' S ' ) && ( p2 == ' i ' || p2 == ' I ' ) && ( p3 == ' d ' || p3 == ' D ' ) )

        return 1 ;

    else
        return 0 ;
}

上面的代码片段将帮助用户在结算系统中输入密码。这将帮助用户维护超市结算系统的安全性。

int main ( )
{
    vat obj ;
    char opt , ch ;
    int a = 1 ;
    ifstream fin ;

    a==passwords ( ) ;
    if ( ! a )
    {
        for ( int i = 0 ; i < 2 ; i + + )
        {
            cout << " \ n Wrong password try once more \ n " ;
            if ( passwords ( ) ) 
            {
                goto last ;
            }
            else
            {
                cout << " \ n \ n \ t \ t \ t all attempts failed ..... " ;
                cout << " \ n \ n \ n \ t \ t \ t see you .................. " ;
                exit ( 0 ) ;
            }

        }
        cout << " \ t \ t \ t sorry all attempts failed ............. \ n \ t \ t \ t inactive " ;
             }

以上代码将是我们超市计费系统的驱动代码。用户将被要求输入密码。如果用户输入的密码错误,则会显示密码错误,请重试。

else {
last : ;
     do {
start :
    system ( " PAUSE " ) ;
    system ( " CLS " ) ;
    cout << " \ n \ n \ t \ t \ t ------------------------------ " ;
    cout << " \ n \ t \ t \ t Billing Management System " ;
    cout << " \ n \ t \ t \ t ------------------------------ " ;
     cout <<"\n\n\t\t\tWhat you want to do?";
     cout<<"\n\t\t\t1.\tTo enter new entry\n\t\t\t2.\tTo view previous entries\n\t\t\t3.\tExit\n";
     cout<<"\n\nEnter your option: ";
     cin>>opt;

如果用户输入了正确的密码,那么上面的循环将开始执行。

switch ( opt )
     {
     case ' 1 ' :
         obj . vatcal ( ) ;

         obj . outputs ( ) ;
         goto start ;
     case ' 2 ' :

         fin . open ( " HIS . TXT " , ios : : in ) ;
         while ( fin . get ( ch ) )
         {
             cout << ch ;
         }
         fin . close ( ) ;

         goto start ;
     case ' 3 ' : 
         exit ( 0 ) ;
     default :
         cout << " \ a " ;
     }

     } while ( opt ! = 3 ) ;
    }
    return 0 ;
}

上面的循环将根据用户选择的选项运行。

超市计费系统程序

#include<iostream>
#include<process.h>
#include<fstream>
#include <stdlib.h>
using namespace std;
class head
{
    char Iname[50][50];

public:
    int totalitems;
    float Qty[3];
    float price[3];
    int vatprice[3];
    int tprice[3];
    void input();
    void output();
};
class vat:public head
{
    float vats;
public:
    void vatcal();
    void outputs();
    void sum();
};

//******************************************************************
//      INPUT FUNCTION
//******************************************************************

void head::input()
{
    system("CLS");
    cout<<"\nEnter number of items= ";
    cin>>totalitems;

    for(int i=0; i<totalitems; i++)
    {
        cout<<"\nEnter name of item "<<i+1<<": ";
        cin>>Iname[i];
        cout<<"Enter quantity: ";
        cin>>Qty[i];
        cout<<"Enter price of item "<<i+1<<": ";
        cin>>price[i];
        tprice[i]=Qty[i]*price[i];
    }
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//     OUTPUT FUNCTION
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
void head::output()
{
    int a;

    ifstream infile("COUNT.TXT");
    infile>>a;

    ofstream outfile("COUNT.TXT");
    a+=1;
    outfile<<a;
    outfile.close();

    {ofstream outfile("HIS.TXT", ios::app);
    outfile<<endl<<"Bill No.: "<<a<<endl;
    outfile<<"------------------------------------------------------------------------"<<endl;
cout<<"\n";
    cout<<"Name of Item\tQuantity   Price  Total Price\n";
    for(int i=0;i<totalitems;i++)
    {
        outfile<<"Name: "<<Iname[i]<<" Qty: "<<Qty[i]<<" Price: "<<tprice[i]<<endl;
        cout<<Iname[i]<<"\t\t"<<Qty[i]<<"\t   "<<price[i]<<"\t   "<<tprice[i]<<'\n';
    }

    outfile<<"------------------------------------------------------------------------"<<endl;
    outfile.close();
    }
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//     VAT CALCULATION
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
void vat::vatcal()
{
    input();
    for(int i=0;i<totalitems;i++)
    {
        if(price[i]<=100.00)
        {
            vatprice[i]=tprice[i]+(0.03*tprice[i]);
        }
        else
        {
            vatprice[i]=tprice[i]+(0.1*tprice[i]);
        }
    }
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//      VAT OUTPUTS
//*  * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * *  
void vat::outputs()
{
    output();

    float cash=0,sum=0,qty=0,sumt=0;

    for(int i=0;i<totalitems;i++)
    {
           sumt+=tprice[i];
           sum+=vatprice[i];
           qty+=Qty[i];
    }
    cout<<"\nTotal:";
    cout<<"\n------------------------------------------------------------------------------";
    cout<<"\n\tQuantity= "<<qty<<"\t\t Sum= "<<sumt<<"\tWith Vat:"<<sum;
    cout<<"\n------------------------------------------------------------------------------";

pay:

    cout<<"\n\n\t\t\t * * * * PAYMENT SUMMARY * * * * \n";
    cout<<"\n\t\t\tTotal cash given: ";
    cin>>cash;

    if(cash>=sum)
        cout<<"\n\t\t\tTotal cash repaid: "<<cash-sum<<'\n';

    else
    {   cout<<"\n\t\t\tCash given is less than total amount!!!";

    goto pay;
    }
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//      PROTECTION PASSWORD
//* * * * * * * * * * * *  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

int passwords()
{

    char p1,p2,p3;

    cout<<"\n\n\n\n\n\n\t\t\tENTER THE PASSWORD: ";

    cin>>p1;
    cout<<"*";
    cin>>p2;
    cout<<"*";
    cin>>p3;
    cout<<"*";

    if ((p1=='s'||p1=='S')&&(p2=='i'||p2=='I')&&(p3=='d'||p3=='D'))

        return 1;

    else
        return 0;
}
// END of Password.

//****************************************************************
//      THE MAIN FUNCTION OF PROGRAM
//****************************************************************


int main()
{
    vat obj;
    char opt, ch;
    int a=1;
    ifstream fin;

    a==passwords();
    if(!a)
    {
        for(int i=0;i<2;i++)
        {
            cout<<"\nWrong password try once more\n";
            if(passwords())
            {
                goto last;
            }
            else
            {
                cout<<"\n\n\t\t\t all attempts failed.....";
                cout<<"\n\n\n\t\t\t see you.................. ";
                exit(0);
            }

        }
        cout<<"\t\t\t sorry all attempts failed............. \n \t\t\tinactive";
             }
    else{
last:; 
     do{
start:
    system("PAUSE");
    system("CLS");
    cout<<"\n\n\t\t\t------------------------------";
    cout<<"\n\t\t\tBilling Management System";
    cout<<"\n\t\t\t------------------------------";
     cout<<"\n\n\t\t\tWhat you want to do?";
     cout<<"\n\t\t\t1.\tTo enter new entry\n\t\t\t2.\tTo view previous entries\n\t\t\t3.\tExit\n";
     cout<<"\n\nEnter your option: ";
     cin>>opt;
     switch(opt)
     {
     case'1':
         obj.vatcal();

         obj.outputs();
         goto start;
     case'2':

         fin.open("HIS.TXT", ios::in);
         while(fin.get(ch))
         {
             cout<<ch;
         }
         fin.close();

         goto start;
     case'3':
         exit(0);
     default:
         cout<<"\a";
     }

     }while(opt!=3);
    }
    return 0;
}

输出:

ENTER THE PASSWORD: 123
***Press any key to continue . . .
                       ---------------------------------------
                        Billing Management System
                        ---------------------------------------
                        What you want to do?
                        1.      To enter new entry
                        2.      To view previous entries
                        3.      Exit
Enter your option: 1

Enter number of items= 3
Enter name of item 1: Vegetables
Enter quantity: 1kg
Enter price of item 1:
Enter name of item 2: Enter quantity: Enter price of item 2:
Enter name of item 3: Enter quantity: Enter price of item 3:
Name of Item    Quantity   Price  Total Price
Vegetables              1          0       0
                0          1.4013e-045     0
                1.13027e-038       0       0

Total:
------------------------------------------------------------------------------
        Quantity= 1              Sum= 0 With Vat:0
------------------------------------------------------------------------------

                        ****PAYMENT SUMMARY****

                        Total cash given:
                        Total cash repaid: 0
Press any key to continue . . .

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程