Đáp án bài tập Kĩ thuật lập trình Viện Điệntrường Đại Học Bách Khoa Hà Nội

81 1.5K 0
Đáp án bài tập Kĩ thuật lập trình Viện Điệntrường Đại Học Bách Khoa Hà Nội

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Mình là SV khóa K58 trường ĐHBKHN. Đây là toàn bộ lời giải kĩ thuật lập trình Viện Điện trường ĐH BKHN của thầy Tùng do mình biên tập lại. Lời giải gồm 9 chương theo chương trình dạy của thầy, chúc các bạn có 1 cái nhìn tổng thể về môn học và đạt kết quả cao trong học tập đặc biệt trong môn học này. Chúc các bạn thành công Thân

Đáp án KTLT thầy Tùng ĐHBKHN MADE BY TẠ TUẤN MINH-K58 Email: 20132615@student.hust.edu.vn Bài Tập Chương (T21) Bài 3: #include int main() { struct SinhVien { char ten[20]; int nam_sinh; int khoa; } sv; printf("Nhap du lieu:\n"); printf("Ten: "); fflush(stdin); gets(sv.ten); printf("Nam sinh: "); scanf("%d", &sv.nam_sinh); printf("Khoa: "); scanf("%d", &sv.khoa); printf("Thong tin sinh vien:\n" " Ten: %s\n" " Nam sinh: %d\n" " Khoa: %d\n", sv.ten, sv.nam_sinh, sv.khoa); return 0; } Bài 4: #include int main() { char x = -1; unsigned char y = (unsigned char)x; printf("Gia tri cua x: %d\n", x); printf("Gia tri cua y: %d\n", y); return 0; } Bài 5+6: #include int main() { struct { char model[20]; float khoi_luong; char mau_son[10]; struct { char chung_loai[20]; float ban_kinh; float khoi_luong; } banh[4]; } oto; int i; printf("Nhap du lieu:\n"); printf("Model: "); fflush(stdin); gets(oto.model); printf("Khoi luong: "); scanf("%f", &oto.khoi_luong); printf("Mau son: "); fflush(stdin); gets(oto.mau_son); printf("Nhap du lieu cho cac banh:\n"); for (i=0; i 0) printf("Phuong trinh co nghiem: %.3f va %.3f\n", (-b-sqrt(delta))/(2*a), (-b+sqrt(delta))/(2*a)); else if (delta == 0.) printf("Phuong trinh co nghiem: %.3f\n", -b/2/a); else printf("Phuong trinh vo nghiem\n"); } return 0; } Bài 2: (Tính tổng nghịch đảo…) #include int main() { int n; float s; for (n=2, s=0.; ni = 0.; } Complex(const Complex& c) { r = c.r; i = c.i; } double real() const { return r; } double imag() const { return i; } Complex add(const Complex& c) const { return Complex(r+c.r, i+c.i); } Complex sub(const Complex& c) const { return Complex(r-c.r, i-c.i); } Complex neg() const { return Complex(-r, -i); } Complex mul(const Complex& c) const { return Complex(r*c.r - i*c.i, i*c.r + r*c.i); } Complex div(const Complex& c) const { double d = c.r*c.r + c.i*c.i; return Complex((r*c.i + i*c.r)/d, (i*c.r - r*c.i)/d); } string asString() const { char s[100]; sprintf(s, "(%.3lf, %.3lf)", r, i); return s; } }; void main() { // - Vector Vector v1(1.3, 2, 3.54), v2(4.4, 5.2, 3.2), v3(4.22, 5.2, 5.2); Vector v = v1.crossProduct(v2).sub(v3).neg(); // v = -(v1.v2 - v3) cout next = NULL; if (!l) return (LLIST)e; for (p=l; p->next; p = p->next) ; p->next = e; return l; } LLIST llInsertAfter(LLIST l, PELEM a, int data) { PELEM e; if (!a) return l; e = (PELEM)malloc(sizeof(ELEM)); e->data = data; e->next = a->next; a->next = e; return l; } LLIST llDeleteHead(LLIST l) { PELEM p; if (!l) return NULL; p = l->next; free(l); return (LLIST)p; } LLIST llDeleteTail(LLIST l) { PELEM p; if (!l) return NULL; if (!l->next) { free(l); return NULL; } for (p = l; p->next->next; p = p->next) ; free(p->next); p->next = NULL; return l; } LLIST llDeleteAfter(LLIST l, PELEM a) { PELEM p; if (!a || !a->next) return l; p = a->next; a->next = p->next; free(p); return l; } PELEM llSeek(LLIST l, int i) { for (; i>0 && l; i ) l = l->next; return (PELEM)l; } void llForEach(LLIST l, LLCALLBACK func, void* user) { for (; l; l=l->next) func(l->data, user); } int llLength(LLIST l) { int c; for (c=0; l; c++) l = l->next; return c; } LLIST llDeleteAll(LLIST l) { PELEM p; for (; l; l=p) { p = l->next; free(l); } return NULL; } LLIst.h #ifndef LLIST_H #define LLIST_H struct SELEM; typedef struct SELEM ELEM, *PELEM, *LLIST; struct SELEM { int data; PELEM next; }; typedef void (*LLCALLBACK)(int,void*); LLIST llInit(); LLIST llInsertHead(LLIST l, int data); LLIST llInsertTail(LLIST l, int data); LLIST llInsertAfter(LLIST l, PELEM a, int data); LLIST llDeleteHead(LLIST l); LLIST llDeleteTail(LLIST l); LLIST llDeleteAfter(LLIST l, PELEM a); LLIST llDeleteAll(LLIST l); PELEM llSeek(LLIST l, int i); void llForEach(LLIST l, LLCALLBACK func, void* user); int llLength(LLIST l); #endif Chương 10: Định nghĩa chồng hàm (T21) Bài 6: bt_6.cpp #include #include "linkedlist.h" #include using namespace std; void sumCallback(int data, void* user) { *((int*)user) += data; } void main() { LinkedList l; for (int i=1; inext; a->next = e; return l; } LLIST llDeleteHead(LLIST l) { PELEM p; if (!l) return NULL; p = l->next; free(l); return (LLIST)p; } LLIST llDeleteTail(LLIST l) { PELEM p; if (!l) return NULL; if (!l->next) { free(l); return NULL; } for (p = l; p->next->next; p = p->next) ; free(p->next); p->next = NULL; return l; } LLIST llDeleteAfter(LLIST l, PELEM a) { PELEM p; if (!a || !a->next) return l; p = a->next; a->next = p->next; free(p); return l; } PELEM llSeek(LLIST l, int i) { for (; i>0 && l; i ) l = l->next; return (PELEM)l; } void llForEach(LLIST l, LLCALLBACK func, void* user) { for (; l; l=l->next) func(l->data, user); } int llLength(LLIST l) { int c; for (c=0; l; c++) l = l->next; return c; } LLIST llDeleteAll(LLIST l) { PELEM p; for (; l; l=p) { p = l->next; free(l); } return NULL; } Llist.h #ifndef LLIST_H #define LLIST_H struct SELEM; typedef struct SELEM ELEM, *PELEM, *LLIST; struct SELEM { int data; PELEM next; }; typedef void (*LLCALLBACK)(int,void*); LLIST llInit(); LLIST llInsertHead(LLIST l, int data); LLIST llInsertTail(LLIST l, int data); LLIST llInsertAfter(LLIST l, PELEM a, int data); LLIST llDeleteHead(LLIST l); LLIST llDeleteTail(LLIST l); LLIST llDeleteAfter(LLIST l, PELEM a); LLIST llDeleteAll(LLIST l); PELEM llSeek(LLIST l, int i); void llForEach(LLIST l, LLCALLBACK func, void* user); int llLength(LLIST l); #endif [...]... } Bài 6: #include typedef struct { char ten[50]; int nam_sinh; int khoa; } SinhVien; int main() { SinhVien sv; printf("Nhap du lieu:\n"); printf("Ten: "); fflush(stdin); gets(sv.ten); printf("Nam sinh: "); scanf("%d", &sv.nam_sinh); printf( "Khoa: "); scanf("%d", &sv .khoa) ; printf("Du lieu da nhap:\n" " Ten: %s\n" " Nam sinh: %d\n" " Khoa: %d\n", sv.ten, sv.nam_sinh, sv .khoa) ; return 0; } Bài. .. (a[i] < b[j]) c[k] = a[i++]; /* Copy từ */ /* Thêm ký tự 0 vào cuối từ */ else c[k] = b[j++]; } printf("Mang da tron: \n"); for (k=0; k

Ngày đăng: 26/12/2015, 18:02

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan