Bài Tập 1

Bài Tập  xác định các lớp  trong quản lý xuất nhập hàng sau : 
quản lý hàng hóa 
phiếu nhập gồm : mã phiếu ngày lập
 thông tin nhà cung cấp gồm : nhà cung cấp gồm mã ncc, tên ncc, địa chỉ
thông tin hàng gồm : mã mặt hàng, đơn giá, số lượng
Bài Làm
Lớp Hàng :

Lớp Nhà Cung Cấp :

Lớp Hóa Đơn

Lớp Main

Các thuật toán tìm kiếm

#include<conio.h>
#include<iostream>
#include<math.h>
#include<iomanip>
#define Max 10
using namespace std;
struct Node{
int key;
Node *left,*right;
} *T;
void insert(int x,Node *&T)
{
if(T==NULL){
T=new Node;
T->left=NULL;
T->right=NULL;
T->key=x;
}
else if(T->key<x) insert(x,T->right);
else insert(x,T->left);
}
void nhapcay(Node *&T,int a[],int n)
{
for(int i=0;i<n;i++)
{
insert(a[i],T);
}
}
void hienpre(Node *T)
{
if(T!=NULL){
cout<<T->key<<setw(5);
hienpre(T->left);
hienpre(T->right);
}
}
void nhap(int a[],int &n)
{
cout<<"nhap vao so phan tu cua mang : "; cin>>n;
for(int i=0;i<n;i++){
cout<<"a["<<i<<"] = ";
cin>>a[i];
}
}
void hien(int a[],int n)
{
for(int i=0;i<n;i++)
cout<<a[i]<<setw(5);
cout<<"\n";
}
int tktt(int x,int a[],int n) //tim kiem tuan tu bang vong lap
{
a[n]=x;int i=0;
while(a[i]!=x) i++;
if(i<n) return 1;
else return 0;
}
int tktt2(int x,int a[],int n)//tim kiem tuan tu su dung de quy
{
if(n<0) return 0;
if(a[n]==x) return 1;
else tktt2(x,a,n-1);
}
int tktt3(int x,int a[],int n) //tim kiem trong day da sap tang
{
a[n]=x; int i=0;
while(a[i]<x) i++;
if(i<n&&a[i]==x) return 1;
else return 0;
}
int tknp(int x,int a[],int n)
{
int l=0,r=n-1,m;
while(l<=r){
m=l+r/2;
if(a[m]==x) return 1;
if(a[m]>x) r=m-1;
else l=m+1;
}
return 0;
}
int tknp2(int x,int a[],int l,int r)
{
if(l>r) return 0;
int k;
k=(l+r);
if(a[k]==x) return 1;
if(a[k]>x) return tknp2(x,a,l,k-1);
else return tknp2(x,a,k+1,l);
}
int tkcnp(int x,Node *T) //tim kiem su dung vong lap
{
while(T!=NULL){
if(T->key==x) return 1;
if(T->key<x) T=T->right;
else T=T->left;
}
return 0;
}
int tkcnp2(int x,Node *T) //tim kiem de quy
{
if(T==NULL) return 0;
if(T->key==x) return 1;
else if(T->key<x) tkcnp2(x,T->right);
else tkcnp2(x,T->left);
}
int main()
{
int a[Max],n,x;
nhap(a,n);
hien(a,n);
// nhapcay(T,a,n);
// hienpre(T);
cout<<"\nNhap x muon tim :"; cin>>x;
//if(tktt(x,a,n)==1) cout<<"tim thay x trong mang"; else cout<<"tim mai roi ma khong thay x dau ca !!!";
//if(tktt2(x,a,n)==1) cout<<"tim thay x trong mang";  else cout<<"tim mai roi ma khong thay x dau ca !!!";
//if(tktt3(x,a,n)==1) cout<<"tim thay x trong mang "; else cout<<"tim mai roi ma khong thay x dau ca !!!";
//if(tknp(x,a,n)==1) cout<<"tim thay x trong mang "; else cout<<"tim mai roi ma khong thay x dau ca !!!";
if(tknp2(x,a,0,n-1)==1) cout<<"tim thay x trong mang "; else cout<<"tim mai roi ma khong thay x dau ca !!!";
//if(tkcnp(x,T)==1)  cout<<"tim thay x trong mang "; else cout<<"tim mai roi ma khong thay x dau ca !!!";
//if(tkcnp2(x,T)==1)  cout<<"tim thay x trong mang "; else cout<<"tim mai roi ma khong thay x dau ca !!!";
getch();
}

CODE vẽ đồ thị sin chuyển đổi quan sát

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
using namespace std;
int  xv1,yv1,xv2,yv2;
float xw1,xw2,yw1,yw2; // cac toa cua cua cua so va khung nhin
float tlx,tly; // ty le

void cuaso(float x1,float y1,float x2,float y2)
{
xw1=x1; xw2=x2; yw1=y1;yw2=y2;  // khoi tao cua so
}
void khungnhin(float x1,float y1,float x2,float y2)
{
  xv1=x1;yv1=y1; xv2=x2; yv2=y2;          // khung nhin
  tlx=(float)(xv2-xv1)/(xw2-xw1);                  // tinh ty le x
  tly=(float)(yv2-yv1)/(yw2-yw1);                  // tinh ty le y
}

void chuyenden(float x,float y)
{
  int xm,ym;
  xm=(int)(tlx*(x-xw1)+xv1+0.5);
  ym=(int)(tly*(yw2-y)+yv1+0.5);
  moveto(xm,ym);
}

void veden(float x,float y)
{
  int xm,ym;
  xm=(int)(tlx*(x-xw1)+xv1+0.5);
  ym=(int)(tly*(yw2-y)+yv1+0.5);
  lineto(xm,ym);
}

void vehetruc()
{
setcolor(4);
float x0=0,y0=0,dy=0.01;
chuyenden(x0,y0);
outtextxy(10,10,"Do thi hinh sin coppyright 2015 by NguyenTan");
for(int i=0;i<1000;i++){
x0=x0+dy;
veden(x0,y0);
}
x0=0;y0=0;
chuyenden(x0,y0);
for(int i=0;i<500;i++){
y0=y0+dy;
veden(x0,y0);
}
x0=0,y0=0;
chuyenden(x0,y0);
for(int i=0;i<500;i++){
x0=x0-dy;
veden(x0,y0);
}
x0=0;y0=0;
chuyenden(x0,y0);
for(int i=0;i<500;i++){
y0=y0-dy;
veden(x0,y0);
}

}

void vedothi()
{
setcolor(2);
float dx=0.01;
float x=xw1;
float y=sin(x);
chuyenden(x,y);
while(x<=xw2){
x=x+dx;
y=sin(x);
veden(x,y);
}
}
int main()
{
int gr=0,gm;
cuaso(-M_PI,-1.5,3*M_PI,1.5);
khungnhin(150,150,300,250);
initgraph(&gr,&gm,"");
vehetruc();
vedothi();
getch();
closegraph();
return 0;
}

CODE tô màu hình thang

#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<iostream>
using namespace std;
struct diem{
int x,y;
};
diem A,B,C,D;
void tomauhinhthang(diem A,diem B,diem C,diem D,int mt)
{
setcolor(mt);
setlinestyle(0,0,0);
float m1=(float) (D.x-A.x)/(D.y-A.y);
float m2=(float) (C.x-B.x)/(C.y-B.y);
int y=A.y+1,x1,x2;
while(y<D.y){
x1=(int) (m1*(y-A.y)+A.x);
x2=(int) (m2*(y-B.y)+B.x);
delay(10);
line(x1+1,y,x2,y);
//cout<<x1<<"\t"<<y<<"\t"<<x2<<"\t"<<y<<"\n";
//for(int x=x1+1;x<x2;x++)
//putpixel(x,y,mt);
y++;
}
}
void hinhthang(diem A,diem B, diem C,diem D)
{
setcolor(3);
setlinestyle(1,0,0);
line(A.x,A.y,D.x,D.y);
line(D.x,D.y,C.x,C.y);
line(A.x,A.y,B.x,B.y);
line(B.x,B.y,C.x,C.y);
}
void ktdh()
{
int gd=0,gm,maloi;
initgraph(&gd,&gm,"");
maloi=graphresult();
if(maloi!=0){
cout<<"Loi do hoa";
getch();
exit(0);
}
else{
cout<<"khoi tao thanh cong";
cout<<"product by NguyenTan";
}
}

int main()
{
A.x=100; A.y=100;
B.x=400; B.y=100;
C.x=280; C.y=300;
D.x=150; D.y=300;
ktdh();
hinhthang(A,B,C,D);
tomauhinhthang(A,B,C,D,4);
getch();
closegraph();
return 0;
}

Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận

Tính năng Reply một cấp cho phép trả lời lại phần bình luận trên Facebook, thường thấy ở các fanpage. Hiện tính năng này dường như cũng đang được thử nghiệm rộng rãi hơn cho người dùng Facebook ở New Zealand. Do đó, để tích hợp thêm nút Reply vào các bài đăng của mình trên Facebook, bạn có thể thực hiện theo các bước sau:
Bước 1: Sử dụng trình duyệt Google Chrome để truy cập vào trang touch.facebook.com.
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 1

Bước 2: Vào thanh thực đơn của Chome > Chọn More tools > JavaScript console (phím tắt: Ctrl + Shift + J).
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 2

Bước 3: Nhấn vào biểu tượng Toggle device mode.
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 3
Bước 4: Chọn thẻ Sensors > Chọn Emulate geolocation coordiantes > Nhập giá trị -41.211111 vào ô Lat  174.781111 vào ô Lon.
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 4

Đây là thông số địa lý của New Zealand, giúp Facebook hiểu rằng bạn đang sử dụng Facebook ở nơi này và sẽ cung cấp cho bạn tính năng Reply.
Bước 5: Chọn tính năng Check-In ở trang Facebook đang hiển thị bên trái cửa sổ Chrome. Trên thông báo hiện ra, chọn Allow.
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 5

Bước 6: Chọn một địa điểm bất kỳ trong danh sách hiện ra. Có thể chọn thêm chế độ Only để mọi người không thấy status này, vì sau khi hoàn thành bạn nên xóa nó đi. Xong, nhấn Post.
 Mẹo Facebook: Tự thêm tính năng Reply vào phần bình luận - 6

Bước 7: Thử nghiệm tính năng Reply vừa xuất hiện trên tài khoản Facebook của bạn. Lưu ý, tính năng mới này không có hiệu lực đối với các status đã đăng tải trước đó.
Sau khi hoàn thành, bạn nên thực hiện ngược lại các thao tác từ bước 3 tới bước 1 để trả lại nguyên trạng cho trình duyệt Chrome.

Code Danh sách móc nối đơn


/*DANH SACH MOC NOI DON QUAN LY SINH VIEN*/
#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct SINHVIEN{
char masv[10];
char hoten[20];
float dtb;
};

struct Node{
SINHVIEN infor;
Node *next;
} *L;

void nhap(Node *&L)
{
Node *q; char s[10];
L=new Node;
q=L;
cout<<"Nhap vao ma sinh vien : "; fflush(stdin); gets(L->infor.masv);
cout<<"Nhap ho ten sinh vien :"; fflush(stdin); gets(L->infor.hoten);
cout<<"diem trung binh : "; cin>>L->infor.dtb;
cout<<"Nhap vao ma sinh vien :"; fflush(stdin); gets(s);
while(strcmp(s,""))
{
q->next=new Node;
q=q->next;
strcpy(q->infor.masv,s);
cout<<"Nhap ho ten sinh vien :"; fflush(stdin); gets(q->infor.hoten);
cout<<"diem trung binh : "; cin>>q->infor.dtb;
cout<<"Nhap vao ma sinh vien :"; fflush(stdin); gets(s);
}
q->next=NULL;
}

void nhap2(Node *&L)
{
Node *q;char s[10];
L=new Node;
q=L;
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(L->infor.masv);
cout<<"Nhap ho ten sinh vien : ";fflush(stdin); gets(L->infor.hoten);
cout<<"diem trung binh : "; cin>>L->infor.dtb;
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(s);
while(strcmp(s,""))
{
Node *p=L;
while(p!=p&&strcmp(s,p->infor.masv))
p=p->next;
if(strcmp(p->infor.masv,s)) {
q->next=new Node;
q=q->next;
strcpy(q->infor.masv,s);
cout<<"Nhap ho ten sinh vien : "; fflush(stdin); gets(q->infor.hoten);
cout<<"dien trung binh : "; cin>>q->infor.dtb;
}
else
cout<<"\tMa Trung Roi Kia nhap lai di !!! \n ";
cout<<"Nhap ma sinh vien : ";
fflush(stdin); gets(s);
}
q->next=NULL;
}

void hien(Node *L)
{
if(L!=NULL)
{
cout<<"========== DANH SACH SINH VIEN ==========\n";
while(L!=NULL)
{
cout<<setw(10)<<L->infor.masv<<setw(10)<<L->infor.hoten<<setw(10)<<L->infor.dtb<<endl;
L=L->next;
}
}
else cout<<"Danh Sach trong roi\n";
}

void sapgiam(Node *L)
{
Node *q,*p;SINHVIEN tg;
if(L!=NULL)
{
q=L;
while(q->next!=NULL)
{
p=q->next;
while(p!=NULL)
{
if(p->infor.dtb > q->infor.dtb)
{
tg=p->infor;
p->infor=q->infor
;q->infor=tg;
}
p=p->next;
}
q=q->next;
}
}
}


void saptang(Node *L)
{
Node *q,*p;SINHVIEN tg;
if(L!=NULL)
{
q=L;
while(q->next!=NULL)
{
p=q->next;
while(p!=NULL)
{
if(p->infor.dtb < q->infor.dtb)
{
tg=q->infor;
q->infor=p->infor;
p->infor=tg;
}
p=p->next;
}
q=q->next;
}
}
}

void loaidau(Node *&L)
{
Node *q;
q=L;
L=L->next;
delete q;
}
void loaicuoi(Node *&L)
{
Node *q;
if(L!=NULL)
{
if(L->next==NULL)
{
L=NULL;
delete L;
}
else{
q=L;
while(q->next->next!=NULL)
q=q->next;
Node *p;
p=q->next;
q->next=NULL;
delete p;
}
}
}

void loaitang(Node *&L)
{
Node *q;
if(L!=NULL){
while(L!=NULL&&L->infor.dtb<5)
{
q=L;
L=L->next;
delete q;
}
}
}

void loaigiam(Node *&L)
{
Node *q,*p;
if(L->infor.dtb<5){
L=NULL;
delete L;
}
if(L!=NULL){
p=L;
while(p->next!=NULL&&p->next->infor.dtb>=5)
p=p->next;
q=p->next;
p->next=NULL;
delete q;

}
}

void loai(Node *&L)
{
Node *q=L,*p;
if(L!=NULL){
while(q->next!=NULL)
{
if(q->next->infor.dtb<5)
{
p= q->next;
q->next=p->next;
delete p;
}
else
q=q->next;
}
if(L->infor.dtb<5){
p=L;
L=L->next;
delete p;
}
}
}

void chendau(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen :\n";
cout<<"Mã sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"Diem trung binh : "; cin>>x->infor.dtb;
x->next=L;
L=x;
}

void chencuoi(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao sinh vien can chen :\n";
cout<<"Nhap ma sv : "; fflush(stdin); gets(x->infor.masv);
cout<<"Ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"Diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL){
Node *q=L;
while(q->next!=NULL)
q=q->next;
q->next=x;
}
else L=x;

}

void chensxt(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen : ";
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Nhap vao ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL)
{
if(L->infor.dtb > x->infor.dtb)
{
x->next=L;
L=x;
}
else{
Node *p=L;
while(p->next!=NULL&&x->infor.dtb < p->next->infor.dtb)
{
x->next=p->next;
p->next=x;
}
}
}
else L=x;
}

void chensxg(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen : ";
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Nhap vao ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL)
{
if(L->infor.dtb > x->infor.dtb)
{
x->next=L;
L=x;
}
else{
Node *p=L;
while(p->next!=NULL&&x->infor.dtb < p->next->infor.dtb)
{
x->next=p->next;
p->next=x;
}
}
}
else L=x;
}

void daochieu(Node *&L)
{
if(L!=NULL)
{
Node *p,*q;
q=NULL;p=L;
while(L->next!=NULL){
L=L->next;
p->next=q;
q=p;
p=L;
}
L->next=q;
}
}

void trungma(Node *&L)
{
if(L!=NULL)
{
Node *q,*p,*k;

p=L;
while(p->next!=NULL)
{
q=p;
while(q->next!=NULL)
{
if(strcmp(q->next->infor.masv,p->infor.masv)==0)
{
k=q->next;
q->next=k->next;
delete k;
}
else q=q->next;
}
if(p->next!=NULL) p=p->next;
}
}
}

int main()
{
nhap(L);
//nhap2(L);
hien(L);
//saptang(L);
//loaitang(L);
//chensxt(L);
//sapgiam(L);
//loaigiam(L);
//loai(L);
//loaidau(L);
//loaicuoi(L);
//chendau(L);
//chencuoi(L);
//daochieu(L);
trungma(L);
hien(L);
return 0;
}

code đồ họa vẽ đường tròn

vẽ đường tròn bằng các thuật toán làm tròn số,bresenham ,midpoint :
#include<conio.h>
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<graphics.h>
using namespace std;
void ktdh()
{
    int gd=0,gm;
    initgraph(&gd,&gm,"");
}
void nhap(int &x,int &y,int &R)
{
    cout<<"Nhap vao toa do tam O\n";
    cout<<"nhap x = ";
    cin>>x;
    cout<<"Nhap y = ";
    cin>>y;
    cout<<"Nhap vao ban kinh duong tron : ";
    cin>>R;
}
void put8pixel(int x0,int y0,int x,int y)
{
    putpixel(x+x0,y+y0,5);
putpixel(y+x0,x+y0,5);
putpixel(-x+x0,-y+y0,5);
putpixel(-y+x0,-x+y0,5);
putpixel(-x+x0,y+y0,5);
putpixel(-y+x0,x+y0,5);
putpixel(x+x0,-y+y0,5);
putpixel(y+x0,-x+y0,5);;
}
void lamtronso(int x0,int y0,int R)
{
    int x,y;
    x=0;y=R;
    while(x<=y)
    {
        y=round(sqrt(R*R-x*x));
        put8pixel(x0,y0,x,y);
        x++;
    }
}
void bresenham(int x0,int y0,int R)
{
    int x,y;
    x=0;y=R;
    int p=3-2*R;
    while(x<=y)
    {
        if(p<0) p=p+4*x-6;
        else{
            y--;
            p=p+4*(x-y+10);
        }
        put8pixel(x0,y0,x,y);
        x++;
    }
}
void midpoint(int x0,int y0,int R)
{
    int x,y;
    x=0;y=R;
    float P=5/4-R;
    cout<<P;
    while(x<=y)
    {
        if(P<0) P=P+2*x+3;
        else{
            y--;
            P=P+2*(x-y)+5;
        }
        put8pixel(x0,y0,x,y);
        x++;
    }
}
int main()
{
    ktdh();
    lamtronso(200,200,50);
    bresenham(200,200,100);
    midpoint(200,200,150);
    getch();
    closegraph();
}