SlideShare a Scribd company logo
1 of 25
Download to read offline
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
1 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‫ڕیزکراوه‬‌‫کان‬:‌‫له‬‌‌‫کۆمه‬‌‫ڵێک‌دانه‬‌‌‫پێک‌هاتووه‬‌‌‫ک‬‫ه‬‌‌‫یه‬‌‌‫ک‌دووری‬‫هه‬‌‫یه‬‌‌‫که‬‌‌‫به‬‌‫شێوه‬‌‫یه‬‌‫کی‌ئاسۆی‌یان‌ستوونی‌ته‬‌‫نها‌یه‬‌‌‫ک‬
‫ڕیز‌ده‬‌‫گرێته‬‌‫وه‬‌‌‫بۆیه‬‌‌‫پێی‌ده‬‌‌‫ڵێن‬(One Dimension)‌‫یان‬‌‌‫ڤێکتۆر‬(Vector)‌‌‫که‬‌‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫هێما‌ده‬‌‌‫کرێت‬‌A‌‫وه‬‌‌‫به‬‌‌
‫یه‬‌‫ک‌قه‬‌‫باره‬‌‌‫دیاری‌د‬‫ه‬‌‫کرێت‌که‬‌‌‫ده‬‌‫کاته‬‌‌‫ژماره‬‌‫ی‌ئه‬‌‫و‌دانانه‬‌‫ی‌که‬‌‌‫له‬‌‌‫ڕیزه‬‌‫که‬‌.‫دان‬‌
‌
‫یاسای‌گشتی‌ڕیزکراوه‬‌‫کانیش‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌:‫بێت‬
Type const size=? ;
Type name[size];
‫سه‬‌‫ره‬‌‫تا‌پێویسته‬‌‌‫وه‬‌‫کو‌هه‬‌‫موو‌به‬‌‫رنامه‬‌‌(‌‫کانی‌پێشوو‬Header‫)ی‌بۆ‌بنووسین‌که‬‌‌‫به‬‌‫شێکی‌سه‬‌‫ره‬‌‫کی‌به‬‌‫رنامه‬‌‫که‬‌‫یه‬‌.‌
‫وه‬‌‌‫ئه‬‌‫گه‬‌‫ر‌پێویستمان‌به‬‌‌‫هه‬‌‫ر‌جۆر‌کردارێکی‌تر‌بوو‌ده‬‌‫بێ‌له‬‌‌(Header)‫دا‌زیادی‌بکه‬‌‫ین‌وه‬‌‌‫ک‌(حساباتی‌بیرکاری‬
‫که‬‌‌‫توانی)‌تێده‬‌‫که‬‌‌(‫وێت،‌یان‌نووسین‬‫تێکست‌و‌حه‬‌‫رف)‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌.‫دا‬
1. #include <iostream.h>
2. #include <conio.h>
3. #include <math.h>
4. #include <cstring.h>
‫خاڵی‬1‌‫و‬2‌‫سه‬‌‫ره‬‌‫کین‌بۆ‌هێده‬‌‫ره‬‌‫که‬‌‌‫که‬‌‌‫ده‬‌‫بێت‌له‬‌‌‫هه‬‌‫موو‌به‬‌‫رنامه‬‌‫یه‬‌‫کدا‌بنووسرێت‌به‬‌:‫اڵم‬
‌‫خاڵێ‬3‌‫به‬‌‫کاردێت‌بۆ‌(حساباتی‌بیرکاری‌که‬‌‌‫توان،‌ڕه‬‌‌‫گ‬‫،‌ته‬‌.)...‌‫ژێ‬
‌‫خاڵی‬4‌‫به‬‌‫کاردێت‌بۆ‌(‌تێکست‌و‌حه‬‌‫رف)‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌.‫دا‬
‫پاشان‌ده‬‌‫چینه‬‌‌‫به‬‌‌‫شی‬(Declaration)‌‫که‬‌‌‫ئه‬‌‫م‌به‬‌‫شه‬‌‌‫به‬‌‌‫مانای‌لێدوان‌دێت‌که‬‌‌‫تیایدا‌ئه‬‌‫وشتانه‬‌‫ی‌که‬‌‌‫پێویستمانه‬‌‌‫ده‬‌‌‫یان‬
‫ناسێنین‌به‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‌‫ئه‬‌‫میش‌چوار‌جۆره‬‌‌:‌
1. int ‌‫به‬‌‫کاردێت‌بۆ‌ژماره‬‌‫ی‌ته‬‌‫واوه‬‌‌‌‫کان‬
2. float ‌‫به‬‌‫کاردێت‌بۆ‌ژماره‌ڕێژه‬‌‫یه‬‌‌‫کان‬‌
3. string ‌‫به‬‌‫کاردێت‌بۆ‌نوسینی‌وشه‬‌‌‌‫یان‌ناو‬
4. char ‌‫به‬‌‫کاردێت‌بۆ‌نوسینی‌ته‬‌‫نها‌یه‬‌‫ک‌حه‬‌‌‫رف‬
‫له‬‌‌‫ڕیزکراوه‬‌‫کاندا‌پێویستمان‌به‬‌‌‫نه‬‌‫گۆڕێک‌یان‌زیاتر‌ده‬‌‫بێت‌که‬‌‌‫له‬‌‌‫دوای‬(Header)‫وه‬‌‌‫ده‬‌‫نووسرێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌:‌
Type const size=? ;‌
“Type”‌‫پێویسته‬‌‌‫به‬‌‌‫ژماره‬‌‫ی‌ته‬‌‫واو‌داخلی‌بکه‬‌‫ین‌که‬‌‌(int)‌‫به‬‌.‌‫کاردێت‬‌
“const”‌‫واته‬‌‌‫نه‬‌‫گۆڕ‬‌‫مه‬‌‫به‬‌‫ست‌له‬‌‌‫ژماره‬‌‫ی‌دانه‬‌‫کانه‬‌‌‫ئه‬‌‫م‌وشه‬‌‫یه‬‌‌‫ده‬‌.‫ستکاری‌ناکرێت‬‌
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
2 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
“size=”‌‫ئه‬‌‫مه‬‌‫ش‌واته‬‌‌‫قه‬‌‫باره‬‌‫ی‌ڕیزه‬‌‫که‬‌‌‫که‬‌‌‫چه‬‌‫ند‌دانه‬‌‫ی‌تێدایه‬‌‌‫خۆمان‌دیاری‌ده‬‌‫که‬‌‫ی‬‫ن‌یان‌به‬‌‫پێی‌پرسیاره‬‌‫که‬‌.‌
‫بۆ‌نمونه‬‌‌:‌
Int const size=3;
‫ده‬‌‌‫توانین‌ناوی‬(size)‌‫بگۆڕین‌به‬‌‌‫هه‬‌‫ر‌حه‬‌‫رفێک‌به‬‌‌‫ئاره‬‌‫زوی‌خۆمان‬”n,m,l,k”‌‫،به‬‌‫اڵم‌پێویسته‬‌‌‫ئاگادار‌بین‌ئه‬‌‌‫و‬
‫حه‬‌‫رفه‬‌‌‫له‬‌‌‫کرداری‌تردا‌به‬‌‫کاری‌نه‬‌‫هێنین‌وه‬‌‌‫نابێت‌دوو‌جار‌پێناسه‬‌‫ی‌بکه‬‌.‌‫ین‬
‫به‬‌‌‫شێکی‌تری‬‫ڕیزکراوه‬‌‫کان‌بریتیه‬‌‌‫له‬‌‌‌‫ناساندنی‌ئه‬‌‫و‌شتانه‬‌‫ی‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‫دا‌به‬‌‫کاری‌ده‬‌‫هێنین‬‌‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌
Int array[size1];
Type k,l,sum,m;
‫پاشان‌هه‬‌‫ر‌شتێکمان‌به‬‌‫کارهێنا‌پێوستبوو‌بیناسێنین‌وه‬‌(‌‫ک‬i,j,n,k,l,m,‌‌‌)‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌int i;
‌‫پاشان‬main()
{‌‌‌
‫ده‬‌‫نووسین‌ده‬‌‫ست‌ده‬‌‫که‬‌‫ین‌به‬‌‌‫به‬‌‫رنامه‬‌‌‫داڕشتنه‬‌‫که‬‌.‌
‫ته‬‌‫نها‌ئه‬‌‫وشتا‌نه‬‌‫بێت‌که‬‌‌‫له‬‌‫سه‬‌‫ره‬‌‫وه‬‌‌‫ناساندوومانه‬‌‌‫وه‬‌‫ک‌قه‬‌‫باره‬‌‌‫و‌ناو‌‌وه‬‌‌‫نابێت‌دووباره‬‌‌.‫بیان‌ناسێنین‬‌
‫له‬‌‌‫ڕیزکراوه‬‌‫کاندا‌بۆ‌زۆربه‬‌‫ی‌کرداره‬‌‫کانی‌وه‬‌‌‫ک‬(cin,cout,if,swap,sum,count,multi,mean)‌‫پێویستمان‌به‬‌‌
‫ته‬‌‫نها‌یه‬‌‫ک‌لووپ‌ده‬‌‫بێت‌ئه‬‌‫گه‬‌‫ر‌قه‬‌‫باره‬‌‌‫نه‬‌‫گۆڕبێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌
for(i=0;i<size;i++)
{
_____
_____
}
‌‌(‌‫أ/‌داغڵ‌کردن‬cin>>‫):‌بۆ‌نموونه:‌ڤێکته‬‌‫ری‬‌An‫که‬‌‌‫قه‬‌‫باره‬‌‌‫کامان‬n=2‌‫قه‬‌‫باره‬‌‫یان‌یه‬‌‫کسانه‬‌
int const n=2;
int a[n];
int I,
for(i=0;i<n;i++)
{
cin>>a[i];
}
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
3 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‫لێره‬‌‫دا‌مه‬‌‫به‬‌‫ستمان‌له‬‌‌a[n]‌‌‫و‬a[i]‌‫چی‌یه‬‌‌‫؟‬‌
‫مه‬‌‫به‬‌‫ست‌له‬‌‌a[n]‌‫واته‬‌‌‫ڤێکته‬‌‫رێکمان‌هه‬‌‫یه‬‌‌‫به‬‌‌‌‫ناوی‬a‌‫وه‬‌‌‫قه‬‌‫باره‬‌‫ی‌ئه‬‌‫م‌ڤێکته‬‌‫ره‬‌‌n‌‫قه‬‌‫باره‬‌‫یه‬‌‌‫که‬‌‌‫ژماره‬‌‫ی‌دانه‬‌‌‫کانی‬
‫ڤێکته‬‌‫ره‬‌‫که‬‌‌‫ده‬‌‫گرێته‬‌‫وه‬‌‌‫وه‬‌‌‫ئه‬‌‫م‌هێمایه‬‌‌‫ته‬‌‫نها‌له‬‌‌‫سه‬‌‫ره‬‌‫تادا‌داخڵ‌ده‬‌‫کرێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌.‌
‌
‌
‫مه‬‌‫به‬‌‫ست‌له‬‌‌a[i]‌‫ئه‬‌‫وه‬‌‫یه‬‌‌‫که‬‌‌‫دانه‬‌‫کان‌به‬‌‌‫پێی‬i‌‫داخل‌یان‌ده‬‌‫ست‌که‬‌‫وت‌یان‌هه‬‌‫ر‌کردارێکی‌تر‌به‬‌‫ستراوه‬‌‌:‌
‫بۆ‌نموونه‬‌‌‫ئێمه‬‌‌‫ڤێ‬‫کته‬‌‫رێکمان‌هه‬‌‫یه‬‌‌‫قه‬‌‫باره‬‌‫که‬‌‌‫ی‬3‌‫یه‬‌‌‫واته‬‌‌int const n=3;
‫وه‬‌‌‫لووپه‬‌‫که‬‌‫شمان‌به‬‌‌i‌‫هێما‌ده‬‌‫که‬‌‫ین‌که‬‌‌‫له‬‌‌0‌‫ده‬‌‫ستپێده‬‌‫کات‌تا‌دانه‬‌‫یه‬‌‫ک‌که‬‌‫متر‌له‬‌‌‫ژماره‬‌‌‫ی‬n‌‫واته‬‌‌3‌
‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌int i;‌‫وه‬‌‌‫لووپه‬‌‫که‬‌‫ش‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌‌:‌‫بێ‬for(i=0;i<n;i++)
‫واته‬‌‌‫له‬‌‌0،1،2‌‫که‬‌‌‫ده‬‌‫کاته‬‌‌‌‫سێ‌،ژماره‬2‌‌‫بچوکتره‬‌‌‫له‬‌3‌
‫به‬‌‫اڵم‌نرخه‬‌‌‫کان‬3‌‫دانه‬‌‫ن‌چونکه‬‌‌‫له‬‌‌0‌‫وه‬‌‌‫ده‬‌‫ست‌پێده‬‌‫کات؛‬‌
‫مه‬‌‫به‬‌‫ستمان‌له‬‌‫مه‬‌‌‫ئه‬‌‫وه‬‌‫یه‬‌‌‫که‬‌‌‫هه‬‌‫ر‌نرخێک‌که‬‌‌‫داخڵی‌ده‬‌‫که‬‌‫ین‌یه‬‌‫کێک‌له‬‌‫و‌ژمارانه‬‌‌‌"0،1،2‫"‌ده‬‌‫گرێت‌و‌ده‬‌‫یکات‌به‬‌‌
‫جێگای‌خۆی‌پێی‌ده‬‌‌‫ڵێن‬“index”‌‫یان‬“subscript”‌‌‫وه‬‌‌‫له‬‌‌‫ده‬‌‫رکه‬‌‫وتنی‌دا‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌‫رده‬‌‫که‬‌‫وێت‬‌
cout<<”a[“<<i+1<<”]=”;
‫ئه‬‌‫مه‬‌‌‌‫هێمای‬“index”‫ه‬‌‌‫واته‬‌‌‫کاتێک‌که‬‌‌i‌‫ده‬‌‫بێ‌به‬‌‌0‌+‌‫تۆ‬1‌‫بکه‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌به‬‌‫شێوه‬‌‫یه‬‌‫کی‌جوان‌ده‬‌‫ربکه‬‌‌‫وێت‬‌
‫ئه‬‌‫مه‬‌‫ش‌له‬‌‌‫نموونه‬‌‫کاندا‌جوانتر‌ده‬‌‫رده‬‌‫که‬‌‫وێت‬:‌
A3 ‫دانه‬‌‫کان‬ index‌ a[i]
i=0
‌i=1‌
‌i=2‌‌
‫واته‬‌‌‫ئێستا‌ئێمه‬‌‌‫ئه‬‌‫گه‬‌‌‫ر‬index‌‫ی‌ژماره‬‌‌8‌‫مان‌بوێت‌ده‬‌‫کاته‬‌‌1‌‫بۆیه‬‌‌‌‫ده‬‌‌‫بێت‬i+1‌‫بکه‬‌‫ین‌بۆئه‬‌‫وه‬‌‌‫ی‌نرخی‌خۆی‬
‫وه‬‌‫ربگرێت‌که‬‌‌‫له‬‌‌‫ڕاستیدا‌ژماره‬‌‌2‌‫ه‬‌.‌
cout<<”a[“<<i+1<<”]=”<<a[i];
‫لێره‬‌‫دا‌کاتێک‌که‬‌‌‫ژماره‬‌‌‫داخڵ‌ده‬‌‫که‬‌‫ین‌ده‬‌‫بێ‌بزانین‌که‬‌‌‫یه‬‌‫که‬‌‫م‌ژماره‬‌‌‫ده‬‌‫چێته‬‌‌a[i=0]‌‫وه‬‌‌‫دووه‬‌‫م‌ژماره‬‌‌‫ده‬‌‫چێته‬‌‌a[i=1]
‫به‬‌‌‫م‬‌‫شێوه‬‌‫یه‬‌‌‫تا‌‌لوپ‌ته‬‌‫واو‌ده‬‌.‫بێت‬‌
‌
a[2]3
8 a[1]
a[0]6
a[2]=8
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
4 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‫تێبینی‌//‌به‬‌‫هیچ‌شێوه‬‌‫یه‬‌‌‫ک‬cin>>‌‫واته‬‌‌‌‫ئینپوت‬<<endl‌‌‫و‬<<” “‌‫وه‬‌‫رناگرێت‌راسته‬‌‫وخۆ‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌
cin>>a[i] <<endl<<” “;
cin>>a[i];
cout<<endl<<” “;
‫لێره‬‌‫ده‬‌‌‫پێش‌ئه‬‌‫وه‬‌‫ی‌ب‬‫اسی‌ده‬‌‫ستکه‬‌‌‫وت‬(cout<<)‫بکه‬‌‫ین‌پێویسته‬‌‌‫جوانکاریه‬‌‫ک‌دابنێین‌بۆ‌به‬‌‫رنامه‬‌‫که‬‌‌‫مان‬‌
‫وه‬‌‌‫ئه‬‌‌‫م‬cout‌‫ی‌جوانکاریه‬‌‌‫هه‬‌‫میشه‬‌‌‫ده‬‌‫بێت‌له‬‌‫پێش‌لووپه‬‌‫وه‬‌‌“for”‌‫بنووسرێت‌بۆ‌ئه‬‌‫وه‬‌‫ی‌ته‬‌‫نها‌یه‬‌‫ک‌جار‌له‬‌‫سه‬‌‌‫ر‬
‫شاشه‬‌‫که‬‌‌‫ده‬‌‫رکه‬‌‫وێت‌به‬‌‫اڵم‌ئه‬‌‫گه‬‌‫ر‌له‬‌‌‫حساباتدا‌بوو‌ئه‬‌‫وا‌ده‬‌‫توانین‌بیخه‬‌‫ینه‬‌‌‫ناو‌لووپه‬‌‫که‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌له‬‌‫گه‬‌‫ڵ‌ئه‬‌‌‫نجامی‬
‫هه‬‌‫موو‌کرداره‬‌‫کاندا‌ده‬‌‫ربکه‬‌‫وێت.‌ئه‬‌‫مه‬‌‫ش‌نووسینێکه‬‌‌‫ده‬‌‫که‬‌‫وێته‬‌‌‫نێوان‌دوو‌کۆته‬‌‌‫یشن‬“ “‌‫ک‬‫ه‬‌‌‫پێویست‌به‬‌‌‌‫ناساندن‬
‫ناکات‌و‌به‬‌‌‫ئاره‬‌‫زووی‌خۆت‌ده‬‌‫توانی‌شتی‌تێدا‌بنووسیت‬‫وه‬‌‌‫له‬‌‌‌‫کۆتایدا‬<<endl;‌‫ده‬‌.‫نووسین‬‌
‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌:‌
cout<<”Enter Numbers of the Vector A:”<<endl; “cin>>” ‫له‬‌‌‫پێش‌داخڵ‌کردنی‌نرخ‌واته‬‌‌‌‌‫بۆ‬
cout<<”A”<<endl<<”___”<<endl;
‌‌/‫ب‬‫ده‬‌‫ستکه‬‌(‌‫وت‬cout<<‫)‌:ئه‬‌‫م‌به‬‌‫شه‬‌‌‫ئه‬‌‫نجامی‌ئه‬‌‫م‬‌‌‫کرداره‬‌‫مان‌ده‬‌‫داتێ‌که‬‌‌‫داخڵمان‌کردووه‬‌‌‫له‬‌‫سه‬‌‫ر‌شاشه‬‌‫که‬‌‌.‌
‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌:‌
for(i=0;i<n;i++)
cout<<a[i]<<endl;
endl‌‫واته‬‌‌‫به‬‌‫شێوه‬‌‫یه‬‌‫کی‌ستوونی‌بێت‌وه‬‌‌‫گه‬‌‫ر‌ویستمان‌به‬‌‌‫شێوه‬‌‫ی‌ئه‬‌‫سۆی‌بێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫دایده‬‌‫نێین‬‌
for(i=0;i<n;i++)
cout<<a[i]<<” “;
‫وه‬‌‌‫له‬‌‌‫دوا‌هه‬‌‫مووی‌ئه‬‌‫مانه‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌شاشه‬‌‌‫ڕه‬‌‫شه‬‌‫که‬‌‫مان‌بۆ‌ده‬‌‫ربکه‬‌‫وێت‌و‌النه‬‌‫چێت‌تا‌خۆمان‌دایده‬‌‫خه‬‌‌‫ین‬‫ده‬‌:‫نووسین‬‌
‌getch();
}
A
__
2
6
4
A : 2 6 4
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
5 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‫نمونه‬‌‫یه‬‌‫ک‬‌‌‫له‬‌‫سه‬‌‫ر‌هه‬‌‫موو‌ئه‬‌‫و‌کردارانه‬‌:‫ی‌پێشوو‬‌
1‫/‌ئه‬‌‫م‌نموونه‬‌‫یه‬‌‌‫له‬‌‫سه‬‌‫ر‌داخڵ‌کردنی‌ژماره‬‌‫ی‌ته‬‌‫واوه‬‌.‌
‌
‌
‌
‌
‌
‌
‌
2‫/‌ئه‬‌‫م‌نموونه‬‌‫یه‬‌‌‫له‬‌‫سه‬‌‫ر‌داخڵ‌کردنی‌نووسینه‬‌‌‫وه‬‌.‫ک‌ناو‬‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
#include <iostream.h>
#include <conio.h>
int const n=4;
int a[n];
int i;
main()
{
cout<<”enter the numbers of vector A:”<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<”A”<<endl<<”__”<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
getch();
}
Enter Numbers of vector A:
3 5 7 9
A
__
3
5
7
9
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
int const n=3;
string a[n];
int i;
main()
{
cout<<”Enter the names of vector A:”<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<” a ”<<endl<<”_____”<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
getch();
}
Enter Names of vector A:
Richard Suzan Danny
A
_____
Richard
Suzan
Danny
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
6 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‫ئه‬‌‫مه‬‌‫ش‌کۆمه‬‌‫ڵێک‌نموونه‬‌:‌
3/write C++ programming to print out with index of the‌Marks vector: 10, 30, 60, 45, 34, 67.
1‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫که‬‌‌‫ئه‬‌‫م‌نمرانه‬‌‌‫چاپ‌بکات‌له‬‌‫گه‬‌‫ل‌جێگه‬‌.‫کانیان‬‌
‌
0‌
‌
‌
‌
‌
‫تێبینی‌ئه‬‌‫م‌به‬‌‫رنامه‬‌‫یه‬‌‌‫پێویسته‬‌‌‫به‬‌‌‌‫داخڵ‌کردن‬(cin>>)‌‫ناکات‌چونکه‬‌‌‫خۆی‌نرخه‬‌‫کانی‌داوه‬‌‌‫به‬‌‫پێ‌ژماره‬‌‫ی‌نرخه‬‌‌‫کان‬
‫قه‬‌‫باره‬‌‫که‬‌‌‫دیاری‌ده‬‌‫که‬‌‫ین‌و‌له‬‌‌‫ته‬‌‫نیشتی‌داخڵ‬‫ی‌ده‬‌‫که‬‌‫ینه‬‌‌‫ناو‌به‬‌‫رنامه‬‌‫که‬‌‫وه‬‌‌‫له‬‌‌‫به‬‌.‫شی‌پێناساندن‌دا‬‌
4/Write C++ Program to read and print out a vector An then find the Maximize number of the vector.
2‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫کی‌سی‌پڵه‬‌‫س‌پڵه‬‌‫س‌بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‌‌‫و‌چاپکردنی‬‌‫ڤێکتۆرێکی‬An‌‫،‌پاشان‬‫گه‬‌‫وره‬‌‫ترین‬‌‫ژماره‬‌‌‫بدۆزه‬‌‫ره‬‌‫وه‬‌‌
‌
#include <iostream.h>
#include <conio.h>
int mark[6]={10,30,60,45,34,67};
int i;
main()
{
cout<<”Marks and Index”<<endl<<”_____________”<<endl;
for(i=0;i<6;i++)
cout<<"Mark("<<i+1<<")="<<mark[i]<<endl;
getch();
}
Marks and Index
______________
Mark(1)=10
Mark(2)=30
Mark(3)=60
Mark(4)=45
Mark(5)=34
Mark(6)=67
#include <iostream.h>
#include <conio.h>
int const n=6;
int a[n];
int i,max1;
main()
{
cout<<”Enter the Numbers of vector A:”<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<”Vector A”<<endl<<”_______”<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
max1=a[0];
for(i=0;i<n;i++)
if(max1<a[i])
max1=a[i];
cout<<”Maximize Number=”<<max1;
getch();
}
Enter the numbers of vector A:
4 3 5 7 9 6
Vector A
________
4
3
5
7
9
6
Maximize number=9
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
7 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
5/Write C++ program to:-
1/set all ten Elements of Array A10 to zero . ‫واته‬‌‌‫هه‬‌‌‫موو‬10‌‫دانه‬‌‫که‬‌‫ی‌ڕیزه‬‌‫که‬‌‌‫بکه‬‌‌‫به‬‌‌‌‌‌‌‌‌‌‌‫سفر‬
2/copy array A10 to array Bn. ‌‫واته‬‌‌‫ڕیزی‌‌‌کۆپی‌بکه‬‌‫ره‬‌‌‫ڕیزی‌‌‌‌وه‬‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌
‌‫تێبینی:‌هێمای‬//‌‫که‬‌‌‫له‬‌‫ناو‌به‬‌‫رنامه‬‌‫که‬‌‫دا‌به‬‌‫کارمان‌هێناوه‬‌‌‫پێی‌ده‬‌‫ڵێن‌کۆمێنت‌وه‬‌‌‫ته‬‌‫نها‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‫دا‌ده‬‌‫رده‬‌‫که‬‌‌‫وێت‬‫بۆ‌تێگه‬‌‫شتنه‬‌‌‫له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‌
‫بۆ‌ئه‬‌‫و‌که‬‌‫سه‬‌‫ی‌کار‌له‬‌‫سه‬‌‫ر‌به‬‌‫رنامه‬‌‌‫دارێژیه‬‌‫که‬‌‌‫ده‬‌‫کات‬(Programmer)‌‫وه‬‌‌‫دوو‌شێوه‬‌‫ی‌هه‬‌‫یه‬:‌‌
1‌‌‌.Comment//‌‫ئه‬‌‫مه‬‌‌‫ته‬‌‫ن‬‫ها‌بۆ‌دێرێک‌کۆمێنت‌به‬‌.‌‫کاردێت‬‌
2‌./*Comment1
Comment2*/‌‌‌‌‌‫ئه‬‌‫مه‬‌‌‫به‬‌‫کاردێت‌بۆ‌دێڕێک‌زیاتر‌بۆ‌ڕوونکردنه‬‌‫وه‬‌‫ی‌به‬‌‫رنامه‬‌‫که‬‌.‌
#include <iostream.h>
#include <conio.h>
int const n=10;
int a[n],b[n];
int i;
main()
{
//1-set all ten elements of array A to zero.
cout<<”Enter Ten Numbers of vector A:”<<endl;
for(i=0;i<10;i++)
cin>>a[i];
cout<<”Vector A”<<endl<<”_______”<<endl;
for(i=0;i<n;i++)
{
a[i]=0;
cout<<a[i]<<endl;
}
//2- Copy array A to Array B.
cout<<”Enter Ten Numbers of vector A:”<<endl;
for(i=0;i<10;i++)
cin>>a[i];
cout<<”Vector B”<<endl<<”_______”<<endl;
for(i=0;i<n;i++)
{
b[i]=a[i];
cout<<b[i]<<endl;
}
getch();
}
Enter ten numbers of vector A:
4 3 5 7 9 6 2 0 1 7
Vector A
________
0
0
0
0
0
0
0
0
0
0
Enter ten numbers of vector A:
4 3 5 7 9 6 2 0 1 7
Vector B
________
4
3
5
7
9
6
2
0
1
7
AB
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
8 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
6/Write C++ program to read and print out An. Then print those numbers which are line between 5 & 15.
6‫/‌به‬‌‫رنامه‬‌‫یه‬‌‌‫ک‬‌‫بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‌‫و‌چاپکردنی‌ڤێکتۆری‬A‌‫.‌پاشان‌ئه‬‌‫و‌ژمارانه‬‌‌‫چاپ‌بکه‬‌‌‫که‬‌‌‫ده‬‌‫که‬‌‫وێته‬‌‌‌‫نێوان‬5‌‌‫و‬15‌‫وه‬‌.‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌
If we want index for the example we just add <<” “<<”index=”<<i+1<<endl; for last cout:
‫ئه‬‌‫گه‬‌‌‫ر‌ویستمان‬(index)‌‫دیاری‌بکه‬‌‫یه‬‌‫ن‌له‬‌‫و‌نموونه‬‌‫ی‌سه‬‌‫ره‬‌‫وه‬‌‫دا‌ئه‬‌‫وا‌ته‬‌‫نا‌ئه‬‌‫مه‬‌‌<<” “<<”index=”<<i+1<<endl;‫زیاد‌ده‬‌‫که‬‌‌‫ین‌بۆ‬
‌‫کۆتا‬cout‌‌.‌
for(i=0;i<n;i++)
{
if(a[i]>5&&a[i]<15)
cout<<”Number=”<<a[i]<<” “<<”endex=”<<i+1endl;
}
getch();
}
#include <iostream.h>
#include <conio.h>
int const n=7;
int a[n];
int i;
main()
{
cout<<”Enter Numbers of vector A:”<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<”Vector A”<<endl<<”_______”<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
cout<<”Numbers which are between 5 & 15:”<<endl<<”___________________________________”<<endl;
for(i=0;i<n;i++)
{
if(a[i]>5&&a[i]<15)
cout<<”Number=”<<a[i]<<endl;
}
getch();
}
Enter the numbers of vector A:
2 3 5 6 15 7 16
Vector A
________
2
3
5
6
15
7
16
Numbers which are between 5 & 15:
_____________________________
Number=6
Number=7
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
9 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
main()
{
int const n=4,m=3,s=n+m;
int a[n];
int b[m];
int c[s];
int i=0,j=4;
cout<<"enter number vector A:n";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter number vector B:n";
for(i=0;i<m;i++)
cin>>b[i];
cout<<"n";
cout<<"A:";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"B:";
for(i=0;i<m;i++)
cout<<b[i]<<" ";
cout<<"n";
cout<<"C:";
for(i=0;i<s;i++)
c[i]=a[i];
for(i=0;i<m;i++)
{
c[j]=b[i];
j=j+1;
}
for(i=0;i<s;i++)
cout<<c[i]<<" ";
getch();
}
7/A/Write C++ program to read and print out the vector of An and Bm then Create the vector Cs by integrating the
vector A and B.
7‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‬‫خوێندنه‬‌‫وه‬‌‫و‌چاپ‌کردنی‌ڤێکته‬‌‌‫ری‬A‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫وه‬‌‌‫ڤێکته‬‌‌‫ری‬B‌‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬m‌‫.‌پاشان‌دروست‌کردنی‌ڤێکته‬‌‌‫ری‬C‌‫به‬‌‌
‫یه‬‌‫کخستنی‌ڤێکته‬‌‌‫ری‬A‌‌‫و‬B‌.‌
‌
a[0]
a[1]
a[2]
a[3]
c[0]
c[1]
c[2]
c[3]
c[4]
c[5]
c[6]
b[0]
b[1]
b[2]
A
C
B
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
10 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
7/B/Write C++ program to read and print out the vector of An and Bn then Create the vector C by integrating the
vector A and B.
7‌//‌‫ب‬‫به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‬‫خوێندنه‬‌‫وه‬‌‫و‌چاپ‌کردنی‌ڤێکته‬‌‌‫ری‬A‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫وه‬‌‌‫ڤێکته‬‌‌‫ری‬n‌‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫.‌پاشان‌دروست‌کردنی‌ڤێکته‬‌‌‫ری‬C‌
‫به‬‌‌‫یه‬‌‫کخستنی‌ڤێکته‬‌‌‫ری‬A‌‌‫و‬B‌.‌
#include <iostream.h>
#include <conio.h>
int const n=4,m=2*n;
int a[n],b[n],c[m];
int i;
main()
{
Cout<<”Enter the numbers of A and B"<<endl;
for(i=0;i<n;i++)
cin>>a[i]>>b[i];
cout<<"A B"<<endl<<"_______"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<" "<<b[i]<<endl;
cout<<endl;
cout<<"C"<<endl<<"___"<<endl;
for(i=0;i<m;i++)
{
c[i]=a[i];
c[i]=b[i-n];
cout<<c[i]<<endl;
}
getch();
}
Enter the numbers of vector A and B:
1 5 2 6 3 7 4 8
A B
______
1 5
2 6
3 7
4 8
C
__
1
2
3
4
5
6
7
8
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
11 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
8/write C++ program to read and print out the vector A and the vector B then print the
subscripts of the command Rules between A and B.
a[1]=3 b[3]=3
a[0]=2
a[1]=3
a[2]=5
a[3]=6
b[0]=1
b[1]=9
b[2]=8
b[3]=3
#include <iostream.h>
#include <conio.h>
main()
{
int const n=4;
int a[n]={2,3,5,6};
int b[n]={1,9,8,3};
int i,j;
cout<<"A"<<endl<<"_"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
cout<<endl;
cout<<"B"<<endl<<"_"<<endl;
for(i=0;i<n;i++)
cout<<b[i]<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==b[j])
cout<<"a["<<i<<"]="<<a[i]<<" "<<"b["<<j<<"]="<<b[j]<<endl;
}
}
getch();
}
A B
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
12 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
9/ Write a C++ program to add order, name and degree, and then find the Maximize of degree and
calculating all degree.
9‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫ب‬‫ۆ‌داخڵ‌کردنی‌ژماره‬‌‌‫و‌ناو‌و‌نمره‬‌‫،‌پاشان‌به‬‌‌‫رزترین‬‫نمره‬‌‌‫بدۆزه‬‌‫ره‬‌‫وه‬‌‌‫له‬‌‫گه‬‌‫ڵ‌کۆکردنه‬‌‫وه‬‌‫ی‌هه‬‌‫موو‌نمره‬‌‫کان‬‌
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
int const n=5;
int a[n];
string b[n];
int i,m,s;
main()
{
cout<<"Enter Name and Degree for 5 student:"<<endl;
for(i=0;i<n;i++)
cin>>b[i]>>a[i];
cout<<endl;
cout<<"Order"<<"t"<<"Name"<<"t"<<"Degree"<<"t"<<endl;
cout<<"_____"<<"t"<<"_____"<<"t"<<"_____"<<endl;
for(i=0;i<n;i++)
cout<<(i+1)<<"t"<<b[i]<<"t"<<a[i]<<endl;
cout<<endl;
m=a[0];
for(i=0;i<n;i++)
if(m<a[i])
m=a[i];
cout<<"Maximize Degree="<<m;
cout<<"t";
s=0;
for(i=0;i<n;i++)
s=s+a[i];
cout<<"All degree="<<s;
getch();
}
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
13 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
//write c++ program to read and print out this table and find the maximize number with its index.
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
main()
{
int const n=3;
string a[n],r;
int b[n];
int i,m,h;
cout<<"Enter Names and degrees"<<endl;
for(i=0;i<n;i++) Input
cin>>a[i]>>b[i];
cout<<"ORDER"<<"t"<<" Name "<<"t"<<"Degree"<<endl<<"_____________________"<<endl;
for(i=0;i<n;i++) Output
cout<<i+1<<"t"<<a[i]<<"t"<<b[i]<<endl;
cout<<"_____________________"<<endl;
for(i=0;i<n;i++)
m=b[0];
for(i=0;i<n;i++)
{ Compare of Maximum number
if(m<b[i])
{
m=b[i];
r=a[i]; for showing the Maximum N.’s Name
h=i+1; For Showing the number of Index
}
}
cout<<"a["<<h<<"]"<<" "<<r<<":"<<m; Output of Index ,Maximum Number and the Name.
getch();
}
‌‌‌‌
Order Name Degree
1 Aram 82
2 Chawan 94
3 Suren 78
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
14 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
1. #include <iostream.h>
2. #include <conio.h>
3. int const n=4;
4. int a[n];
5. int b[n];
6. int i,k;
7. main()
8. {
9. for(i=0;i<n;i++)
10. cin>>a[i]>>b[i];
11. cout<<endl;
12. cout<<"A"<<"t"<<"B"<<endl<<"__"<<"t"<<"__"<<endl;
13. for(i=0;i<n;i++)
14. cout<<a[i]<<"t"<<b[i]<<endl;
15. cout<<endl;
16. for(i=0;i<n;i++)
17. {
18. k=a[i]+b[i];
19. if(k>10)
20. cout<<"The value which is greater than ten="<<k<<endl;
21. }
22. getch();
23. }
11/ Assume that we have two lists of integer values.
Write C++ program to print all pairs of values which are add up to ten.
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
15 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
int const n=5;
int a[n];
int i;
main()
{
for(i=0;i<n;i++)
cin>>a[i];
cout<<endl;
cout<<"A"<<endl<<"__"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
if(a[i]%6==0)
cout<<"The number which is divided by six="<<a[i]<<endl;
else
cout<<"The reminder number="<<a[i]<<endl;
}
getch();
}
12/ Write C++ Program to read a set of n integer values. Print the number and reminder
when the number is divided by 6.
12‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‫ی‌کۆمه‬‌‫ڵێک‌نرخی‌ته‬‌‫واو‌پاشان‌ئه‬‌‫و‌ژمارانه‬‌‌‫و‌ماوه‬‌‫که‬‌‫ی‌چاپ‌بکه‬‌‌‫که‬‌‌‫دابه‬‌‌‫ش‬
‫ده‬‌‫بێ‌به‬‌‫سه‬‌‫ر‌ژماره‬‌‌6‌.‫دا‬
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
16 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
1. #include <iostream.h>
2. #include <conio.h>
3. #include <math.h>
4. int i,n,r,x,y;
5. main()
6. {
7. cout<<"N=";
8. cin>>n;
9. cout<<endl;
10. r=0;
11. for(i=0;i<n;i++)
12. {
13. cout<<"Y=";
14. cin>>y;
15. cout<<"X=";
16. cin>>x;
17. r=r+pow(y,3)*x;
18. }
19. cout<<"Result="<<r;
20. getch();
21. }
13/Write C++ program to evaluate the value of r, which is defined as follows:
r=∑ 3
i * Xi = Y3
1*X1 + Y3
2*X2 + … +Y3
n*Xn
Explain: r= Y3
1*X1 + Y3
2*X2 + Y3
3*X3 … +Y3
n*Xn
r= 23
*3+33
*4+13
*5
r= 8*3+27*4+1*5 >>> r= 24+108+5 >>> r= 137
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
17 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
int const n=4;
int a[n];
int i, sum=0;
float m;
main()
{
cout<<"Enter four numbersn";
for(i=0;i<n;i++)
cin>>a[i];
cout<<endl;
cout<<"A"<<endl<<"___"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
sum=sum+a[i];
m=sum/n;
}
cout<<"Sum="<<sum<<" "<<"Mean Value="<<m;
cout<<endl;
for(i=0;i<n;i++)
{
if(a[i]>m)
cout<<"Greter Number="<<a[i]<<endl;
}
getch();
}
14/write C++ program to read a set of 20 numbers and calculate their mean value ,print out those
numbers which are greater than the mean value.
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
18 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
int const n=4;
int a[n];
int b[n];
int i,m;
main()
{
cout<<"Enter four pair integers number:"<<endl;
for(i=0;i<n;i++)
cin>>a[i]>>b[i];
cout<<endl;
cout<<"Order"<<"t"<<"A"<<"t"<<"B"<<endl;
cout<<"_____"<<"t"<<"_"<<"t"<<"_"<<endl;
for(i=0;i<n;i++)
cout<<" "<<i+1<<"t"<<a[i]<<"t"<<b[i]<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
if(a[i]%b[i]==0)
cout<<"Order="<<""<<i+1<<""<<"t"<<"First
Order="<<a[i]<<"t"<<"Second Order="<<b[i]<<endl;
}
getch();
}
15/ Write C++ program to read a list of pair integers, then print those order pairs which first
order divided by second order.
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
19 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
int const n=4;
string name[n];
string dep[n];
string col[n];
string x;
int i;
main()
{
cout<<"Enter Name,Department and College of FOUR Students:"<<endl;
for(i=0;i<n;i++)
cin>>name[i]>>dep[i]>>col[i];
cout<<endl;
cout<<" Name "<<" "<<"Department"<<" "<<" College "<<endl;
cout<<"______"<<" "<<"__________"<<" "<<"____________"<<endl;
for(i=0;i<n;i++)
cout<<name[i]<<"t"<<dep[i]<<"tt"<<col[i]<<endl;
cout<<"_____________________________"<<endl;
cout<<"Search:";
cin>>x;
for(i=0;i<n;i++)
{
if(name[i]==x)
cout<<"Found:"<<" "<<"Dep:"<<dep[i]<<"t"<<"Col:"<<col[i]<<endl;
}
getch();
}
16/Write C++ program to read and print out this table:
Name Department college
---- ------------ ------
---- ------------ ------
---- ------------ ------
Check whether the name Talar is in the list or not? If the name is in the list print its
department and college.
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
20 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
int const n=10;
int a[n];
int i,c,j;
main()
{
cout<<"Enter numbers"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<endl;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
c=a[j];
a[j]=a[i];
a[i]=c;
}
}
}
cout<<" A "<<endl<<"___"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
getch();
}
17/Write C++ program to sort a set of n numbers (Data Array) in ASCENDING order.
‫تێبینی‬1‫/‌ئه‬‌‫گه‬‌‫ر‌بمانه‬‌‫وێ‌ژماره‬‌‫کان‌له‬‌‌‫گه‬‌‫وره‬‌‫وه‬‌‌‫بۆ‌بچووک‌ڕیزبکاته‬‌‌‫ته‬‌‫نها‌ئه‬‌‫مه‬‌‌‫ده‬‌‌‫گۆڕین‬
if(a[j]>a[i])
‫تێبینی‬2‫:‌هه‬‌‫ندێ‌جار‌له‬‌‌‫به‬‌‫رنامه‬‌‫کانده‬‌‌‫ئه‬‌‫مانه‬‌‌‫به‬‌‫کار‌ده‬‌:‌‫هێنین‬‌
1/‌<<”t”‌‫ئه‬‌‫مه‬‌‌‫له‬‌‌‫جیاتی‬Space‌‫بۆشایی‌به‬‌‫کاردێت‌که‬‌‌6 Space‌‫ده‬‌‫نوێنێت‌و‌زۆر‌جوان‌نوسینه‬‌‫کان‌ده‬‌‫رده‬‌‫چن‌له‬‌‌
‫ڕیزه‬‌‫کاندا‌بۆیه‬‌‌‫باشتره‬‌‌‫ئه‬‌‫مه‬‌‌‫باکاربهێنین‌له‬‌‌‫باتی‬Space‌<<” “=‌.‌
2‌/<<”n”‌‫ئه‬‌‫مه‬‌‌‫به‬‌‫مانی‌ڕیزێکی‌نوێ‌دێت‌و‌کورتکراوه‬‌"‫ی‬newline‌‫"ه‬‌‌‫وه‬‌‌‫ده‬‌‫توانین‌له‬‌‌‫جیاتی‌ئه‬‌‫مه‬‌‌‌
‌‫ئامڕازی‬<<endl;‌‫به‬‌.‌‫کاربهێنین‬‌
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
21 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
18/Write program to read and print out this table
Name Degree
Ala 80
Sara 20
---- ----
Rewrite this table after rearrange degree from largest to smallest.
‌
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
int const n=3;
string a[n];
string k;
int b[n];
int i,j,c;
main()
{
cout<<"Enter Name and Degree‌for three student:"<<endl;
for(i=0;i<n;i++)
cin>>a[i]>>b[i];
cout<<endl;
cout<<"Name"<<"t"<<"Degree"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"t"<<b[i]<<endl;
cout<<endl;
cout<<”The table after Rearrange degree”<<endl;
cout<<”____________________________” <<endl;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(b[j]>b[i])
{
c=b[j];
k=a[j];
b[j]=b[i];
a[j]=a[i];
b[i]=c;
a[i]=k;
}
}
cout<<"Name"<<"t"<<"Degree"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"t"<<b[i]<<endl;
getch();
}
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
22 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
#include <iostream.h>
#include <conio.h>
#include <cstring.h>
int const n=4;
string a[n];
int b[n];
string x[n];
int i;
main()
{
cout<<"Enter Name and Degree for four students:"<<endl;
for(i=0;i<n;i++)
cin>>a[i]>>b[i];
cout<<endl;
for(i=0;i<n;i++)
{
if(b[i]>=90&&b[i]<=100)
x[i]="A";
if(b[i]>=80&&b[i]<90)
x[i]="B";
if(b[i]>=70&&b[i]<80)
x[i]="C";
if(b[i]<70)
x[i]="D";
}
cout<<"Name"<<"t"<<"Degree"<<"t"<<"Grade"<<endl;
cout<<"_______________________________"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"t"<<b[i]<<"t"<<x[i]<<endl;
cout<<"_______________________________"<<endl;
cout<<"ARAM CSD -- C++ PROGRAMMING";
getch();
}
19/Write C++ program to print this table
Name Degree Grade
Alan 87 B
Sara 95 A
Akam 62 D
Lana 78 C
if the degree between 90 and 100 write in Grade A
if the degree between 80 and 90 write in Grade B
if the degree between 70 and 80 write in Grade C
if the degree less than 70 write in Grade D
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
23 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
20/ Write a program to develop the Vector A with 4 rows, from this list 49 633 2 5.
First row divisible by 2,
second row divisible by 5,
third row divisible by 3 and
last row divisible by 7.
#include <iostream.h>
#include <conio.h>
int const n=4;
float a[n]={49,633,2,5};
int i,j;
float div,res;
main()
{
cout<<endl;
cout<<"Vector A"<<endl;
cout<<"________"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"n";
cout<<endl;
cout<<"_________________"<<endl;
res=a[0]/2;
cout<<"First Result="<<res<<endl;
cout<<"_________________n"<<endl;
res=a[1]/5;
cout<<"Second Result="<<res<<endl;
cout<<"_________________n"<<endl;
res=a[2]/3;
cout<<"Third Result="<<res<<endl;
cout<<"_________________n"<<endl;
res=a[3]/7;
cout<<"Last Result="<<res<<endl;
cout<<"_________________n"<<endl;
getch();
}
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
24 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
21/Write C++ program to read
and print out the Vector An . Then
find the Mean of the vector An
#include <iostream.h>
#include <conio.h>
int const n=3;
int a[n];
int i;
float sum,m;
main()
{
for(i=0;i<n;i++)
cin>>a[i];
cout<<endl;
cout<<"A"<<endl<<"__"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
cout<<endl;
sum=0;
for(i=0;i<n;i++)
sum=sum+a[i];
m=sum/n;
cout<<"Mean of the vector A="<<m;
getch();
}
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
25 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
‌

More Related Content

Viewers also liked

TFG DIPUTACIÓ DE BARCELONA
TFG DIPUTACIÓ DE BARCELONA TFG DIPUTACIÓ DE BARCELONA
TFG DIPUTACIÓ DE BARCELONA cocarroideceba
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAram SE
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAram SE
 
C++ programming flowchart. home work t.hemn
C++ programming flowchart. home work t.hemnC++ programming flowchart. home work t.hemn
C++ programming flowchart. home work t.hemnAram SE
 
Controle automatico de_processos
Controle automatico de_processosControle automatico de_processos
Controle automatico de_processosWilliam Andrade
 
Access lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAccess lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAram SE
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scriptingAkshay Siwal
 
Breakfast club oktober 2013
Breakfast club oktober 2013Breakfast club oktober 2013
Breakfast club oktober 2013AmalieFrom
 

Viewers also liked (10)

TFG BUFF
TFG BUFFTFG BUFF
TFG BUFF
 
85
8585
85
 
TFG DIPUTACIÓ DE BARCELONA
TFG DIPUTACIÓ DE BARCELONA TFG DIPUTACIÓ DE BARCELONA
TFG DIPUTACIÓ DE BARCELONA
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a Database
 
Access lesson 02 Creating a Database
Access lesson 02 Creating a DatabaseAccess lesson 02 Creating a Database
Access lesson 02 Creating a Database
 
C++ programming flowchart. home work t.hemn
C++ programming flowchart. home work t.hemnC++ programming flowchart. home work t.hemn
C++ programming flowchart. home work t.hemn
 
Controle automatico de_processos
Controle automatico de_processosControle automatico de_processos
Controle automatico de_processos
 
Access lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access BasicsAccess lesson 01 Microsoft Access Basics
Access lesson 01 Microsoft Access Basics
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Breakfast club oktober 2013
Breakfast club oktober 2013Breakfast club oktober 2013
Breakfast club oktober 2013
 

Similar to 2 arrays in c++ programming aramse

سی پلاس پلاس به عنوان زبان دومی برای یادگیری شی گرایی
سی پلاس پلاس به عنوان زبان دومی  برای یادگیری شی گراییسی پلاس پلاس به عنوان زبان دومی  برای یادگیری شی گرایی
سی پلاس پلاس به عنوان زبان دومی برای یادگیری شی گراییmrm_196
 
Advance programming c++
Advance programming c++Advance programming c++
Advance programming c++AliNazarizadeh
 
Jozve c#2 mohamady_zahedy
Jozve c#2 mohamady_zahedyJozve c#2 mohamady_zahedy
Jozve c#2 mohamady_zahedydanesh_fd
 
1. preface, hello world
1. preface, hello world1. preface, hello world
1. preface, hello worldVahid Heidari
 
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسان
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسانبرنامه سازی 2- اعظم صالح-هنرستان جنت فارسان
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسانtarasad
 

Similar to 2 arrays in c++ programming aramse (6)

سی پلاس پلاس به عنوان زبان دومی برای یادگیری شی گرایی
سی پلاس پلاس به عنوان زبان دومی  برای یادگیری شی گراییسی پلاس پلاس به عنوان زبان دومی  برای یادگیری شی گرایی
سی پلاس پلاس به عنوان زبان دومی برای یادگیری شی گرایی
 
Advance programming c++
Advance programming c++Advance programming c++
Advance programming c++
 
Jozve c#2 mohamady_zahedy
Jozve c#2 mohamady_zahedyJozve c#2 mohamady_zahedy
Jozve c#2 mohamady_zahedy
 
1. preface, hello world
1. preface, hello world1. preface, hello world
1. preface, hello world
 
vb.net
vb.netvb.net
vb.net
 
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسان
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسانبرنامه سازی 2- اعظم صالح-هنرستان جنت فارسان
برنامه سازی 2- اعظم صالح-هنرستان جنت فارسان
 

2 arrays in c++ programming aramse

  • 1. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 1 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‫ڕیزکراوه‬‌‫کان‬:‌‫له‬‌‌‫کۆمه‬‌‫ڵێک‌دانه‬‌‌‫پێک‌هاتووه‬‌‌‫ک‬‫ه‬‌‌‫یه‬‌‌‫ک‌دووری‬‫هه‬‌‫یه‬‌‌‫که‬‌‌‫به‬‌‫شێوه‬‌‫یه‬‌‫کی‌ئاسۆی‌یان‌ستوونی‌ته‬‌‫نها‌یه‬‌‌‫ک‬ ‫ڕیز‌ده‬‌‫گرێته‬‌‫وه‬‌‌‫بۆیه‬‌‌‫پێی‌ده‬‌‌‫ڵێن‬(One Dimension)‌‫یان‬‌‌‫ڤێکتۆر‬(Vector)‌‌‫که‬‌‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫هێما‌ده‬‌‌‫کرێت‬‌A‌‫وه‬‌‌‫به‬‌‌ ‫یه‬‌‫ک‌قه‬‌‫باره‬‌‌‫دیاری‌د‬‫ه‬‌‫کرێت‌که‬‌‌‫ده‬‌‫کاته‬‌‌‫ژماره‬‌‫ی‌ئه‬‌‫و‌دانانه‬‌‫ی‌که‬‌‌‫له‬‌‌‫ڕیزه‬‌‫که‬‌.‫دان‬‌ ‌ ‫یاسای‌گشتی‌ڕیزکراوه‬‌‫کانیش‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌:‫بێت‬ Type const size=? ; Type name[size]; ‫سه‬‌‫ره‬‌‫تا‌پێویسته‬‌‌‫وه‬‌‫کو‌هه‬‌‫موو‌به‬‌‫رنامه‬‌‌(‌‫کانی‌پێشوو‬Header‫)ی‌بۆ‌بنووسین‌که‬‌‌‫به‬‌‫شێکی‌سه‬‌‫ره‬‌‫کی‌به‬‌‫رنامه‬‌‫که‬‌‫یه‬‌.‌ ‫وه‬‌‌‫ئه‬‌‫گه‬‌‫ر‌پێویستمان‌به‬‌‌‫هه‬‌‫ر‌جۆر‌کردارێکی‌تر‌بوو‌ده‬‌‫بێ‌له‬‌‌(Header)‫دا‌زیادی‌بکه‬‌‫ین‌وه‬‌‌‫ک‌(حساباتی‌بیرکاری‬ ‫که‬‌‌‫توانی)‌تێده‬‌‫که‬‌‌(‫وێت،‌یان‌نووسین‬‫تێکست‌و‌حه‬‌‫رف)‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌.‫دا‬ 1. #include <iostream.h> 2. #include <conio.h> 3. #include <math.h> 4. #include <cstring.h> ‫خاڵی‬1‌‫و‬2‌‫سه‬‌‫ره‬‌‫کین‌بۆ‌هێده‬‌‫ره‬‌‫که‬‌‌‫که‬‌‌‫ده‬‌‫بێت‌له‬‌‌‫هه‬‌‫موو‌به‬‌‫رنامه‬‌‫یه‬‌‫کدا‌بنووسرێت‌به‬‌:‫اڵم‬ ‌‫خاڵێ‬3‌‫به‬‌‫کاردێت‌بۆ‌(حساباتی‌بیرکاری‌که‬‌‌‫توان،‌ڕه‬‌‌‫گ‬‫،‌ته‬‌.)...‌‫ژێ‬ ‌‫خاڵی‬4‌‫به‬‌‫کاردێت‌بۆ‌(‌تێکست‌و‌حه‬‌‫رف)‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌.‫دا‬ ‫پاشان‌ده‬‌‫چینه‬‌‌‫به‬‌‌‫شی‬(Declaration)‌‫که‬‌‌‫ئه‬‌‫م‌به‬‌‫شه‬‌‌‫به‬‌‌‫مانای‌لێدوان‌دێت‌که‬‌‌‫تیایدا‌ئه‬‌‫وشتانه‬‌‫ی‌که‬‌‌‫پێویستمانه‬‌‌‫ده‬‌‌‫یان‬ ‫ناسێنین‌به‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‌‫ئه‬‌‫میش‌چوار‌جۆره‬‌‌:‌ 1. int ‌‫به‬‌‫کاردێت‌بۆ‌ژماره‬‌‫ی‌ته‬‌‫واوه‬‌‌‌‫کان‬ 2. float ‌‫به‬‌‫کاردێت‌بۆ‌ژماره‌ڕێژه‬‌‫یه‬‌‌‫کان‬‌ 3. string ‌‫به‬‌‫کاردێت‌بۆ‌نوسینی‌وشه‬‌‌‌‫یان‌ناو‬ 4. char ‌‫به‬‌‫کاردێت‌بۆ‌نوسینی‌ته‬‌‫نها‌یه‬‌‫ک‌حه‬‌‌‫رف‬ ‫له‬‌‌‫ڕیزکراوه‬‌‫کاندا‌پێویستمان‌به‬‌‌‫نه‬‌‫گۆڕێک‌یان‌زیاتر‌ده‬‌‫بێت‌که‬‌‌‫له‬‌‌‫دوای‬(Header)‫وه‬‌‌‫ده‬‌‫نووسرێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌:‌ Type const size=? ;‌ “Type”‌‫پێویسته‬‌‌‫به‬‌‌‫ژماره‬‌‫ی‌ته‬‌‫واو‌داخلی‌بکه‬‌‫ین‌که‬‌‌(int)‌‫به‬‌.‌‫کاردێت‬‌ “const”‌‫واته‬‌‌‫نه‬‌‫گۆڕ‬‌‫مه‬‌‫به‬‌‫ست‌له‬‌‌‫ژماره‬‌‫ی‌دانه‬‌‫کانه‬‌‌‫ئه‬‌‫م‌وشه‬‌‫یه‬‌‌‫ده‬‌.‫ستکاری‌ناکرێت‬‌
  • 2. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 2 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar “size=”‌‫ئه‬‌‫مه‬‌‫ش‌واته‬‌‌‫قه‬‌‫باره‬‌‫ی‌ڕیزه‬‌‫که‬‌‌‫که‬‌‌‫چه‬‌‫ند‌دانه‬‌‫ی‌تێدایه‬‌‌‫خۆمان‌دیاری‌ده‬‌‫که‬‌‫ی‬‫ن‌یان‌به‬‌‫پێی‌پرسیاره‬‌‫که‬‌.‌ ‫بۆ‌نمونه‬‌‌:‌ Int const size=3; ‫ده‬‌‌‫توانین‌ناوی‬(size)‌‫بگۆڕین‌به‬‌‌‫هه‬‌‫ر‌حه‬‌‫رفێک‌به‬‌‌‫ئاره‬‌‫زوی‌خۆمان‬”n,m,l,k”‌‫،به‬‌‫اڵم‌پێویسته‬‌‌‫ئاگادار‌بین‌ئه‬‌‌‫و‬ ‫حه‬‌‫رفه‬‌‌‫له‬‌‌‫کرداری‌تردا‌به‬‌‫کاری‌نه‬‌‫هێنین‌وه‬‌‌‫نابێت‌دوو‌جار‌پێناسه‬‌‫ی‌بکه‬‌.‌‫ین‬ ‫به‬‌‌‫شێکی‌تری‬‫ڕیزکراوه‬‌‫کان‌بریتیه‬‌‌‫له‬‌‌‌‫ناساندنی‌ئه‬‌‫و‌شتانه‬‌‫ی‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‫دا‌به‬‌‫کاری‌ده‬‌‫هێنین‬‌‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌ Int array[size1]; Type k,l,sum,m; ‫پاشان‌هه‬‌‫ر‌شتێکمان‌به‬‌‫کارهێنا‌پێوستبوو‌بیناسێنین‌وه‬‌(‌‫ک‬i,j,n,k,l,m,‌‌‌)‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌int i; ‌‫پاشان‬main() {‌‌‌ ‫ده‬‌‫نووسین‌ده‬‌‫ست‌ده‬‌‫که‬‌‫ین‌به‬‌‌‫به‬‌‫رنامه‬‌‌‫داڕشتنه‬‌‫که‬‌.‌ ‫ته‬‌‫نها‌ئه‬‌‫وشتا‌نه‬‌‫بێت‌که‬‌‌‫له‬‌‫سه‬‌‫ره‬‌‫وه‬‌‌‫ناساندوومانه‬‌‌‫وه‬‌‫ک‌قه‬‌‫باره‬‌‌‫و‌ناو‌‌وه‬‌‌‫نابێت‌دووباره‬‌‌.‫بیان‌ناسێنین‬‌ ‫له‬‌‌‫ڕیزکراوه‬‌‫کاندا‌بۆ‌زۆربه‬‌‫ی‌کرداره‬‌‫کانی‌وه‬‌‌‫ک‬(cin,cout,if,swap,sum,count,multi,mean)‌‫پێویستمان‌به‬‌‌ ‫ته‬‌‫نها‌یه‬‌‫ک‌لووپ‌ده‬‌‫بێت‌ئه‬‌‫گه‬‌‫ر‌قه‬‌‫باره‬‌‌‫نه‬‌‫گۆڕبێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌ for(i=0;i<size;i++) { _____ _____ } ‌‌(‌‫أ/‌داغڵ‌کردن‬cin>>‫):‌بۆ‌نموونه:‌ڤێکته‬‌‫ری‬‌An‫که‬‌‌‫قه‬‌‫باره‬‌‌‫کامان‬n=2‌‫قه‬‌‫باره‬‌‫یان‌یه‬‌‫کسانه‬‌ int const n=2; int a[n]; int I, for(i=0;i<n;i++) { cin>>a[i]; }
  • 3. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 3 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‫لێره‬‌‫دا‌مه‬‌‫به‬‌‫ستمان‌له‬‌‌a[n]‌‌‫و‬a[i]‌‫چی‌یه‬‌‌‫؟‬‌ ‫مه‬‌‫به‬‌‫ست‌له‬‌‌a[n]‌‫واته‬‌‌‫ڤێکته‬‌‫رێکمان‌هه‬‌‫یه‬‌‌‫به‬‌‌‌‫ناوی‬a‌‫وه‬‌‌‫قه‬‌‫باره‬‌‫ی‌ئه‬‌‫م‌ڤێکته‬‌‫ره‬‌‌n‌‫قه‬‌‫باره‬‌‫یه‬‌‌‫که‬‌‌‫ژماره‬‌‫ی‌دانه‬‌‌‫کانی‬ ‫ڤێکته‬‌‫ره‬‌‫که‬‌‌‫ده‬‌‫گرێته‬‌‫وه‬‌‌‫وه‬‌‌‫ئه‬‌‫م‌هێمایه‬‌‌‫ته‬‌‫نها‌له‬‌‌‫سه‬‌‫ره‬‌‫تادا‌داخڵ‌ده‬‌‫کرێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌.‌ ‌ ‌ ‫مه‬‌‫به‬‌‫ست‌له‬‌‌a[i]‌‫ئه‬‌‫وه‬‌‫یه‬‌‌‫که‬‌‌‫دانه‬‌‫کان‌به‬‌‌‫پێی‬i‌‫داخل‌یان‌ده‬‌‫ست‌که‬‌‫وت‌یان‌هه‬‌‫ر‌کردارێکی‌تر‌به‬‌‫ستراوه‬‌‌:‌ ‫بۆ‌نموونه‬‌‌‫ئێمه‬‌‌‫ڤێ‬‫کته‬‌‫رێکمان‌هه‬‌‫یه‬‌‌‫قه‬‌‫باره‬‌‫که‬‌‌‫ی‬3‌‫یه‬‌‌‫واته‬‌‌int const n=3; ‫وه‬‌‌‫لووپه‬‌‫که‬‌‫شمان‌به‬‌‌i‌‫هێما‌ده‬‌‫که‬‌‫ین‌که‬‌‌‫له‬‌‌0‌‫ده‬‌‫ستپێده‬‌‫کات‌تا‌دانه‬‌‫یه‬‌‫ک‌که‬‌‫متر‌له‬‌‌‫ژماره‬‌‌‫ی‬n‌‫واته‬‌‌3‌ ‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌int i;‌‫وه‬‌‌‫لووپه‬‌‫که‬‌‫ش‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌‌:‌‫بێ‬for(i=0;i<n;i++) ‫واته‬‌‌‫له‬‌‌0،1،2‌‫که‬‌‌‫ده‬‌‫کاته‬‌‌‌‫سێ‌،ژماره‬2‌‌‫بچوکتره‬‌‌‫له‬‌3‌ ‫به‬‌‫اڵم‌نرخه‬‌‌‫کان‬3‌‫دانه‬‌‫ن‌چونکه‬‌‌‫له‬‌‌0‌‫وه‬‌‌‫ده‬‌‫ست‌پێده‬‌‫کات؛‬‌ ‫مه‬‌‫به‬‌‫ستمان‌له‬‌‫مه‬‌‌‫ئه‬‌‫وه‬‌‫یه‬‌‌‫که‬‌‌‫هه‬‌‫ر‌نرخێک‌که‬‌‌‫داخڵی‌ده‬‌‫که‬‌‫ین‌یه‬‌‫کێک‌له‬‌‫و‌ژمارانه‬‌‌‌"0،1،2‫"‌ده‬‌‫گرێت‌و‌ده‬‌‫یکات‌به‬‌‌ ‫جێگای‌خۆی‌پێی‌ده‬‌‌‫ڵێن‬“index”‌‫یان‬“subscript”‌‌‫وه‬‌‌‫له‬‌‌‫ده‬‌‫رکه‬‌‫وتنی‌دا‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫ده‬‌‫رده‬‌‫که‬‌‫وێت‬‌ cout<<”a[“<<i+1<<”]=”; ‫ئه‬‌‫مه‬‌‌‌‫هێمای‬“index”‫ه‬‌‌‫واته‬‌‌‫کاتێک‌که‬‌‌i‌‫ده‬‌‫بێ‌به‬‌‌0‌+‌‫تۆ‬1‌‫بکه‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌به‬‌‫شێوه‬‌‫یه‬‌‫کی‌جوان‌ده‬‌‫ربکه‬‌‌‫وێت‬‌ ‫ئه‬‌‫مه‬‌‫ش‌له‬‌‌‫نموونه‬‌‫کاندا‌جوانتر‌ده‬‌‫رده‬‌‫که‬‌‫وێت‬:‌ A3 ‫دانه‬‌‫کان‬ index‌ a[i] i=0 ‌i=1‌ ‌i=2‌‌ ‫واته‬‌‌‫ئێستا‌ئێمه‬‌‌‫ئه‬‌‫گه‬‌‌‫ر‬index‌‫ی‌ژماره‬‌‌8‌‫مان‌بوێت‌ده‬‌‫کاته‬‌‌1‌‫بۆیه‬‌‌‌‫ده‬‌‌‫بێت‬i+1‌‫بکه‬‌‫ین‌بۆئه‬‌‫وه‬‌‌‫ی‌نرخی‌خۆی‬ ‫وه‬‌‫ربگرێت‌که‬‌‌‫له‬‌‌‫ڕاستیدا‌ژماره‬‌‌2‌‫ه‬‌.‌ cout<<”a[“<<i+1<<”]=”<<a[i]; ‫لێره‬‌‫دا‌کاتێک‌که‬‌‌‫ژماره‬‌‌‫داخڵ‌ده‬‌‫که‬‌‫ین‌ده‬‌‫بێ‌بزانین‌که‬‌‌‫یه‬‌‫که‬‌‫م‌ژماره‬‌‌‫ده‬‌‫چێته‬‌‌a[i=0]‌‫وه‬‌‌‫دووه‬‌‫م‌ژماره‬‌‌‫ده‬‌‫چێته‬‌‌a[i=1] ‫به‬‌‌‫م‬‌‫شێوه‬‌‫یه‬‌‌‫تا‌‌لوپ‌ته‬‌‫واو‌ده‬‌.‫بێت‬‌ ‌ a[2]3 8 a[1] a[0]6 a[2]=8
  • 4. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 4 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‫تێبینی‌//‌به‬‌‫هیچ‌شێوه‬‌‫یه‬‌‌‫ک‬cin>>‌‫واته‬‌‌‌‫ئینپوت‬<<endl‌‌‫و‬<<” “‌‫وه‬‌‫رناگرێت‌راسته‬‌‫وخۆ‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌ cin>>a[i] <<endl<<” “; cin>>a[i]; cout<<endl<<” “; ‫لێره‬‌‫ده‬‌‌‫پێش‌ئه‬‌‫وه‬‌‫ی‌ب‬‫اسی‌ده‬‌‫ستکه‬‌‌‫وت‬(cout<<)‫بکه‬‌‫ین‌پێویسته‬‌‌‫جوانکاریه‬‌‫ک‌دابنێین‌بۆ‌به‬‌‫رنامه‬‌‫که‬‌‌‫مان‬‌ ‫وه‬‌‌‫ئه‬‌‌‫م‬cout‌‫ی‌جوانکاریه‬‌‌‫هه‬‌‫میشه‬‌‌‫ده‬‌‫بێت‌له‬‌‫پێش‌لووپه‬‌‫وه‬‌‌“for”‌‫بنووسرێت‌بۆ‌ئه‬‌‫وه‬‌‫ی‌ته‬‌‫نها‌یه‬‌‫ک‌جار‌له‬‌‫سه‬‌‌‫ر‬ ‫شاشه‬‌‫که‬‌‌‫ده‬‌‫رکه‬‌‫وێت‌به‬‌‫اڵم‌ئه‬‌‫گه‬‌‫ر‌له‬‌‌‫حساباتدا‌بوو‌ئه‬‌‫وا‌ده‬‌‫توانین‌بیخه‬‌‫ینه‬‌‌‫ناو‌لووپه‬‌‫که‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌له‬‌‫گه‬‌‫ڵ‌ئه‬‌‌‫نجامی‬ ‫هه‬‌‫موو‌کرداره‬‌‫کاندا‌ده‬‌‫ربکه‬‌‫وێت.‌ئه‬‌‫مه‬‌‫ش‌نووسینێکه‬‌‌‫ده‬‌‫که‬‌‫وێته‬‌‌‫نێوان‌دوو‌کۆته‬‌‌‫یشن‬“ “‌‫ک‬‫ه‬‌‌‫پێویست‌به‬‌‌‌‫ناساندن‬ ‫ناکات‌و‌به‬‌‌‫ئاره‬‌‫زووی‌خۆت‌ده‬‌‫توانی‌شتی‌تێدا‌بنووسیت‬‫وه‬‌‌‫له‬‌‌‌‫کۆتایدا‬<<endl;‌‫ده‬‌.‫نووسین‬‌ ‌‫به‬‌‫م‌شێوه‬‌‫یه‬‌:‌ cout<<”Enter Numbers of the Vector A:”<<endl; “cin>>” ‫له‬‌‌‫پێش‌داخڵ‌کردنی‌نرخ‌واته‬‌‌‌‌‫بۆ‬ cout<<”A”<<endl<<”___”<<endl; ‌‌/‫ب‬‫ده‬‌‫ستکه‬‌(‌‫وت‬cout<<‫)‌:ئه‬‌‫م‌به‬‌‫شه‬‌‌‫ئه‬‌‫نجامی‌ئه‬‌‫م‬‌‌‫کرداره‬‌‫مان‌ده‬‌‫داتێ‌که‬‌‌‫داخڵمان‌کردووه‬‌‌‫له‬‌‫سه‬‌‫ر‌شاشه‬‌‫که‬‌‌.‌ ‫به‬‌‫م‌شێوه‬‌‫یه‬‌‌:‌ for(i=0;i<n;i++) cout<<a[i]<<endl; endl‌‫واته‬‌‌‫به‬‌‫شێوه‬‌‫یه‬‌‫کی‌ستوونی‌بێت‌وه‬‌‌‫گه‬‌‫ر‌ویستمان‌به‬‌‌‫شێوه‬‌‫ی‌ئه‬‌‫سۆی‌بێت‌به‬‌‫م‌شێوه‬‌‫یه‬‌‌‫دایده‬‌‫نێین‬‌ for(i=0;i<n;i++) cout<<a[i]<<” “; ‫وه‬‌‌‫له‬‌‌‫دوا‌هه‬‌‫مووی‌ئه‬‌‫مانه‬‌‌‫بۆ‌ئه‬‌‫وه‬‌‫ی‌شاشه‬‌‌‫ڕه‬‌‫شه‬‌‫که‬‌‫مان‌بۆ‌ده‬‌‫ربکه‬‌‫وێت‌و‌النه‬‌‫چێت‌تا‌خۆمان‌دایده‬‌‫خه‬‌‌‫ین‬‫ده‬‌:‫نووسین‬‌ ‌getch(); } A __ 2 6 4 A : 2 6 4
  • 5. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 5 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‫نمونه‬‌‫یه‬‌‫ک‬‌‌‫له‬‌‫سه‬‌‫ر‌هه‬‌‫موو‌ئه‬‌‫و‌کردارانه‬‌:‫ی‌پێشوو‬‌ 1‫/‌ئه‬‌‫م‌نموونه‬‌‫یه‬‌‌‫له‬‌‫سه‬‌‫ر‌داخڵ‌کردنی‌ژماره‬‌‫ی‌ته‬‌‫واوه‬‌.‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ 2‫/‌ئه‬‌‫م‌نموونه‬‌‫یه‬‌‌‫له‬‌‫سه‬‌‫ر‌داخڵ‌کردنی‌نووسینه‬‌‌‫وه‬‌.‫ک‌ناو‬‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ #include <iostream.h> #include <conio.h> int const n=4; int a[n]; int i; main() { cout<<”enter the numbers of vector A:”<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<”A”<<endl<<”__”<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; getch(); } Enter Numbers of vector A: 3 5 7 9 A __ 3 5 7 9 #include <iostream.h> #include <conio.h> #include <cstring.h> int const n=3; string a[n]; int i; main() { cout<<”Enter the names of vector A:”<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<” a ”<<endl<<”_____”<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; getch(); } Enter Names of vector A: Richard Suzan Danny A _____ Richard Suzan Danny
  • 6. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 6 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‫ئه‬‌‫مه‬‌‫ش‌کۆمه‬‌‫ڵێک‌نموونه‬‌:‌ 3/write C++ programming to print out with index of the‌Marks vector: 10, 30, 60, 45, 34, 67. 1‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫که‬‌‌‫ئه‬‌‫م‌نمرانه‬‌‌‫چاپ‌بکات‌له‬‌‫گه‬‌‫ل‌جێگه‬‌.‫کانیان‬‌ ‌ 0‌ ‌ ‌ ‌ ‌ ‫تێبینی‌ئه‬‌‫م‌به‬‌‫رنامه‬‌‫یه‬‌‌‫پێویسته‬‌‌‫به‬‌‌‌‫داخڵ‌کردن‬(cin>>)‌‫ناکات‌چونکه‬‌‌‫خۆی‌نرخه‬‌‫کانی‌داوه‬‌‌‫به‬‌‫پێ‌ژماره‬‌‫ی‌نرخه‬‌‌‫کان‬ ‫قه‬‌‫باره‬‌‫که‬‌‌‫دیاری‌ده‬‌‫که‬‌‫ین‌و‌له‬‌‌‫ته‬‌‫نیشتی‌داخڵ‬‫ی‌ده‬‌‫که‬‌‫ینه‬‌‌‫ناو‌به‬‌‫رنامه‬‌‫که‬‌‫وه‬‌‌‫له‬‌‌‫به‬‌.‫شی‌پێناساندن‌دا‬‌ 4/Write C++ Program to read and print out a vector An then find the Maximize number of the vector. 2‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫کی‌سی‌پڵه‬‌‫س‌پڵه‬‌‫س‌بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‌‌‫و‌چاپکردنی‬‌‫ڤێکتۆرێکی‬An‌‫،‌پاشان‬‫گه‬‌‫وره‬‌‫ترین‬‌‫ژماره‬‌‌‫بدۆزه‬‌‫ره‬‌‫وه‬‌‌ ‌ #include <iostream.h> #include <conio.h> int mark[6]={10,30,60,45,34,67}; int i; main() { cout<<”Marks and Index”<<endl<<”_____________”<<endl; for(i=0;i<6;i++) cout<<"Mark("<<i+1<<")="<<mark[i]<<endl; getch(); } Marks and Index ______________ Mark(1)=10 Mark(2)=30 Mark(3)=60 Mark(4)=45 Mark(5)=34 Mark(6)=67 #include <iostream.h> #include <conio.h> int const n=6; int a[n]; int i,max1; main() { cout<<”Enter the Numbers of vector A:”<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<”Vector A”<<endl<<”_______”<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; max1=a[0]; for(i=0;i<n;i++) if(max1<a[i]) max1=a[i]; cout<<”Maximize Number=”<<max1; getch(); } Enter the numbers of vector A: 4 3 5 7 9 6 Vector A ________ 4 3 5 7 9 6 Maximize number=9
  • 7. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 7 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 5/Write C++ program to:- 1/set all ten Elements of Array A10 to zero . ‫واته‬‌‌‫هه‬‌‌‫موو‬10‌‫دانه‬‌‫که‬‌‫ی‌ڕیزه‬‌‫که‬‌‌‫بکه‬‌‌‫به‬‌‌‌‌‌‌‌‌‌‌‫سفر‬ 2/copy array A10 to array Bn. ‌‫واته‬‌‌‫ڕیزی‌‌‌کۆپی‌بکه‬‌‫ره‬‌‌‫ڕیزی‌‌‌‌وه‬‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌ ‌‫تێبینی:‌هێمای‬//‌‫که‬‌‌‫له‬‌‫ناو‌به‬‌‫رنامه‬‌‫که‬‌‫دا‌به‬‌‫کارمان‌هێناوه‬‌‌‫پێی‌ده‬‌‫ڵێن‌کۆمێنت‌وه‬‌‌‫ته‬‌‫نها‌له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‫دا‌ده‬‌‫رده‬‌‫که‬‌‌‫وێت‬‫بۆ‌تێگه‬‌‫شتنه‬‌‌‫له‬‌‌‫به‬‌‫رنامه‬‌‫که‬‌‌ ‫بۆ‌ئه‬‌‫و‌که‬‌‫سه‬‌‫ی‌کار‌له‬‌‫سه‬‌‫ر‌به‬‌‫رنامه‬‌‌‫دارێژیه‬‌‫که‬‌‌‫ده‬‌‫کات‬(Programmer)‌‫وه‬‌‌‫دوو‌شێوه‬‌‫ی‌هه‬‌‫یه‬:‌‌ 1‌‌‌.Comment//‌‫ئه‬‌‫مه‬‌‌‫ته‬‌‫ن‬‫ها‌بۆ‌دێرێک‌کۆمێنت‌به‬‌.‌‫کاردێت‬‌ 2‌./*Comment1 Comment2*/‌‌‌‌‌‫ئه‬‌‫مه‬‌‌‫به‬‌‫کاردێت‌بۆ‌دێڕێک‌زیاتر‌بۆ‌ڕوونکردنه‬‌‫وه‬‌‫ی‌به‬‌‫رنامه‬‌‫که‬‌.‌ #include <iostream.h> #include <conio.h> int const n=10; int a[n],b[n]; int i; main() { //1-set all ten elements of array A to zero. cout<<”Enter Ten Numbers of vector A:”<<endl; for(i=0;i<10;i++) cin>>a[i]; cout<<”Vector A”<<endl<<”_______”<<endl; for(i=0;i<n;i++) { a[i]=0; cout<<a[i]<<endl; } //2- Copy array A to Array B. cout<<”Enter Ten Numbers of vector A:”<<endl; for(i=0;i<10;i++) cin>>a[i]; cout<<”Vector B”<<endl<<”_______”<<endl; for(i=0;i<n;i++) { b[i]=a[i]; cout<<b[i]<<endl; } getch(); } Enter ten numbers of vector A: 4 3 5 7 9 6 2 0 1 7 Vector A ________ 0 0 0 0 0 0 0 0 0 0 Enter ten numbers of vector A: 4 3 5 7 9 6 2 0 1 7 Vector B ________ 4 3 5 7 9 6 2 0 1 7 AB
  • 8. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 8 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 6/Write C++ program to read and print out An. Then print those numbers which are line between 5 & 15. 6‫/‌به‬‌‫رنامه‬‌‫یه‬‌‌‫ک‬‌‫بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‌‫و‌چاپکردنی‌ڤێکتۆری‬A‌‫.‌پاشان‌ئه‬‌‫و‌ژمارانه‬‌‌‫چاپ‌بکه‬‌‌‫که‬‌‌‫ده‬‌‫که‬‌‫وێته‬‌‌‌‫نێوان‬5‌‌‫و‬15‌‫وه‬‌.‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ If we want index for the example we just add <<” “<<”index=”<<i+1<<endl; for last cout: ‫ئه‬‌‫گه‬‌‌‫ر‌ویستمان‬(index)‌‫دیاری‌بکه‬‌‫یه‬‌‫ن‌له‬‌‫و‌نموونه‬‌‫ی‌سه‬‌‫ره‬‌‫وه‬‌‫دا‌ئه‬‌‫وا‌ته‬‌‫نا‌ئه‬‌‫مه‬‌‌<<” “<<”index=”<<i+1<<endl;‫زیاد‌ده‬‌‫که‬‌‌‫ین‌بۆ‬ ‌‫کۆتا‬cout‌‌.‌ for(i=0;i<n;i++) { if(a[i]>5&&a[i]<15) cout<<”Number=”<<a[i]<<” “<<”endex=”<<i+1endl; } getch(); } #include <iostream.h> #include <conio.h> int const n=7; int a[n]; int i; main() { cout<<”Enter Numbers of vector A:”<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<”Vector A”<<endl<<”_______”<<endl; for(i=0;i<n;i++) { cout<<a[i]<<endl; } cout<<”Numbers which are between 5 & 15:”<<endl<<”___________________________________”<<endl; for(i=0;i<n;i++) { if(a[i]>5&&a[i]<15) cout<<”Number=”<<a[i]<<endl; } getch(); } Enter the numbers of vector A: 2 3 5 6 15 7 16 Vector A ________ 2 3 5 6 15 7 16 Numbers which are between 5 & 15: _____________________________ Number=6 Number=7
  • 9. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 9 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> main() { int const n=4,m=3,s=n+m; int a[n]; int b[m]; int c[s]; int i=0,j=4; cout<<"enter number vector A:n"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter number vector B:n"; for(i=0;i<m;i++) cin>>b[i]; cout<<"n"; cout<<"A:"; for(i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; cout<<"B:"; for(i=0;i<m;i++) cout<<b[i]<<" "; cout<<"n"; cout<<"C:"; for(i=0;i<s;i++) c[i]=a[i]; for(i=0;i<m;i++) { c[j]=b[i]; j=j+1; } for(i=0;i<s;i++) cout<<c[i]<<" "; getch(); } 7/A/Write C++ program to read and print out the vector of An and Bm then Create the vector Cs by integrating the vector A and B. 7‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‬‫خوێندنه‬‌‫وه‬‌‫و‌چاپ‌کردنی‌ڤێکته‬‌‌‫ری‬A‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫وه‬‌‌‫ڤێکته‬‌‌‫ری‬B‌‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬m‌‫.‌پاشان‌دروست‌کردنی‌ڤێکته‬‌‌‫ری‬C‌‫به‬‌‌ ‫یه‬‌‫کخستنی‌ڤێکته‬‌‌‫ری‬A‌‌‫و‬B‌.‌ ‌ a[0] a[1] a[2] a[3] c[0] c[1] c[2] c[3] c[4] c[5] c[6] b[0] b[1] b[2] A C B
  • 10. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 10 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 7/B/Write C++ program to read and print out the vector of An and Bn then Create the vector C by integrating the vector A and B. 7‌//‌‫ب‬‫به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‬‫خوێندنه‬‌‫وه‬‌‫و‌چاپ‌کردنی‌ڤێکته‬‌‌‫ری‬A‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫وه‬‌‌‫ڤێکته‬‌‌‫ری‬n‌‫به‬‌‌‫قه‬‌‫باره‬‌‌‫ی‬n‌‫.‌پاشان‌دروست‌کردنی‌ڤێکته‬‌‌‫ری‬C‌ ‫به‬‌‌‫یه‬‌‫کخستنی‌ڤێکته‬‌‌‫ری‬A‌‌‫و‬B‌.‌ #include <iostream.h> #include <conio.h> int const n=4,m=2*n; int a[n],b[n],c[m]; int i; main() { Cout<<”Enter the numbers of A and B"<<endl; for(i=0;i<n;i++) cin>>a[i]>>b[i]; cout<<"A B"<<endl<<"_______"<<endl; for(i=0;i<n;i++) cout<<a[i]<<" "<<b[i]<<endl; cout<<endl; cout<<"C"<<endl<<"___"<<endl; for(i=0;i<m;i++) { c[i]=a[i]; c[i]=b[i-n]; cout<<c[i]<<endl; } getch(); } Enter the numbers of vector A and B: 1 5 2 6 3 7 4 8 A B ______ 1 5 2 6 3 7 4 8 C __ 1 2 3 4 5 6 7 8
  • 11. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 11 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 8/write C++ program to read and print out the vector A and the vector B then print the subscripts of the command Rules between A and B. a[1]=3 b[3]=3 a[0]=2 a[1]=3 a[2]=5 a[3]=6 b[0]=1 b[1]=9 b[2]=8 b[3]=3 #include <iostream.h> #include <conio.h> main() { int const n=4; int a[n]={2,3,5,6}; int b[n]={1,9,8,3}; int i,j; cout<<"A"<<endl<<"_"<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; cout<<endl; cout<<"B"<<endl<<"_"<<endl; for(i=0;i<n;i++) cout<<b[i]<<endl; cout<<endl; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i]==b[j]) cout<<"a["<<i<<"]="<<a[i]<<" "<<"b["<<j<<"]="<<b[j]<<endl; } } getch(); } A B
  • 12. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 12 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 9/ Write a C++ program to add order, name and degree, and then find the Maximize of degree and calculating all degree. 9‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫ب‬‫ۆ‌داخڵ‌کردنی‌ژماره‬‌‌‫و‌ناو‌و‌نمره‬‌‫،‌پاشان‌به‬‌‌‫رزترین‬‫نمره‬‌‌‫بدۆزه‬‌‫ره‬‌‫وه‬‌‌‫له‬‌‫گه‬‌‫ڵ‌کۆکردنه‬‌‫وه‬‌‫ی‌هه‬‌‫موو‌نمره‬‌‫کان‬‌ #include <iostream.h> #include <conio.h> #include <cstring.h> int const n=5; int a[n]; string b[n]; int i,m,s; main() { cout<<"Enter Name and Degree for 5 student:"<<endl; for(i=0;i<n;i++) cin>>b[i]>>a[i]; cout<<endl; cout<<"Order"<<"t"<<"Name"<<"t"<<"Degree"<<"t"<<endl; cout<<"_____"<<"t"<<"_____"<<"t"<<"_____"<<endl; for(i=0;i<n;i++) cout<<(i+1)<<"t"<<b[i]<<"t"<<a[i]<<endl; cout<<endl; m=a[0]; for(i=0;i<n;i++) if(m<a[i]) m=a[i]; cout<<"Maximize Degree="<<m; cout<<"t"; s=0; for(i=0;i<n;i++) s=s+a[i]; cout<<"All degree="<<s; getch(); }
  • 13. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 13 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar //write c++ program to read and print out this table and find the maximize number with its index. #include <iostream.h> #include <conio.h> #include <cstring.h> main() { int const n=3; string a[n],r; int b[n]; int i,m,h; cout<<"Enter Names and degrees"<<endl; for(i=0;i<n;i++) Input cin>>a[i]>>b[i]; cout<<"ORDER"<<"t"<<" Name "<<"t"<<"Degree"<<endl<<"_____________________"<<endl; for(i=0;i<n;i++) Output cout<<i+1<<"t"<<a[i]<<"t"<<b[i]<<endl; cout<<"_____________________"<<endl; for(i=0;i<n;i++) m=b[0]; for(i=0;i<n;i++) { Compare of Maximum number if(m<b[i]) { m=b[i]; r=a[i]; for showing the Maximum N.’s Name h=i+1; For Showing the number of Index } } cout<<"a["<<h<<"]"<<" "<<r<<":"<<m; Output of Index ,Maximum Number and the Name. getch(); } ‌‌‌‌ Order Name Degree 1 Aram 82 2 Chawan 94 3 Suren 78
  • 14. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 14 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 1. #include <iostream.h> 2. #include <conio.h> 3. int const n=4; 4. int a[n]; 5. int b[n]; 6. int i,k; 7. main() 8. { 9. for(i=0;i<n;i++) 10. cin>>a[i]>>b[i]; 11. cout<<endl; 12. cout<<"A"<<"t"<<"B"<<endl<<"__"<<"t"<<"__"<<endl; 13. for(i=0;i<n;i++) 14. cout<<a[i]<<"t"<<b[i]<<endl; 15. cout<<endl; 16. for(i=0;i<n;i++) 17. { 18. k=a[i]+b[i]; 19. if(k>10) 20. cout<<"The value which is greater than ten="<<k<<endl; 21. } 22. getch(); 23. } 11/ Assume that we have two lists of integer values. Write C++ program to print all pairs of values which are add up to ten.
  • 15. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 15 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> int const n=5; int a[n]; int i; main() { for(i=0;i<n;i++) cin>>a[i]; cout<<endl; cout<<"A"<<endl<<"__"<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; cout<<endl; for(i=0;i<n;i++) { if(a[i]%6==0) cout<<"The number which is divided by six="<<a[i]<<endl; else cout<<"The reminder number="<<a[i]<<endl; } getch(); } 12/ Write C++ Program to read a set of n integer values. Print the number and reminder when the number is divided by 6. 12‫/‌به‬‌‫رنامه‬‌‫یه‬‌‫ک‌بنووسه‬‌‌‫بۆ‌خوێندنه‬‌‫وه‬‌‫ی‌کۆمه‬‌‫ڵێک‌نرخی‌ته‬‌‫واو‌پاشان‌ئه‬‌‫و‌ژمارانه‬‌‌‫و‌ماوه‬‌‫که‬‌‫ی‌چاپ‌بکه‬‌‌‫که‬‌‌‫دابه‬‌‌‫ش‬ ‫ده‬‌‫بێ‌به‬‌‫سه‬‌‫ر‌ژماره‬‌‌6‌.‫دا‬
  • 16. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 16 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 1. #include <iostream.h> 2. #include <conio.h> 3. #include <math.h> 4. int i,n,r,x,y; 5. main() 6. { 7. cout<<"N="; 8. cin>>n; 9. cout<<endl; 10. r=0; 11. for(i=0;i<n;i++) 12. { 13. cout<<"Y="; 14. cin>>y; 15. cout<<"X="; 16. cin>>x; 17. r=r+pow(y,3)*x; 18. } 19. cout<<"Result="<<r; 20. getch(); 21. } 13/Write C++ program to evaluate the value of r, which is defined as follows: r=∑ 3 i * Xi = Y3 1*X1 + Y3 2*X2 + … +Y3 n*Xn Explain: r= Y3 1*X1 + Y3 2*X2 + Y3 3*X3 … +Y3 n*Xn r= 23 *3+33 *4+13 *5 r= 8*3+27*4+1*5 >>> r= 24+108+5 >>> r= 137
  • 17. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 17 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> int const n=4; int a[n]; int i, sum=0; float m; main() { cout<<"Enter four numbersn"; for(i=0;i<n;i++) cin>>a[i]; cout<<endl; cout<<"A"<<endl<<"___"<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; cout<<endl; for(i=0;i<n;i++) { sum=sum+a[i]; m=sum/n; } cout<<"Sum="<<sum<<" "<<"Mean Value="<<m; cout<<endl; for(i=0;i<n;i++) { if(a[i]>m) cout<<"Greter Number="<<a[i]<<endl; } getch(); } 14/write C++ program to read a set of 20 numbers and calculate their mean value ,print out those numbers which are greater than the mean value.
  • 18. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 18 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> int const n=4; int a[n]; int b[n]; int i,m; main() { cout<<"Enter four pair integers number:"<<endl; for(i=0;i<n;i++) cin>>a[i]>>b[i]; cout<<endl; cout<<"Order"<<"t"<<"A"<<"t"<<"B"<<endl; cout<<"_____"<<"t"<<"_"<<"t"<<"_"<<endl; for(i=0;i<n;i++) cout<<" "<<i+1<<"t"<<a[i]<<"t"<<b[i]<<endl; cout<<endl; for(i=0;i<n;i++) { if(a[i]%b[i]==0) cout<<"Order="<<""<<i+1<<""<<"t"<<"First Order="<<a[i]<<"t"<<"Second Order="<<b[i]<<endl; } getch(); } 15/ Write C++ program to read a list of pair integers, then print those order pairs which first order divided by second order.
  • 19. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 19 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> #include <cstring.h> int const n=4; string name[n]; string dep[n]; string col[n]; string x; int i; main() { cout<<"Enter Name,Department and College of FOUR Students:"<<endl; for(i=0;i<n;i++) cin>>name[i]>>dep[i]>>col[i]; cout<<endl; cout<<" Name "<<" "<<"Department"<<" "<<" College "<<endl; cout<<"______"<<" "<<"__________"<<" "<<"____________"<<endl; for(i=0;i<n;i++) cout<<name[i]<<"t"<<dep[i]<<"tt"<<col[i]<<endl; cout<<"_____________________________"<<endl; cout<<"Search:"; cin>>x; for(i=0;i<n;i++) { if(name[i]==x) cout<<"Found:"<<" "<<"Dep:"<<dep[i]<<"t"<<"Col:"<<col[i]<<endl; } getch(); } 16/Write C++ program to read and print out this table: Name Department college ---- ------------ ------ ---- ------------ ------ ---- ------------ ------ Check whether the name Talar is in the list or not? If the name is in the list print its department and college.
  • 20. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 20 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> int const n=10; int a[n]; int i,c,j; main() { cout<<"Enter numbers"<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<endl; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[j]<a[i]) { c=a[j]; a[j]=a[i]; a[i]=c; } } } cout<<" A "<<endl<<"___"<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; getch(); } 17/Write C++ program to sort a set of n numbers (Data Array) in ASCENDING order. ‫تێبینی‬1‫/‌ئه‬‌‫گه‬‌‫ر‌بمانه‬‌‫وێ‌ژماره‬‌‫کان‌له‬‌‌‫گه‬‌‫وره‬‌‫وه‬‌‌‫بۆ‌بچووک‌ڕیزبکاته‬‌‌‫ته‬‌‫نها‌ئه‬‌‫مه‬‌‌‫ده‬‌‌‫گۆڕین‬ if(a[j]>a[i]) ‫تێبینی‬2‫:‌هه‬‌‫ندێ‌جار‌له‬‌‌‫به‬‌‫رنامه‬‌‫کانده‬‌‌‫ئه‬‌‫مانه‬‌‌‫به‬‌‫کار‌ده‬‌:‌‫هێنین‬‌ 1/‌<<”t”‌‫ئه‬‌‫مه‬‌‌‫له‬‌‌‫جیاتی‬Space‌‫بۆشایی‌به‬‌‫کاردێت‌که‬‌‌6 Space‌‫ده‬‌‫نوێنێت‌و‌زۆر‌جوان‌نوسینه‬‌‫کان‌ده‬‌‫رده‬‌‫چن‌له‬‌‌ ‫ڕیزه‬‌‫کاندا‌بۆیه‬‌‌‫باشتره‬‌‌‫ئه‬‌‫مه‬‌‌‫باکاربهێنین‌له‬‌‌‫باتی‬Space‌<<” “=‌.‌ 2‌/<<”n”‌‫ئه‬‌‫مه‬‌‌‫به‬‌‫مانی‌ڕیزێکی‌نوێ‌دێت‌و‌کورتکراوه‬‌"‫ی‬newline‌‫"ه‬‌‌‫وه‬‌‌‫ده‬‌‫توانین‌له‬‌‌‫جیاتی‌ئه‬‌‫مه‬‌‌‌ ‌‫ئامڕازی‬<<endl;‌‫به‬‌.‌‫کاربهێنین‬‌
  • 21. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 21 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 18/Write program to read and print out this table Name Degree Ala 80 Sara 20 ---- ---- Rewrite this table after rearrange degree from largest to smallest. ‌ #include <iostream.h> #include <conio.h> #include <cstring.h> int const n=3; string a[n]; string k; int b[n]; int i,j,c; main() { cout<<"Enter Name and Degree‌for three student:"<<endl; for(i=0;i<n;i++) cin>>a[i]>>b[i]; cout<<endl; cout<<"Name"<<"t"<<"Degree"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"t"<<b[i]<<endl; cout<<endl; cout<<”The table after Rearrange degree”<<endl; cout<<”____________________________” <<endl; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) if(b[j]>b[i]) { c=b[j]; k=a[j]; b[j]=b[i]; a[j]=a[i]; b[i]=c; a[i]=k; } } cout<<"Name"<<"t"<<"Degree"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"t"<<b[i]<<endl; getch(); }
  • 22. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 22 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar #include <iostream.h> #include <conio.h> #include <cstring.h> int const n=4; string a[n]; int b[n]; string x[n]; int i; main() { cout<<"Enter Name and Degree for four students:"<<endl; for(i=0;i<n;i++) cin>>a[i]>>b[i]; cout<<endl; for(i=0;i<n;i++) { if(b[i]>=90&&b[i]<=100) x[i]="A"; if(b[i]>=80&&b[i]<90) x[i]="B"; if(b[i]>=70&&b[i]<80) x[i]="C"; if(b[i]<70) x[i]="D"; } cout<<"Name"<<"t"<<"Degree"<<"t"<<"Grade"<<endl; cout<<"_______________________________"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"t"<<b[i]<<"t"<<x[i]<<endl; cout<<"_______________________________"<<endl; cout<<"ARAM CSD -- C++ PROGRAMMING"; getch(); } 19/Write C++ program to print this table Name Degree Grade Alan 87 B Sara 95 A Akam 62 D Lana 78 C if the degree between 90 and 100 write in Grade A if the degree between 80 and 90 write in Grade B if the degree between 70 and 80 write in Grade C if the degree less than 70 write in Grade D
  • 23. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 23 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 20/ Write a program to develop the Vector A with 4 rows, from this list 49 633 2 5. First row divisible by 2, second row divisible by 5, third row divisible by 3 and last row divisible by 7. #include <iostream.h> #include <conio.h> int const n=4; float a[n]={49,633,2,5}; int i,j; float div,res; main() { cout<<endl; cout<<"Vector A"<<endl; cout<<"________"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"n"; cout<<endl; cout<<"_________________"<<endl; res=a[0]/2; cout<<"First Result="<<res<<endl; cout<<"_________________n"<<endl; res=a[1]/5; cout<<"Second Result="<<res<<endl; cout<<"_________________n"<<endl; res=a[2]/3; cout<<"Third Result="<<res<<endl; cout<<"_________________n"<<endl; res=a[3]/7; cout<<"Last Result="<<res<<endl; cout<<"_________________n"<<endl; getch(); }
  • 24. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 24 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar 21/Write C++ program to read and print out the Vector An . Then find the Mean of the vector An #include <iostream.h> #include <conio.h> int const n=3; int a[n]; int i; float sum,m; main() { for(i=0;i<n;i++) cin>>a[i]; cout<<endl; cout<<"A"<<endl<<"__"<<endl; for(i=0;i<n;i++) cout<<a[i]<<endl; cout<<endl; sum=0; for(i=0;i<n;i++) sum=sum+a[i]; m=sum/n; cout<<"Mean of the vector A="<<m; getch(); }
  • 25. May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS) 25 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar ‌