0% found this document useful (0 votes)
66 views

Bruh I Hate File Handling - CPP

This C++ program is a simple inventory management system for a seller named Syapi. It includes structures to store seller and product data. The main function displays a menu that allows a seller to log in, add multiple product names and prices to a text file, and view the catalog. A customer can view the catalog and select an item to "buy". The program uses files, strings, loops and switches to manage basic seller and shopping functionality.

Uploaded by

Jayson Amodia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Bruh I Hate File Handling - CPP

This C++ program is a simple inventory management system for a seller named Syapi. It includes structures to store seller and product data. The main function displays a menu that allows a seller to log in, add multiple product names and prices to a text file, and view the catalog. A customer can view the catalog and select an item to "buy". The program uses files, strings, loops and switches to manage basic seller and shopping functionality.

Uploaded by

Jayson Amodia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <conio.h>
#include <stdlib.h>
#include <string> //for string functions
#include <fstream> //for file handling
#include <iostream> // for file handling

using namespace std;

//void function for the main menu


void mainMenu(){
printf("=====================================\n");
printf("========= Welcome to Syapi! =========\n");
printf("=====================================\n");
printf("** sana all makatapos c++ project! **\n\n");
printf("Please choose an option from the choices below:\n");
printf("If you are a vendor and want to add items, press 1.\n");
printf("If you are a customer who wants to buy from the catalog, press
2.\n");
printf("If you want to quit, press 3.\n");
printf("Input your choice: ");
}

//structure of seller
struct syapiAccountSeller{
char username[80];
int PIN[80];
char nameProduct[80][80];
int productPrice[80][80];
char buy[80];
};
struct syapiAccountSeller syapiSeller;

//HERE IS THE MAIN


int main(){
int choice,itemQuantity, i;
string output;
char string[80];

//do while loop here


do{
//main menu
mainMenu();
//input for menu
scanf("%d", &choice);
system("cls");

switch(choice){
case 1: {
system("cls");
printf("=== Syapi Seller Log In ===\n");
printf("Enter PIN: ");
scanf("%d", &syapiSeller.PIN[80]);

if (syapiSeller.PIN[80] == 123){
printf("\nLogin successful!\n");
printf("Welcome Syapi Seller!\n\n");

printf("How many items will you add?: ");


scanf("%d", &itemQuantity);

printf("Input the names and prices of the items:\n");


FILE *filePointer = (fopen("products.txt", "w"));
for (i = 0; i < itemQuantity; i++){
scanf("%s", syapiSeller.nameProduct[i]);
fprintf(filePointer," %s",
syapiSeller.nameProduct[i]);
}
fclose(filePointer);
printf("Inputs successful!\n");

printf("These are the contents of the Syapi


catalog:\n\n");
ifstream inFile ("products.txt");
while (inFile) {
std::string output;
getline(inFile, output);
cout << output << endl;
}
inFile.close();
getch();
}
else{
printf("Please try again.");
getch();
}
break;

case 2: {
system("cls");
printf("These are the contents of your catalog:\n\n");
ifstream inFile ("products.txt");
while (!inFile.eof()) {
std::string output;
getline(inFile, output);
cout << output << endl;
}
cin.ignore();
printf("What will you buy?\n");
printf("Input: ");
gets(string);
printf("You bought:");
puts(string);
printf("\nThank you for shopping!");
getch();
break;
}

case 3: {
break;
}

default: {
printf("Wrong input. Please try again.");
getch();
break;
}
}
}
system("cls");
} while (choice !=3);

printf("Thank you for shopping with us!");


return 0;
}

You might also like