یک برنامه کوچک!
| يكشنبه, ۲۵ فروردين ۱۳۹۲، ۰۷:۴۷ ب.ظ
در مسیر باد گرفتن سی++ اخیرا دو مبحث آرایه ها و شی گرایی رو یاد گرفتم.برای اینکه مطمئن بشم که خوب برام جا افتاده یه برنامه ساده و کوچیک نوشتم که شبیه یه پایگاه داده عمل می کنه.اول اطلاعات چند تا کتاب مثل اسم کتاب،اسم نویسنده و تعداد صفحه ها رو ازتون می گیره بعد بهتون امکان جستو جو میده.
میدونم زیادی ساده ست ولی بهر حال ما هم مبتدیم دیگه.
#include <iostream> #include <string.h> using namespace std; class book { public: string name; string author; int page; }; void index(string bn,book b[],int n) { for (int i=0;i<n;i++) { if (bn == b[i].name) { cout << "Name of author : " << b[i].author << " Number of pages : " << b[i].page << "\n"; } } } string input_name; int main() { int i,size; cout << "enter the number of books : "; cin >> size; book a[size]; for (i=0;i < size;i++) { cout << "enter the name of the book : "; cin >> a[i].name; cout << "enter the name of author : "; cin >> a[i].author; cout << "enter the number of pages : "; cin >> a[i].page; cout << "------------------------------\n"; } cout << "\n=====================================\n" << "the information has been placed in database.\n" << "enter the name of books in order to find their information\n\n"; cout << "enter the title : "; cin >> input_name; index(input_name,a,3); return 0; }