Lập trình cấu trúc
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef struct
{
char ten[100];
int soluong, dongia, giatri;
}sach;
void nhap(sach a[], int n)
{
for (int i=0; i<n; i++)
{
cout << "nhap ten sach thu "<< i+1 <<":"<< endl;
fflush(stdin);
gets(a[i].ten);
cout << "nhap so luong, don gia thu"<< i+1 <<":"<<endl;
cin >> a[i].soluong>> a[i].dongia;
a[i].giatri = a[i].soluong *a[i].dongia;
}
}
void tim(sach a[], int n)
{
for (int i=0; i<n; i++)
{
if (strcmp(a[i].ten, "Phuong phap luan lap trinh")==0)
{
cout << "Thong tin ve cuon sach:"<< endl;
cout << "Ten: "<< a[i].ten << endl;
cout << "so luong, do gia, gia tri lan luot la:"<< endl;
cout << a[i].soluong << endl << a[i].dongia << endl << a[i].giatri << endl;
return;
}
}
cout << "Khong co cuon sach yeu cau!" << endl;
}
int dem(sach a[], int n)
{
int d=0;
for (int i=0; i<n; i++)
{
if (a[i].soluong > 10)
{
d++;
}
}
return d;
}
int main(int argc, char *argv[])
{
sach a[1000];
int n;
cout << "nhap so luong sach: "<< endl;
cin >> n;
nhap(a, n);
tim(a, n);
cout << "sach co so luong lon hon 10 la: "<< dem(a, n)<< "dau sach"<<endl;
system("pause");
}
Bạn đang đọc truyện trên: Truyen247.Pro