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 theMarks 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 Degreefor 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