Untitled
unknown
plain_text
10 months ago
12 kB
3
Indexable
#include<bits/stdc++.h>
#include<string>
using namespace std;
class PHIEU;
class HH
{
private:
char mahang[20];
char tenhang[30];
float dongia;
int sl;
long thanhtien;
public:
void nhap();
void xuat();
friend class PHIEU;
friend void sx(PHIEU &a);
friend void in(PHIEU a);
friend void sua (PHIEU &a);
friend void xoaSLHon20(PHIEU &a);
friend void xoaMaxSL(PHIEU &a);
friend void chenMatHang(PHIEU &a, int k);
friend void demVaInSLHon10(PHIEU a);
};
void HH::nhap()
{
cout << "Nhap ma hang: "; fflush(stdin); gets(mahang);
cout << "Nhap ten hang: "; fflush(stdin); gets(tenhang);
cout << "Nhap don gia: "; cin >> dongia;
cout << "Nhap so luong: "; cin >> sl;
thanhtien = dongia * sl;
}
void HH::xuat()
{
cout << mahang << setw(15) << tenhang << setw(15) << dongia << setw(15) << sl << setw(15) << thanhtien << endl;
}
class PHIEU
{
private:
char maphieu[20];
char ngaylap[20];
char manv[20];
char hoten[20];
char khachhang[30];
int n;
HH *X;
public:
void nhap();
void xuat();
friend void sx(PHIEU &a);
friend void in(PHIEU a);
friend void sua(PHIEU &a);
friend void xoaSLHon20(PHIEU &a);
friend void xoaMaxSL(PHIEU &a);
friend void chenMatHang(PHIEU &a, int k);
friend void demVaInSLHon10(PHIEU a);
};
void PHIEU::nhap()
{
cout << "Nhap ma phieu: "; fflush(stdin); gets(maphieu);
cout << "Nhap ngay lap: "; fflush(stdin); gets(ngaylap);
cout << "Nhap ma nhan vien: "; fflush(stdin); gets(manv);
cout << "Nhap ho ten: "; fflush(stdin); gets(hoten);
cout << "Nhap khach hang: "; fflush(stdin); gets(khachhang);
do
{
cout << "Nhap so luong hang: ";
cin >> n;
} while (n < 0);
X = new HH[n];
for (int i = 0; i < n; i++) {
cout << "Nhap thong tin hang thu " << i + 1 << endl;
X[i].nhap();
}
}
void PHIEU::xuat()
{
cout << "Bach hoa Thanh Huong" << endl;
cout << "====================PHIEU MUA HANG====================" << endl;
cout << "Ma phieu: " << maphieu << setw(20) << "Ngay lap phieu: " << ngaylap << endl;
cout << "Ma nhan vien: " << manv << setw(20) << "Ho va ten: " << hoten << endl;
cout << "Khach hang: " << khachhang << endl;
cout << "Ma hang" << setw(15) << "Ten hang" << setw(15) << "Don gia" << setw(15) << "So luong" << setw(15) << "Thanh tien" << endl;
int TSL = 0;
long TT = 0;
for (int i = 0; i < n; i++)
{
X[i].xuat();
TSL += X[i].sl;
TT += X[i].thanhtien;
}
cout << "TONG" << setw(45) << TSL << setw(15) << TT << endl;
}
void sx(PHIEU &a)
{
for (int i = 0; i < a.n - 1; i++) {
for (int j = i + 1; j < a.n; j++) {
if (a.X[i].dongia > a.X[j].dongia) {
HH tg = a.X[i];
a.X[i] = a.X[j];
a.X[j] = tg;
}
}
}
a.xuat();
}
void in(PHIEU a)
{
long max_thanhtien = 0;
for (int i = 0; i < a.n; i++) {
if (a.X[i].thanhtien > max_thanhtien) {
max_thanhtien = a.X[i].thanhtien;
}
}
cout << "Mat hang co thanh tien lon nhat:" << endl;
for (int i = 0; i < a.n; i++) {
if (a.X[i].thanhtien == max_thanhtien) {
a.X[i].xuat();
}
}
}
void sua(PHIEU &a){
strcpy(a.khachhang,"Nguyen Hai Long");
}
void xoaSLHon20(PHIEU &a)
{
for (int i = 0; i < a.n; i++ ) {
if (a.X[i].sl > 20) {
for (int j = i; j < a.n - 1; j++) {
a.X[j] = a.X[j + 1];
}
a.n--;
} else {
i++;
}
}
}
void xoaMaxSL(PHIEU &a)
{
int maxSL = a.X[0].sl, pos = 0;
for (int i = 1; i < a.n; i++) {
if (a.X[i].sl > maxSL) {
maxSL = a.X[i].sl;
pos = i;
}
}
for (int i = pos; i < a.n - 1; i++) {
a.X[i] = a.X[i + 1];
}
a.n--;
}
void chenMatHang(PHIEU &a, int k)
{
if (k < 0 || k > a.n) {
cout << "Vi tri chen khong hop le!" << endl;
return;
}
HH newItem;
cout << "Nhap thong tin mat hang moi:" << endl;
newItem.nhap();
HH *temp = new HH[a.n + 1];
for (int i = 0; i < k; i++) {
temp[i] = a.X[i];
}
temp[k] = newItem;
for (int i = k; i < a.n; i++) {
temp[i + 1] = a.X[i];
}
delete[] a.X;
a.X = temp;
a.n++;
}
void demVaInSLHon10(PHIEU a)
{
int count = 0;
cout << "Danh sach mat hang co so luong > 10:" << endl;
for (int i = 0; i < a.n; i++) {
if (a.X[i].sl > 10) {
a.X[i].xuat();
count++;
}
}
cout << "Tong so mat hang co so luong > 10: " << count << endl;
}
int main()
{
PHIEU a;
cout << "Nhap thong tin phieu: " << endl;
a.nhap();
//strcpy(a.khachhang, "Nguyen Hai Long");
cout << "Thong tin phieu: " << endl;
a.xuat();
cout << "Danh sach mat hang sau khi sx: " << endl;
sx(a);
cout << "Danh sach mat hang co thanh tien lon nhat: " << endl;
in(a);
cout << "Phieu sau khi sua" << endl;
sua(a);
// Xoa mat hang co so luong > 20
cout << "Xoa mat hang co so luong > 20:" << endl;
xoaSLHon20(a);
a.xuat();
// Xoa mat hang co so luong max
cout << "Xoa mat hang co so luong max:" << endl;
xoaMaxSL(a);
a.xuat();
// Chen mat hang vao vi tri k
int k;
cout << "Nhap vi tri chen: ";
cin >> k;
chenMatHang(a, k);
a.xuat();
// Dem va in danh sach mat hang co so luong > 10
demVaInSLHon10(a);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
class TL{
private:
char tensp[20];
char mausac[20];
float gia;
public:
TL();
TL(char *name,char *color,float x);
bool operator!();
friend istream& operator>>(istream& is,TL& B);
friend ostream& operator<<(ostream& os, TL&B);
bool operator==(TL B);
};
TL::TL(){
strcpy(tensp,"sony");
strcpy(mausac,"den");
gia=10;
}
TL::TL(char *name,char *color,float x){
strcpy(tensp,name);
strcpy(mausac,color);
gia=x;
}
istream& operator>>(istream& is,TL &B){
cout<<"nhap ten san pham: ";
is>>B.tensp;
cout<<"nhap mau sac: ";
is>>B.mausac;
cout<<"nhap gia: ";
is>>B.gia;
return is;
}
ostream& operator<<(ostream& os,TL &B){
os<<"Ten san pham: "<<B.tensp<<", Mau sac: "<<B.mausac<<", Gia: "<<B.gia<<endl;
return os;
}
bool TL::operator!()
{
if(gia>250&&strcmp(mausac,"trang")==0)
return true;
return false;
}
bool TL::operator==(TL B){
if(strcmp(tensp,B.tensp)==0&&gia==B.gia&&strcmp(mausac,B.mausac)==0)
return true;
return false;
}
int main(){
TL A,B;
cout<<"nhap thong tin tu lanh A: ";
cin>>A;
cout<<"nhap thong tin tu lanh B: ";
cin>>B;
cout<<A<<endl;
cout<<B<<endl;
if(!A){
cout<<"Tu lanh A co gia >250 va co mau trang! "<<endl;
} else{
cout<<"Tu lanh A co gia < 250 va khong co mau trang! "<<endl;
}
if(!B){
cout<<"Tu lanh B co gia >250 va co mau trang! "<<endl;
} else{
cout<<"Tu lanh B co gia < 250 va khong co mau trang! "<<endl;
}
if(A==B){
cout<<"hai tu lanh A, B co cung ten, mau sac va gia ban "<<endl;;
} else{
cout<<"hai tu lanh A, B khong co cung ten, mau sac va gia ban "<<endl;
}
ofstream f("TL.txt",ios::out);
f<<A<<endl;
f<<B<<endl;
if(!A){
f<<"Tu lanh A co gia >250 va co mau trang! "<<endl;
} else{
f<<"Tu lanh A khong co vua gia < 250, vua mau trang! "<<endl;
}
if(!B){
f<<"Tu lanh B co gia >250 va co mau trang! "<<endl;
} else{
f<<"Tu lanh B khong co vua gia < 250 ,vua co mau trang! "<<endl;
}
if(A==B){
f<<"hai tu lanh A, B co cung ten, mau sac va gia ban "<<endl;;
} else{
f<<"hai tu lanh A, B khong co cung ten, mau sac va gia ban "<<endl;
}
#include<bits/stdc++.h>
using namespace std;
class VECTOR{
float x,y,z;
public:
friend istream& operator>>(istream& is, VECTOR &B);
friend ostream& operator<<(ostream& os, VECTOR& B);
VECTOR operator+(VECTOR B);
bool operator-(VECTOR B);
float operator*();
};
istream& operator>>(istream& is, VECTOR &B){
cout<<"nhap x: ";
is>>B.x;
cout<<"nhap y: ";
is>>B.y;
cout<<"nhap z: ";
is>>B.z;
return is;
}
ostream& operator<<(ostream& os, VECTOR &B){
os<<"X= "<<B.x<<", Y= "<<B.y<<", Z= "<<B.z<<endl;
return os;
}
VECTOR VECTOR::operator+(VECTOR B){
VECTOR t;
t.x=x+B.x;
t.y=y+B.y;
t.z=z+B.z;
return t;
}
bool VECTOR::operator-(VECTOR B){
if(x>B.x&&y>B.y&&z>B.z)
return true;
return false;
}
float THUADAT::operator*()
{
return ChieuDai*ChieuRong;
}
int main(){
VECTOR A,B;
cout<<"nhap vector a; "<<endl;
cin>>A;
cout<<"nhap vector b; "<<endl;
cin>>B;
double S1=*TD1;
double S2=*TD2;
cout << "Dien tich thua dat 1: " << S1 << endl;
cout << "Dien tich thua dat 2: " << S2 << endl;
VECTOR t=A+B;
cout<<"tong hai vecto: "<<t<<endl;
if(A-B){
cout<<"a lon hon b! "<<endl;
}else{
cout<<"a nho hon b! "<<endl;
}
ofstream f("Vector.txt",ios::out);
f<<"tong hai vecto: "<<t<<endl;
if(A-B){
f<<"a lon hon b! "<<endl;
}else{
f<<"a nho hon b! "<<endl;
}
f.close();
}
#include<bits/stdc++.h>
using namespace std;
class MOTO;
class NSX{
char tennsx[20];
char diachi[20];
public:
void nhap();
void xuat();
friend class HANGHOA;
friend void xoa(MOTO*a,int &n);
};
void NSX::nhap(){
cout<<"nhap ten nha san xuat: ";fflush(stdin);gets(tennsx);
cout<<"nhap dia chi: ";fflush(stdin);gets(diachi);
}
void NSX::xuat(){
cout<<"Nha san xuat: "<<tennsx<<endl;
cout<<"Dia chi: "<<diachi<<endl;
}
class HANGHOA{
char nhanhieu[20];
NSX x;
public:
void nhap();
void xuat();
friend void xoa(MOTO*a,int &n);
};
void HANGHOA::nhap(){
x.nhap();
cout<<"nhap nhan hieu: ";fflush(stdin);gets(nhanhieu);
}
void HANGHOA::xuat(){
x.xuat();
cout<<"Nhan hieu: "<<nhanhieu<<endl;
}
class MOTO:public HANGHOA{
int phanphoi;
float giathanh;
public:
void nhap();
void xuat();
friend void bonus1(MOTO*a,int n);
};
void MOTO::nhap(){
HANGHOA::nhap();
cout<<"nhap phan phoi: ";cin>>phanphoi;
cout<<"nhap gia thanh: ";cin>>giathanh;
}
void MOTO::xuat(){
HANGHOA::xuat();
cout<<"Phan phoi: "<<phanphoi<<endl;
cout<<"Gia thanh: "<<giathanh<<endl;
}
void bonus1(MOTO*a,int n){
float min=a[0].giathanh;
for(int i=0;i<n;i++){
if(a[i].giathanh<min){
min=a[i].giathanh;
}
}
for(int i=0;i<n;i++){
if(a[i].giathanh==min){
a[i].xuat();
}
}
}
void xoa(MOTO*a,int &n){
for(int i=0;i<n;i++){
while(strcmp(a[i].x.tennsx,"HONDA")==0){
for(int j=i;j<n;j++){
a[j]=a[j+1];
n--;
}
}
} a=(MOTO*)realloc(a,(n)*sizeof(MOTO));
}
int main(){
int n;
do{
cout<<"nhap n moto: ";
cin>>n;
}while(n<0&&n>50);
MOTO*a;
a=new MOTO[n];
for(int i=0;i<n;i++){
cout<<"nhap thong tin moto thu "<<i+1<<endl;
a[i].nhap();
}
for(int i=0;i<n;i++){
cout<<"thong tin moto thu "<<i+1<<endl;
a[i].xuat();
}
cout<<"NHUNG MOTO CO GIA THAP NHAT: "<<endl;
bonus1(a,n);
cout<<"DANH SACH MOTO SAU KHI XOA: "<<endl;
xoa(a,n);
for(int i=0;i<n;i++){
cout<<"thong tin oto thu "<<i+1<<endl;
a[i].xuat();
}
}Editor is loading...
Leave a Comment