jeudi 7 avril 2022

How to make function, pointer, array, file in 1 coding? [closed]

Welcome to Honey IT. Feel free to access this website to make a purchased. DEVICE NORMAL PRICE Laptop 800 Tablet 500 Smartphone 400. Create C++ program to help Honey IT creates their own system that can perform as below:

  1. void MainMenu() a. This function will display 3 activities: i. Product List ii. Buy Product iii. Discount Price
  2. void ProductList() a. This function will display all product with the price from device.txt file.
  3. float Product Purchased () a. This function will allow user select buying item and return total price. b. All selected item price will be saved into an array and printed in receipt.txt file.
  4. void Discount () a. This function will receive total price as pointer and calculated the discount. If total>2500, 25% discount from purchased will be deduct. Price after discount will passing into main body using pointer. b. This program will run until user want to exit this system. This system will display the total purchased.

Not my assignment just some exercise for my skill. This is what I have done so far. not complete yet. what did I forgot to put in ?

thank you for your answer. appreciate it.

#include<iostream>
#include<fstream>
using namespace std;

void MainMenu();
void MainMenu(){
    
    cout<<"\n1. Product List"<<endl;
    cout<<"2. Buy Product"<<endl;
    cout<<"3. Discount Price"<<endl;
    cout<<"\n   Enter Your Activities: ";
}

void ProductList();
void ProductList(){
    
    ifstream list("device.txt");
    list.close();
}

float ProductPurchase(float item);
float ProductPurchase(float item){
    
    float buy,price,total;
    char stop;
    ofstream item("receipt.txt");
    total=total+price;
    cout<<"\n Total : "<<total<<endl;
    return total;
}

void Discount(float *price);
void Discount(float *price){
    
    float total,discount,*price;
    
    if(total>2500){
        discount=0.25*total;
        price=total-discount;
    }
    else{
        cout<<"no discount";
    }
    
}

int main(){
    
    char choice, stop;
    int x;
    float buy, price=0;
    
    do{
        MainMenu();
        cin>>x;
        
        if(x==1){
            ProductList();
        }
        else if(x==2){
                
        do{
            cout<<"1. Laptop"<<endl;
            cout<<"2. Tablet"<<endl;
            cout<<"3. Smart phone"<<endl;
        
            cout<<"Item to buy: ";
            cin>>buy;
            
            if(buy==1){
                cout<<"Laptop";
                price=800;
            }
            else if(buy==2){
                price=500;
            }
            else if(buy==3){
                price=400;
            }
        
        }while(stop=='y'||stop=='Y');
        ProductPurchase(buy);
        }
        else if(x==3){
            Discount();
        }
        else{
            cout<<"\n   Invalid. Please try again!"<<endl;
        }
        
        cout<<"\nDo you want to continue (Y||y): ";
        cin>>choice;
        
    }while(choice=='Y'||choice=='y');
    
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire