FunnyVALENTINE
D4C LOVE TRAIN
- Joined
- Apr 19, 2026
- Posts
- 1,523
- Reputation
- 1,534
C++:
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<cctype>
#include<filesystem>
#include<algorithm>
#include<random>
#include<bitset>
#include<set>
#include<string_view>
#include<memory>
#include<cmath>
#include<fstream>
#include<limits>
#include<sstream>
using std::vector;
using std::string;
using std::unordered_map;
using std::bitset;
using std::cout;
using std::cin;
using std::cerr;
class item
{
public:
string item_Name{};
long long item_quantity{};
long double item_cost{};
long double total_cost{};
bool existing_item{};
void input()
{
bool name_valid{};
do{
name_valid = true;
existing_item = false;
cout<<"Enter the name of the item: ";
std::getline(cin,item_Name);
if(item_Name.length() < 4 || item_Name.length() > 20)
{
cout<<"Name should not be less than 4 or more than 20 characters\n";
name_valid = false;
continue;
}
bool itemExists(const string& name);
if(itemExists(item_Name))
{
cout<<"Item Exists\n";
existing_item = true;
return;
}
for(char a: item_Name)
{
if(!std::isalpha(static_cast<unsigned char>(a)))
{
cout<<"Name should only be Alphabets\n";
name_valid = false;
break;
}
}
if(!name_valid)
{
continue;
}
}while(!name_valid);
//Asking quantity of item
while(true)
{
cout<<"Enter the Quantity of the item: ";
if(cin>>item_quantity)
{
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
break;
}
cout << "Quantity should only contain numbers.\n";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
};
//Asking Cost of Item
while(true)
{
cout<<"Enter the Cost of the item: ";
if(cin>>item_cost)
{
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
break;
}
cout << "Cost should only be numbers.\n";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
};
//Calculating total cost
total_cost = static_cast<long double>(item_quantity * item_cost);
}
};
int main()
{
item a{};
int option{};
do{
cout<<"1.Input a new Item"<<'\n';
cout<<"2.Modify an existing item's quantity"<<'\n';
cout<<"3.Modify an existing item's cost"<<'\n';
cout<<"4.Delete an Item"<<'\n';
cout<<"5.Exit"<<'\n';
cout<<'\n';
cout<<"Enter a value between 1-5 to begin operation: ";
cin>>option;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << '\n';
if(option == 1)
{
a.input();
if(!a.existing_item)
{
if (!std::filesystem::exists("database.csv"))
{
std::ofstream abc{"database.csv"};
abc << "Name,Quantity,Cost,Total Cost\n";
}
std::ofstream abc{"database.csv", std::ios::app};
abc << a.item_Name << ','
<< a.item_quantity << ','
<< a.item_cost << ','
<< a.total_cost << '\n';
}
}
else if(option == 2)
{
vector<string> lines{};
string line{};
std::ifstream tyu{"database.csv"};
std::getline(tyu,line);
while(std::getline(tyu,line))
{
lines.push_back(line);
}
string new_item{};
cout<<"Enter the name of item you wanna modify?: ";
std::getline(cin,new_item);
cout<<'\n';
for(int i = 0; i < lines.size(); ++i)
{
std::stringstream ss(lines[i]);
string name{};
std::getline(ss, name, ',');
if(name == new_item)
{
std::string quantity;
std::string cost;
std::getline(ss, quantity, ',');
std::getline(ss, cost, ',');
int new_quantity{};
cout<<"Enter New Quantity: ";
cin>>new_quantity;
long double new_cost = std::stold(cost);
long double total = new_quantity * new_cost;
lines[i] = name + "," +
std::to_string(new_quantity) + "," +
cost + "," +
std::to_string(total);
std::ofstream out("database.csv");
out << "Name,Quantity,Cost,Total Cost\n";
for (const auto& record : lines)
{
out << record << '\n';
}
}
}
}
else if(option == 3)
{
vector<string> lines{};
string line{};
std::ifstream tyu{"database.csv"};
std::getline(tyu,line);
while(std::getline(tyu,line))
{
lines.push_back(line);
}
string new_item{};
cout<<"Enter the name of item you wanna modify?: ";
std::getline(cin,new_item);
cout<<'\n';
for(int i = 0; i < lines.size(); ++i)
{
std::stringstream ss(lines[i]);
string name{};
std::getline(ss, name, ',');
if(name == new_item)
{
std::string quantity;
std::string cost;
std::getline(ss, quantity, ',');
std::getline(ss, cost, ',');
long double new_cost{};
cout<<"Enter New Cost: ";
cin>>new_cost;
long long new_QUANTITY = std::stoll(quantity);
long double new_total = static_cast<long double>(new_cost * new_QUANTITY);
lines[i] = name + "," +
quantity + "," +
std::to_string(new_cost) + "," +
std::to_string(new_total);
std::ofstream out("database.csv");
out << "Name,Quantity,Cost,Total Cost\n";
for (const auto& record : lines)
{
out << record << '\n';
}
}
}
}
else if(option == 4)
{
vector<string> lines{};
string line{};
std::ifstream tyu{"database.csv"};
std::getline(tyu,line);
while(std::getline(tyu,line))
{
lines.push_back(line);
}
string new_item{};
cout<<"Enter the name of item you wanna delete?: ";
std::getline(cin,new_item);
cout<<'\n';
for(int i = 0; i < lines.size(); ++i)
{
std::stringstream ss(lines[i]);
string name{};
std::getline(ss, name, ',');
if(name == new_item)
{
string quantity{};
string cost{};
string total{};
std::getline(ss, quantity, ',');
std::getline(ss, cost, ',');
std::getline(ss,total,',');
lines[i] = name + ',' + quantity + ',' + cost + ',' + total;
lines.erase(lines.begin() + i);
std::ofstream out("database.csv");
out << "Name,Quantity,Cost,Total Cost\n";
for (const auto& record : lines)
{
out << record << '\n';
}
break;
}
}
}
else if(option == 5)
{
cout<<"Saving.....\n";
}
}while(option !=5);
return 0;
}
bool itemExists(const string& name)
{
string stored_data{};
std::ifstream def{"database.csv"};
std::getline(def, stored_data);
while(std::getline(def, stored_data))
{
std::stringstream ss(stored_data);
string Item_name{};
std::getline(ss,Item_name,',');
if(Item_name == name)
{
cout<<"Checking.......\n";
return true;
}
}
return false;
}
THE CODE ABOVE IS A STOCK MANAGEMENT SYSTEM.
@Jason Voorhees help me my nigga

I want you to do 2 things.
1.Check my code and compare it to professional level
.2.Tell me how should i Improve
.Also I'm going to learn Qt and Opengl in this month .
So i can make GUI based Applications.
Last edited:



?
you are sus