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

Hehe Shibe

The document defines functions for inputting, outputting, deleting, sorting and displaying inventory items. It includes struct definitions for items and functions for menu navigation, counting items, and the core operations.

Uploaded by

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

Hehe Shibe

The document defines functions for inputting, outputting, deleting, sorting and displaying inventory items. It includes struct definitions for items and functions for menu navigation, counting items, and the core operations.

Uploaded by

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

#include <iostream>

#include <cstring>

using namespace std;

struct mh{

int ma;

string ten;

int solg;

int gia;

int don;

};

void nhap(mh ds[]);

void xuat(mh ds[]);

void xoa(mh ds[]);

void sx(mh ds[]);

void menu();

int dem(mh ds[], int);

int main (){

mh ds[1000];

cout << "nhap ma hang hoa : ";

cin >> ds[1].ma;

fflush(stdin);

cout << "nhap ten hang hoa : ";

getline (cin, ds[1 ].ten);

cout << "so luong hang ton kho : ";

cin >> ds[1 ].solg;

cout << "don gia ton kho : ";

cin >> ds[1 ].gia;


cout << "don gia ban : ";

cin >> ds[1].don;

int k;

menu ();

cin >> k;

while (k != 0){

if ( k== 1) {

nhap (ds);

menu ();

cin >> k;

if ( k== 2) {

xoa ( ds);

menu();

cin >> k;

if (k == 3){

sx (ds);

menu ();

cin >> k ;

if (k == 4){

xuat (ds);

menu ();

cin >> k;

}
int dem (mh ds[], int b){

for (int i=1; ds[i].ma !=0 ; i++){

b= b+1;

return b;

void nhap( mh ds[]){

int a=0;

cout << "nhap ma hang hoa : ";

cin >> ds[dem(ds, a) + 1].ma;

cin.ignore(100, '\n');

cout << "nhap ten hang hoa : ";

getline (cin, ds[dem(ds, a) ].ten);

cout << "so luong hang ton kho : ";

cin >> ds[dem(ds, a) ].solg;

cout << "don gia ton kho : ";

cin >> ds[dem(ds, a) ].gia;

cout << "don gia ban : ";

cin >> ds[dem(ds, a) ].don;

for (int i= 1; i<= dem(ds, a)-1; i++){

if ( ds[i].ma == ds[dem(ds, a) ].ma){

ds [i].solg += ds[dem(ds, a) ].solg;

ds [i].don += ds[dem(ds, a) ].don;

ds [dem(ds, a) ].ma = 0;

}
}

void xuat (mh ds[]){

int a = 0;

// cout << dem(ds, a) ;

for (int i=1; i <= dem(ds, a) ; i++){

cout << "****so thu tu : " << i <<"\n";

cout << " ma mat hang : " << ds[i].ma << "\n";

cout << " ten mat hang : " << ds[i].ten << "\n";

cout << " so luong ton kho : " << ds[i].solg << "\n";

cout << " don gia : " << ds[i].gia << "\n";

cout << " thanh tien : " << ds[i].gia * ds[i].solg << "\n";

cout << " don gia ban : " << ds[i].don << "\n" ;

void xoa (mh ds[]){

int k ;

int a=0 ;

cout << "xoa hang ma so : " ;

cin >> k;

for (int i=1; i<= dem (ds, a) +1; i++){

if(ds[i].ma == k ){

for (int z =0; i+z <= dem (ds, a) ;z++){

cout << dem(ds, a);

ds[i+z].ma = ds[i+1+z].ma;

ds[i+z].ten = ds[i+1+z].ten;

ds[i+z].solg = ds[i+1+z].solg;

ds[i+z].gia = ds[i+1+z].gia;
ds[i+z].don = ds[i+1+z].don;

void sx(mh ds[]){

int a=0;

int temp=0;

string z;

for (int i=1; i <= dem (ds, a); i++){

for (int j=1; j <= dem (ds, a); j++ ){

if (ds[i].ma > ds[j].ma){

temp = ds[i].ma;

ds[i].ma = ds[j].ma;

ds[j].ma = temp;

z = ds[i].ten;

ds[i].ten = ds[j].ten;

ds[j].ten = z;

temp = ds[i].solg;

ds[i].solg = ds[j].solg;

ds[j].solg = temp;

temp = ds[i].gia;

ds[i].gia = ds[j].gia;

ds[j].gia = temp;
temp = ds[i].don;

ds[i].don = ds[j].don;

ds[j].don = temp;

void menu(){

cout << " Menu\n";

cout << " 1.Them mat hang\n";

cout << " 2.Xoa mat hang\n";

cout << " 3.Sap xep mat hang\n";

cout << " 4.In danh sach\n";

cout << " 0.Thoat ra ngoai\n";

You might also like