SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
Damascus University 
Faculty of Information Technology Engineering 
Shapes and calculate 
(area and contour) / C++ OOP concept
الكود : 
#include<iostream> 
using namespace std; 
struct elem 
{ 
int col; 
double val; 
elem* next; 
}; 
struct HoleMat 
{ elem* mat[200]; }; 
//////////////////////////////////////////////////////////////////////////////////// 
void insert(elem* &reshead,int j,double x) 
{ 
elem* p=new elem; 
p->col=j; //intilizing node 
p->val=x; 
p->next=NULL; 
if(reshead==NULL) 
{ 
reshead=p; 
} 
else 
if(reshead->col > j) 
{ 
p->next= reshead; 
reshead=p; 
} 
else 
{ 
elem* r; 
r=reshead; 
while( (r->next != NULL)&&(r->next->col < j) ) 
{ 
r=r->next; 
}; 
p->next = r->next; 
r->next=p; 
} 
}; 
bool change(HoleMat &a,int n,int colom,int value) // to change the value if there is another value ((at the same place)) 
{ 
elem* ph; 
for(int i=1; i<=n; i++) 
{ 
ph=a.mat[i]; 
while (ph!=NULL) 
{ 
if(ph->col == colom) 
{ 
ph->val=value; 
return true; 
} 
else 
{ 
ph=ph->next; 
} 
} 
} 
return false; 
}; 
void ReadHMat(HoleMat& a,int n,int &maxcol) 
{ 
maxcol=-4; 
char w=' '; 
int j1,i1; 
double e1; 
for(int i=0; i<200; i++) ///creatig NULL array; 
{ 
a.mat[i]=NULL;
}; 
do 
{ 
cout<<"the element: n"; 
cin>>e1; 
cout<<"the row number: "<<" <= "<<n<<endl; 
cin>>i1; 
cout<<"the colom number: n"; 
cin>>j1; 
if(change(a,n,j1,e1) ) //change the value with th NEW 
{ 
cout<<"there is an elem at the same colom(changed) !! reputn"; 
} 
else 
insert(a.mat[i1],j1,e1); 
if(j1>maxcol) //find max col for matrix 
maxcol=j1; 
start: cout<<"read element again?!!(y or n).. :n"; 
cin>>w; 
if( (w!='y')&&(w!='n')) 
goto start; 
} 
while(w != 'n'); 
}; 
void WriteHMat(HoleMat a,int n,int maxcol) 
{ 
for(int i=1; i<= n; i++) 
{ 
if(a.mat[i] == NULL) //for print 0 whole line 
for(int j=1; j<=maxcol;j++) 
{ 
cout<<" 0 "; 
} 
cout<<endl; 
elem* ls =a.mat[i]; 
int k=1; 
while (ls != NULL) 
{ 
if(ls->col == k) 
{ 
cout<<"( "<< ls->col<<" )| " <<ls->val<<" "; 
ls=ls->next; 
} 
else 
{ cout<<" 0 "; } 
k++; 
} 
if( (k != maxcol)&&( k!= 1) ) // to complet the line with 0 
for(int q=k; q<=maxcol; q++) 
cout<<" 0 "; 
if(a.mat[i] != NULL) //to Not print spaces!! 
cout<<endl; 
};//for 
}; 
void putcurrent(elem*& head,elem* &current,double v1,int c1) //& current 
{ 
elem* temp=new elem; 
temp->col=c1; 
temp->val=v1; 
temp->next=NULL; 
if(current==NULL) 
{ 
head=temp; 
current=temp; 
} 
else 
{
current->next = temp; 
current = current->next; 
} 
}; 
void addmat(HoleMat a,HoleMat b,HoleMat& res,int n1) // & res 
{ 
for(int i=0; i<200; i++) ///creatig NULL array to max 200; 
{ 
res.mat[i]=NULL; 
}; 
for(int i=1; i<= n1 ;i++) 
{ 
elem* p1=a.mat[i]; 
elem* p2=b.mat[i]; 
elem* current; 
current=NULL; 
while( (p1 != NULL)&&(p2 !=NULL) ) //comparing and put the least.. 
{ 
if(p1 ->col < p2->col) 
{ 
putcurrent(res.mat[i],current,p1->val,p1->col); 
p1 = p1->next; 
} 
else if (p2 ->col < p1->col) 
{ 
putcurrent(res.mat[i],current,p2->val,p2->col); 
p2 = p2->next; 
} 
else // == 
{ 
double sum=p1->val + p2->val ; 
putcurrent(res.mat[i],current,sum,p1->col); 
p1 = p1->next; 
p2 = p2->next; 
} 
};//while 
while(p1 != NULL) //for what is left in a .. 
{ 
putcurrent(res.mat[i],current,p1->val,p1->col); 
p1 = p1->next; 
}; 
while(p2 != NULL) //for what is left in b .. 
{ 
putcurrent(res.mat[i],current,p2->val,p2->col); 
p2 = p2->next; 
}; 
};//for 
}; 
double SumHMat(HoleMat z,int n) 
{ 
double sum=0; 
elem* ph; 
for(int i=1; i<=n; i++) 
{ 
ph=z.mat[i]; 
while (ph != NULL) 
{ 
sum=sum + ph->val; 
ph=ph->next; 
} 
}; 
return sum; 
}; 
double MaxMat(HoleMat y,int n) 
{ 
double max; 
int maxrow,maxcol; 
int i=1; // find the first row != NUll to give Max an intilize value 
elem* t; //auxitiare 
while ( y.mat[i] == NULL) 
{ i++ ; }; 
max=y.mat[i] ->val; 
for(int j=i; j<=n;j++)
{ 
t=y.mat[j]; 
while(t != NULL) 
{ 
if( t->val > max) 
{ 
max= t->val; 
maxrow=j; 
maxcol=t->col; 
} 
t=t->next; 
}; 
}; 
// just print max's node 
cout<<"( "<<maxrow<<" , "<<maxcol<<" )| " <<max<<" "; 
return max; 
}; 
////////////////////////////////////////////////////////////////////////////////// 
void main() 
{ 
HoleMat a,b,res,z,y; 
int max; 
char c=' '; 
int n,n1,n2; //row dimention.. 
while( c != '0') 
{ 
cout<<"|----------------------------------------------------------------------|n"; 
cout<<"| CHOICE MENU |n" ; 
cout<<"|-----|----|-----------------------------------------------------------|n"; 
cout<<"| |(1)-| Read your matrix: 'press (1) ' |n"; 
cout<<"| --|----|------------------------------------------- |n"; 
cout<<"| |(2)-| writeMatrix : 'press (2) ' |n"; 
cout<<"| --|----|------------------------------------------- |n"; 
cout<<"| |(3)-| Add two matrix 'press (3) ' |n"; 
cout<<"| --|----|------------------------------------------- |n"; 
cout<<"| |(4)-| sum all matrix elements : 'press (4) ' |n"; 
cout<<"| --|----|------------------------------------------- |n"; 
cout<<"| |(5)-| Find Max element int the Matrix : 'press (5) ' |n"; 
cout<<"| --|----|------------------------------------------- |n"; 
cout<<"| |(0)-| to EXIT.. 'press (0) ' |n"; 
cout<<"|-----|----|-----------------------------------------------------------|n"; 
cout<<"|----------------------------------------------------------------------|n"; 
cout<<"enter your choice : "; 
cin>>c; 
switch(c) 
{ 
case '1': { 
cout<<"enter the all row(max row number) number: n"; 
cin>>n; 
ReadHMat(a,n,max); 
cout<<"------------------------------------------------------------------------n"; 
break; 
}; 
case'2': { 
cout<<"WRITEMAT...............n"; 
WriteHMat(a,n,max); 
cout<<"---------------------------------------------------------------------------- n"; 
break; 
}; 
case'3': { 
cout<<"FIrst matrix: n"; 
cout<<"enter the all row(max row number) number: n"; 
cin>>n1; 
ReadHMat(a,n1,max); 
WriteHMat(a,n1,max); 
// 
cout<<"Second matrix: n"; 
cout<<"enter the all row(max row number) number: n"; 
cin>>n2; 
ReadHMat(b,n2,max);
WriteHMat(b,n2,max); 
if(n1 != n2) 
{ 
cout<<"cannot do the add n1!=n2 n"; 
break; 
} 
addmat(a,b,res,n1); 
cout<<"******the RES*******n"; 
WriteHMat(res,n1,max); 
break; 
}; 
case'4':{ 
cout<<"enter the all row(max row number) number: n"; 
cin>>n; 
cout<<"Put the matrix: n"; 
ReadHMat(z,n,max); 
WriteHMat(z,n,max); 
cout<<"the sum of all elements = n"; 
cout<<SumHMat(z,n)<<endl; 
break; 
}; 
case'5': { 
cout<<"enter the all row(max row number) number: n"; 
cin>>n; 
cout<<"Put the matrix: n"; 
ReadHMat(y,n,max); 
WriteHMat(y,n,max); 
cout<<"the Max number in it= "<<MaxMat(y,n)<<endl; 
break; 
}; 
case'0': 
{ 
cout<<"End Program..My wishes :D....n"; 
break; 
}; 
default: { cout<<"error value..n"; break;}; 
}; 
};//while 
system("pause");

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

week-5x
week-5xweek-5x
week-5x
 
Tower of HANOI
Tower of HANOITower of HANOI
Tower of HANOI
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
TSP algorithm (Computational Thinking) Dropbox
TSP algorithm (Computational Thinking) DropboxTSP algorithm (Computational Thinking) Dropbox
TSP algorithm (Computational Thinking) Dropbox
 
Freeing Tower Bridge
Freeing Tower BridgeFreeing Tower Bridge
Freeing Tower Bridge
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322Ct es past_present_future_nycpgday_20130322
Ct es past_present_future_nycpgday_20130322
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Hendromardikadorkdanbretastevanny.js
Hendromardikadorkdanbretastevanny.jsHendromardikadorkdanbretastevanny.js
Hendromardikadorkdanbretastevanny.js
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Assignement c++
Assignement c++Assignement c++
Assignement c++
 

Similar a Damascus University Faculty Shapes Calculate C++ OOP

#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfrozakashif85
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdfpasqualealvarez467
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfaryan9007
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfamarnathmahajansport
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdfapleather
 

Similar a Damascus University Faculty Shapes Calculate C++ OOP (20)

#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdf
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 

Más de kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_listskinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked listkinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointerskinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfileskinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfileskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templateskinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritancekinan keshkeh
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces kinan keshkeh
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
 

Más de kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 

Último

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Último (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

Damascus University Faculty Shapes Calculate C++ OOP

  • 1. Damascus University Faculty of Information Technology Engineering Shapes and calculate (area and contour) / C++ OOP concept
  • 2. الكود : #include<iostream> using namespace std; struct elem { int col; double val; elem* next; }; struct HoleMat { elem* mat[200]; }; //////////////////////////////////////////////////////////////////////////////////// void insert(elem* &reshead,int j,double x) { elem* p=new elem; p->col=j; //intilizing node p->val=x; p->next=NULL; if(reshead==NULL) { reshead=p; } else if(reshead->col > j) { p->next= reshead; reshead=p; } else { elem* r; r=reshead; while( (r->next != NULL)&&(r->next->col < j) ) { r=r->next; }; p->next = r->next; r->next=p; } }; bool change(HoleMat &a,int n,int colom,int value) // to change the value if there is another value ((at the same place)) { elem* ph; for(int i=1; i<=n; i++) { ph=a.mat[i]; while (ph!=NULL) { if(ph->col == colom) { ph->val=value; return true; } else { ph=ph->next; } } } return false; }; void ReadHMat(HoleMat& a,int n,int &maxcol) { maxcol=-4; char w=' '; int j1,i1; double e1; for(int i=0; i<200; i++) ///creatig NULL array; { a.mat[i]=NULL;
  • 3. }; do { cout<<"the element: n"; cin>>e1; cout<<"the row number: "<<" <= "<<n<<endl; cin>>i1; cout<<"the colom number: n"; cin>>j1; if(change(a,n,j1,e1) ) //change the value with th NEW { cout<<"there is an elem at the same colom(changed) !! reputn"; } else insert(a.mat[i1],j1,e1); if(j1>maxcol) //find max col for matrix maxcol=j1; start: cout<<"read element again?!!(y or n).. :n"; cin>>w; if( (w!='y')&&(w!='n')) goto start; } while(w != 'n'); }; void WriteHMat(HoleMat a,int n,int maxcol) { for(int i=1; i<= n; i++) { if(a.mat[i] == NULL) //for print 0 whole line for(int j=1; j<=maxcol;j++) { cout<<" 0 "; } cout<<endl; elem* ls =a.mat[i]; int k=1; while (ls != NULL) { if(ls->col == k) { cout<<"( "<< ls->col<<" )| " <<ls->val<<" "; ls=ls->next; } else { cout<<" 0 "; } k++; } if( (k != maxcol)&&( k!= 1) ) // to complet the line with 0 for(int q=k; q<=maxcol; q++) cout<<" 0 "; if(a.mat[i] != NULL) //to Not print spaces!! cout<<endl; };//for }; void putcurrent(elem*& head,elem* &current,double v1,int c1) //& current { elem* temp=new elem; temp->col=c1; temp->val=v1; temp->next=NULL; if(current==NULL) { head=temp; current=temp; } else {
  • 4. current->next = temp; current = current->next; } }; void addmat(HoleMat a,HoleMat b,HoleMat& res,int n1) // & res { for(int i=0; i<200; i++) ///creatig NULL array to max 200; { res.mat[i]=NULL; }; for(int i=1; i<= n1 ;i++) { elem* p1=a.mat[i]; elem* p2=b.mat[i]; elem* current; current=NULL; while( (p1 != NULL)&&(p2 !=NULL) ) //comparing and put the least.. { if(p1 ->col < p2->col) { putcurrent(res.mat[i],current,p1->val,p1->col); p1 = p1->next; } else if (p2 ->col < p1->col) { putcurrent(res.mat[i],current,p2->val,p2->col); p2 = p2->next; } else // == { double sum=p1->val + p2->val ; putcurrent(res.mat[i],current,sum,p1->col); p1 = p1->next; p2 = p2->next; } };//while while(p1 != NULL) //for what is left in a .. { putcurrent(res.mat[i],current,p1->val,p1->col); p1 = p1->next; }; while(p2 != NULL) //for what is left in b .. { putcurrent(res.mat[i],current,p2->val,p2->col); p2 = p2->next; }; };//for }; double SumHMat(HoleMat z,int n) { double sum=0; elem* ph; for(int i=1; i<=n; i++) { ph=z.mat[i]; while (ph != NULL) { sum=sum + ph->val; ph=ph->next; } }; return sum; }; double MaxMat(HoleMat y,int n) { double max; int maxrow,maxcol; int i=1; // find the first row != NUll to give Max an intilize value elem* t; //auxitiare while ( y.mat[i] == NULL) { i++ ; }; max=y.mat[i] ->val; for(int j=i; j<=n;j++)
  • 5. { t=y.mat[j]; while(t != NULL) { if( t->val > max) { max= t->val; maxrow=j; maxcol=t->col; } t=t->next; }; }; // just print max's node cout<<"( "<<maxrow<<" , "<<maxcol<<" )| " <<max<<" "; return max; }; ////////////////////////////////////////////////////////////////////////////////// void main() { HoleMat a,b,res,z,y; int max; char c=' '; int n,n1,n2; //row dimention.. while( c != '0') { cout<<"|----------------------------------------------------------------------|n"; cout<<"| CHOICE MENU |n" ; cout<<"|-----|----|-----------------------------------------------------------|n"; cout<<"| |(1)-| Read your matrix: 'press (1) ' |n"; cout<<"| --|----|------------------------------------------- |n"; cout<<"| |(2)-| writeMatrix : 'press (2) ' |n"; cout<<"| --|----|------------------------------------------- |n"; cout<<"| |(3)-| Add two matrix 'press (3) ' |n"; cout<<"| --|----|------------------------------------------- |n"; cout<<"| |(4)-| sum all matrix elements : 'press (4) ' |n"; cout<<"| --|----|------------------------------------------- |n"; cout<<"| |(5)-| Find Max element int the Matrix : 'press (5) ' |n"; cout<<"| --|----|------------------------------------------- |n"; cout<<"| |(0)-| to EXIT.. 'press (0) ' |n"; cout<<"|-----|----|-----------------------------------------------------------|n"; cout<<"|----------------------------------------------------------------------|n"; cout<<"enter your choice : "; cin>>c; switch(c) { case '1': { cout<<"enter the all row(max row number) number: n"; cin>>n; ReadHMat(a,n,max); cout<<"------------------------------------------------------------------------n"; break; }; case'2': { cout<<"WRITEMAT...............n"; WriteHMat(a,n,max); cout<<"---------------------------------------------------------------------------- n"; break; }; case'3': { cout<<"FIrst matrix: n"; cout<<"enter the all row(max row number) number: n"; cin>>n1; ReadHMat(a,n1,max); WriteHMat(a,n1,max); // cout<<"Second matrix: n"; cout<<"enter the all row(max row number) number: n"; cin>>n2; ReadHMat(b,n2,max);
  • 6. WriteHMat(b,n2,max); if(n1 != n2) { cout<<"cannot do the add n1!=n2 n"; break; } addmat(a,b,res,n1); cout<<"******the RES*******n"; WriteHMat(res,n1,max); break; }; case'4':{ cout<<"enter the all row(max row number) number: n"; cin>>n; cout<<"Put the matrix: n"; ReadHMat(z,n,max); WriteHMat(z,n,max); cout<<"the sum of all elements = n"; cout<<SumHMat(z,n)<<endl; break; }; case'5': { cout<<"enter the all row(max row number) number: n"; cin>>n; cout<<"Put the matrix: n"; ReadHMat(y,n,max); WriteHMat(y,n,max); cout<<"the Max number in it= "<<MaxMat(y,n)<<endl; break; }; case'0': { cout<<"End Program..My wishes :D....n"; break; }; default: { cout<<"error value..n"; break;}; }; };//while system("pause");