BÀI TẬP CHƯƠNG 7 Bài 1: Bài 2: #include <iostream.h> #include <conio.h> char ASCII(char A[]) { for(int i=0; A[i]!='\0'; i++) { if ( A[i] != ' ' ) { cout<<"Ma ASCII cua ki tu "<<A[i]<<" la : "<<int(A[i])<<endl; } } return 0; } int main() { char s[1000]; cout<<"Nhap vao mot chuoi: \t"; cin>>(s); cout<<"\n \n"; ASCII(s); cout<<endl; } #include <iostream.h> #include <conio.h> int main() { char *s; cout<<"Nhap vao mot chuoi : \t"; cin.getline(s,1000); cout<<"Chuoi sau khi dao la : \t"; int l=strlen(s)-1; for(int i=l; i>=0; i ) cout<<s[i]; cout<<"\n \n"; cout<<endl; } Bài 3: #include <iostream.h> #include <conio.h> int doixung(char *st); int main() { char s[1000]; cout<<"\n Nhap vao mot chuoi: "; gets(s); if(doixung(s)==0) { cout<<"\n Day la chuoi KHONG DOI XUNG"; cout<<"\n \n"; cout<<endl; } else { cout<<"\n Day la chuoi DOI XUNG"; cout<<"\n \n"; cout<<endl; } } int doixung(char *st) { int i,j; for(i=0,j=strlen(st)-1;i<strlen(st)/2;j ,i++) if(st[i]!=st[j]) return 0; return 1; } Bài 4: #include <iostream.h> #include <conio.h> int main() { char s[1000],kt; int D=0; cout<<"Nhap vao mot chuoi : "; gets(s); cout<<"\n \n"; cout<<"Nhap ki tu can dem : "; cin>>kt; for(int i=0; i<strlen(s); i++) if(s[i]==kt) D++; cout<<"\n \n"; cout<<"Ki tu "<<kt<<" xuat hien "<<D<<" lan "; cout<<"\n \n"; cout<<endl; } Bài 5: #include<iostream.h> #include<conio.h> int main() { //Phan 1: int i=0,tam; char s[100]; cout<<" Nhap vao mot chuoi: \t"; cin.getline(s,100); int l=strlen(s); cout<<"In ra man hinh tu ben trai nhat cua chuoi va phan con lai cua chuoi"; cout<<"\n \n"; while(s[i]!=' ') { cout<<s[i]; i++; tam=i; } cout<<"\n"; for(int j=tam+1;j<l;j++) cout<<s[j]; cout<<"\n"; cout<<endl; //Phan 2: i=l-1; cout<<"In ra man hinh tu ben phai nhat cua chuoi va phan con lai cua chuoi"; cout<<"\n \n"; while(s[i]!=' ') { i ; tam=i; } for(int j=tam+1;j<l;j++) cout<<s[j]; cout<<"\n"; for(int j=0;j<tam;j++) cout<<s[j]; cout<<"\n"; } Bài 6: #include <iostream.h> #include <conio.h> int main() { char s[100]; cout<<" Nhap vao mot chuoi : "; cin.getline(s,100); int l=strlen(s); cout<<"Xuat chuoi ra man hinh moi tu mot dong \n"; cout<<"\n \n"; for(int i=0;i<l;i++) { if (s[i]!=' ') cout<<s[i]; else cout<<"\n"; } cout<<"\n"; } Bài 7: #include <iostream.h> #include <conio.h> int main() { int l, i, k, tam; char s[100]; cout<<"Nhap vao mot chuoi: \t"; cin.getline(s,100); l=strlen(s); cout<<endl; cout<<"In ra dao nguoc cua chuoi theo tung tu \n"; cout<<"\n \n"; //Them mot khoang trang vao dau chuoi de tien hanh dao chu for (int i=l; i>0; i ) s[i]=s[i-1]; s[0]=' '; cout<<"\n"; l=l+1; tam=l; //Dao chu for( i=l-1; i>=0; i ) { if(s[i]==' ') { for(k=i+1; k<tam; k++) cout<<s[k]; cout<<" "; tam=i; } } cout<<"\n"; cout<<"\n"; } Bài 9: #include <iostream.h> #include <conio.h> int ktd(char s1[], int n); int ktd(char s1[], int n) { int d=0; for(int i=0;i<n;i++) if(s1[i]==' ') d++; else break; return d; } int ktc(char s1[], int n); int ktc(char s1[], int n) { int c=0; for(int i=n-1; i>=0; i ) if(s1[i]==' ') c++; else break; return c; } int main() { char *s1,*s2; s1=new char[50]; s2=new char[50]; cout <<"Nhap vao ho va ten cua nguoi do: \t"; gets(s1); int n=strlen(s1), dem=1, d, c; d=ktd(s1,n); c=ktc(s1,n); s2[0]=d; for(int i=d; i<n-c; i++) { if(s1[i]==' '&&s1[i+1]!=' ') { s2[dem]=i+1; dem++; } } cout<<"\n \n"; cout<<"Ho va ten: \t"; for(int j=0; j<dem; j++) { for(int k=s2[j]; k<n-c; k++) { if(s1[k]!=' ') cout<<s1[k]; else break; } cout<<" "; } cout<<"\nTen: \t"; for(int l=s2[dem-1]; l<n-c; l++) if(s1[l]!=' ') cout<<s1[l]; cout<<endl; } BÀI TẬP CHƯƠNG 8 Bài 1: #include<iostream.h> #include<conio.h> struct nhanvien { unsigned int maNV; char hoten[100]; char diachi[100]; int CBQL; }; typedef nhanvien dsNV[100]; int nhap(dsNV nv, int n) { for (int i=0; i< n; i++) { cout<<"Nhan vien thu "<<i+1<<":\n"; cout<<"Nhap ma Nhan vien:\t"; cin>>nv[i].maNV; cout<<"Nhap Ho va ten:\t"; cin.ignore(); cin.getline(nv[i].hoten,100); cout<<"Nhap Dia chi:\t"; cin.getline(nv[i].diachi,100); cout<<"Nhap 1 neu la Can bo quan ly,nguoc lai nhap 0 :\t"; cin>>nv[i].CBQL; } } int xuat(dsNV nv, int i) { cout<<"\nTHONG TIN CUA NHAN VIEN\n"<<endl; cout<<"Ma so NV: \t"<<nv[i].maNV<<endl; cout<<"Ho & ten: \t"<<nv[i].hoten<<endl; cout<<"Dia chi: \t"<<nv[i].diachi<<endl; if(1 == nv[i].CBQL) cout<<"Day la CBQL"; } int xuatCBQL(dsNV nv, int n) { for(int i=0; i<n; i++) if(1==nv[i].CBQL) xuat(nv,i); } int xuatdsNV(dsNV nv, int n) { for(int i=0; i<n; i++) xuat(nv,i); } int main() { int n,k; dsNV nv; cout<<"Nhap n:\t"; cin>>n; nhap(nv,n); xuatCBQL(nv,n); getche(); system("cls"); return main(); } [...]... n:\t"; cin>>n; nhap(nv,n); xoaCBQL(nv,n); xuatdsNV(nv,n); return main(); } BÀI TẬP TRƯỚC Bài 1/33: //chu vi va dien tich hinh tron #include int main() { float r , p , s; const float pi=3.14; cout >r; p=2*pi*r; s=pi*r*r; cout . BÀI TẬP CHƯƠNG 7 Bài 1: Bài 2: #include <iostream.h> #include <conio.h> char ASCII(char A[]) { for(int. n: "; cin>>n; nhap(nv,n); xoaCBQL(nv,n); xuatdsNV(nv,n); return main(); } BÀI TẬP TRƯỚC Bài 1/33: Bài 6/33: //chu vi va dien tich hinh tron #include <iostream> int main() { float. l=s2[dem-1]; l<n-c; l++) if(s1[l]!=' ') cout<<s1[l]; cout<<endl; } BÀI TẬP CHƯƠNG 8 Bài 1: #include<iostream.h> #include<conio.h> struct nhanvien { unsigned int