Home › Forums › C Programming › C++ Object Oriented Programming Arrays and Pointer
- This topic has 0 replies, 1 voice, and was last updated 17 years, 1 month ago by veenisha.
Viewing 0 reply threads
- AuthorPosts
- November 16, 2007 at 9:57 am #2033veenishaParticipant
Let us discuss how to use arrays and Pointers in C++.
Here i made a program, in which arrays are used in making a class.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576numbers criteria.cpp<br /><br />/*<br />Muhammad Atif Agha<br />Punjab University<br />College of Information Technology<br />PUCIT<br />BSCSF06M081<br />*/<br /><br /><br />#include <iostream.h><br />#include <conio.h><br />#include <string.h><br />//Program which tells us from an Array that which Number is bigger than how many numbers in an Array<br /><br />class A{<br />private:<br />int size;<br />char arr[80];<br />public:<br />A()<br />{<br />size=0;<br />}<br />void setfunc (char a[],int s)<br />{<br />strcpy(arr,a);<br />size=s;<br />}<br /><br />void fun (char arr[],int s);<br /><br /><br />void showfunc()<br />{<br />cout<<arr;<br />cout<<endl<<endl;<br />}<br /><br />};<br />// Outside the class<br /><br />void A::fun(char arr[],int size)<br />{<br />int i,j;<br />for (i=0;i<size;i++)<br />{<br />int count=0;<br />for (j=0;j<size;j++)<br />{<br />if (arr>arr[j])<br />count=count+1;<br />}<br />cout<<endl<<arr<<" is bigger than "<<count<<" numbers in an array"<<endl;<br />}<br />}<br /><br />int main(){<br />clrscr();<br />A a1,a2;<br />int i;<br />char array[80];<br />int s;<br />cout<<"Enter the size"<<endl;<br />cin>>s;<br />cout<<endl<<endl;<br />for (i=0;i<s;i++)<br />{<br />cin>>array;<br />}<br />a1.setfunc(array,s);<br />a2.fun(array,s);<br />getch();<br />return 0;<br />}
- AuthorPosts
Viewing 0 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.