Upload
aram-se
View
100
Download
3
Embed Size (px)
DESCRIPTION
Citation preview
May 22, 2012 C++ PROGRAMMING ONE DIMENSION (ARRAYS)
1 Borland C++ Programming | by ARAM CSD Thanks for My Teacher: Dr.Selar
کنهایهکیئاسۆییانستوونیتهیهشێوهبهکهیهههکدوورییههکپێکهاتووهڵێکدانهکۆمهله:کانڕیزکراوه
بهوه Aکرێتهێمادهیهمشێوهبهکه(Vector)ڤێکتۆر یان(One Dimension)ڵێنپێیدهبۆیهوهگرێتهڕیزده
دان.کهڕیزهلهیکهودانانهیئهژمارهکاتهدهکرێتکههدیاریدبارهکقهیه
بێت:دهیهمشێوهکانیشبهیاسایگشتیڕیزکراوه
Type const size=? ;
Type name[size];
.یهکهرنامهکیبهرهشێکیسهبه(یبۆبنووسینکهHeaderکانیپێشوو)رنامهمووبهکوههوهتاپێویستهرهسه
ک)حساباتیبیرکاریینوهدازیادیبکه(Header)بێلهرجۆرکردارێکیتربوودهههرپێویستمانبهگهئهوه
دا.کهرنامهبهرف(لهتێکستوحهوێت،یاننووسین)کهتوانی(تێدهکه
1. #include <iostream.h>
2. #include <conio.h>
3. #include <math.h>
4. #include <cstring.h>
اڵم:کدابنووسرێتبهیهرنامهمووبهههبێتلهدهکهکهرهکینبۆهێدهرهسه2و1خاڵی
ژێ...(.،تهگتوان،ڕهکاردێتبۆ)حساباتیبیرکاریکهبه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;
وئاگاداربینئهاڵمپێویسته،به”n,m,l,k”زویخۆمانئارهرفێکبهرحهههبگۆڕینبه (size)توانینناویده
ین.یبکهنابێتدووجارپێناسههێنینوهکارینهکرداریتردابهلهرفهحه
یهمشێوهبههێنینکاریدهدابهکهرنامهبهیلهوشتانهناساندنیئهلهکانبریتیهڕیزکراوهشێکیتریبه
Int array[size1];
Type k,l,sum,m;
;int i (,i,j,n,k,l,mک)کارهێناپێوستبووبیناسێنینوهرشتێکمانبهپاشانهه
()mainپاشان
{
.کهداڕشتنهرنامهبهینبهکهستدهنووسیندهده
بیانناسێنین.نابێتدووبارهوناووهبارهکقهوهناساندوومانهوهرهسهلهبێتکهوشتانهنهائهته
پێویستمانبه(cin,cout,if,swap,sum,count,multi,mean)ککانیوهیکردارهکاندابۆزۆربهڕیزکراوهله
یهمشێوهگۆڕبێتبهنهبارهرقهگهبێتئهکلووپدهنهایهته
for(i=0;i<size;i++)
{
_____
_____
}
کسانهیانیهبارهقهn=2کامانبارهقهکه An ری(:بۆنموونه:ڤێکته<<cinأ/داغڵکردن)
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[i]و a[n]ستمانلهبهدامهلێره
کانییدانهژمارهکهیهبارهقهnرهمڤێکتهیئهبارهقهوهaناویبهیهرێکمانههڤێکتهواته a[n]ستلهبهمه
.یهمشێوهکرێتبهتاداداخڵدهرهسهنهالهتهمهێمایهئهوهوهگرێتهدهکهرهڤێکته
:ستراوهرکردارێکیتربهوتیانههستکهداخلیانده iپێیکانبهدانهکهیهوهئه a[i]ستلهبهمه
;int const n=3واتهیه3یکهبارهقهیهرێکمانههکتهڤێئێمهبۆنموونه
3واته nیژمارهمترلهککهیهکاتتادانهستپێدهده0لهینکهکههێماده iشمانبهکهلووپهوه
for(i=0;i<n;i++)بێ:دهیهمشێوهشبهکهلووپهوه ;int iیهمشێوهبه
3 لهبچوکتره2سێ،ژمارهکاتهدهکه0،1،2لهواته
کات؛ستپێدهدهوه0لهنچونکهدانه3کاناڵمنرخهبه
یکاتبهگرێتوده"ده0،1،2"وژمارانهکێکلهینیهکهداخڵیدهرنرخێککهههکهیهوهئهمهستمانلهبهمه
وێتکهردهدهیهمشێوهوتنیدابهرکهدهلهوه”subscript“یان ”index“ڵێنجێگایخۆیپێیده
cout<<”a[“<<i+1<<”]=”;
وێتربکهکیجواندهیهشێوهیبهوهبۆئهبکه1تۆ+0بێبهده iکاتێککهواتهه ”index“هێمایمهئه
:وێتکهردهکانداجوانتردهنموونهشلهمهئه
A3 کاندانه index a[i]
i=0
i=1
i=2
ینرخیخۆیوهینبۆئهبکه i+1بێتدهبۆیه1کاتهمانبوێتده8یژمارهindexرگهئهئێستائێمهواته
.ه2ڕاستیداژمارهلهربگرێتکهوه
cout<<”a[“<<i+1<<”]=”<<a[i];
a[i=1]چێتهدهمژمارهدووهوهa[i=0]چێتهدهمژمارهکهیهبێبزانینکهیندهکهداخڵدهژمارهداکاتێککهلێره
بێت.واودهتالوپتهیهشێوهمبه
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
یهمشێوهوخۆبهرناگرێتراستهوه“ ”>>و endl>>ئینپوتواته <<cinکیههیچشێوهتێبینی//به
cin>>a[i] <<endl<<” “;
cin>>a[i];
cout<<endl<<” “;
مانکهرنامهکدابنێینبۆبهجوانکاریهینپێویستهبکه (>>cout)وتستکهاسیدهیبوهپێشئهدهلێره
رسهکجارلهنهایهیتهوهبنووسرێتبۆئه ”for“وهپێشلووپهبێتلهدهمیشهههیجوانکاریه coutمئهوه
نجامیڵئهگهیلهوهبۆئهکهناولووپهینهتوانینبیخهوادهحساباتدابووئهرلهگهاڵمئهوێتبهرکهدهکهشاشه
ناساندنپێویستبههک “ “یشننێواندووکۆتهوێتهکهدهشنووسینێکهمهوێت.ئهربکهکاندادهمووکردارههه
نووسین.ده;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 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.
وهرهبدۆزهژمارهترینورهگه،پاشانAnڤێکتۆرێکیوچاپکردنیوهبۆخوێندنهسبنووسهسپڵهکیسیپڵهیهرنامه/به2
#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
A B
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.
.وه15و5نێوانوێتهکهدهکهچاپبکهوژمارانه.پاشانئهAوچاپکردنیڤێکتۆریوهبۆخوێندنهبنووسهکیهرنامه/به6
If we want index for the example we just add <<” “<<”index=”<<i+1<<endl; for last cout:
ینبۆکهزیادده ;index=”<<i+1<<endl”>>“ ”>> مهنائهواتهدائهوهرهیسهونموونهنلهیهدیاریبکه (index)رویستمانگهئه
.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.
به Cری.پاشاندروستکردنیڤێکتهmیبارهقهبه Bریڤێکتهوه nیبارهقهبه Aریوچاپکردنیڤێکتهوهخوێندنه بۆکبنووسهیهرنامه/به7
.Bو Aریکخستنیڤێکتهیه
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.
Cری.پاشاندروستکردنیڤێکتهnیبارهقهبه nریڤێکتهوه nیبارهقهبه Aریوچاپکردنیڤێکتهوهخوێندنه بۆکبنووسهیهرنامهبهب//7
.Bو Aریکخستنیڤێکتهیهبه
#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=∑
3i * Xi = Y3
1*X1 + Y32*X2 + … +Y3
n*Xn
Explain: r= Y31*X1 + Y3
2*X2 + Y33*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 numbers\n";
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]<<"\t\t"<<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 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();
}
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