Showing posts with label Egypt. Show all posts
Showing posts with label Egypt. Show all posts

Monday, June 3, 2013

Some C++ Problems for Beginners (7)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder

-2DimArrayFrom1DimArray.cpp:
Problem Definition:
Supposing that you have the following 1 Dimensional Array called A as a known input:
int A[10] = {1,1,2,5,3,4,9,8,7,1};
 
Fill the Char Array B (char B [10][10]) with the Histogram values taken from the Array A
then Print the Histogram in B
================================================
output:
-------
 
*
*
**
*****
***
****
*********
********
*******
*
 
================================================

[C++]
  1 /*  About The Simple Code "_2DimArrayFrom1DimArray.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3 
  4     This simple code is a free simple: you can redistribute it and/or modify 
  5     it under the terms of the GNU General Public License as published by 
  6     the Free Software Foundation, either version 3 of the License, or 
  7     (at your option) any later version. 
  8   
  9     This program is distributed in the hope that it will be useful, 
 10     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12     GNU General Public License for more details. 
 13   
 14     You should have received a copy of the GNU General Public License 
 15     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 16 
 17 #include <iostream>
 18 using namespace std;       
 19 
 20 /*Problem Definition
 21 Supposing that you have the following 1 Dimensional Array called A as a known input:
 22 int A[10] = {1,1,2,5,3,4,9,8,7,1};
 23 
 24 Fill the Char Array B (char B [10][10]) with the Histogram values taken 
 25 from the Array A then Print the Histogram in B
 26 ================================================
 27 output:
 28 -------
 29 
 30 *
 31 *
 32 **
 33 *****
 34 ***
 35 ****
 36 *********
 37 ********
 38 *******
 39 *
 40 
 41 ================================================
 42 //*///Prototypes
 43 void FillArray(int A[10], char B[10][10]);
 44 void PrintArray(char B[10][10]);
 45 
 46 void main()
 47 {
 48  int A[10] = {1,1,2,5,3,4,9,8,7,1};        
 49  char B [10][10];            
 50 
 51  FillArray(A, B);            
 52  PrintArray(B);             
 53 }
 54 
 55 //Function "FillArray" takes 2 Attributes A --> The input Array & B --> The output Array
 56 //It takes the values from the Array "A" and fill the Output Array "B" with 
 57 //Stars and Spaces to Draw the Histogram
 58 void FillArray(int A[10], char B[10][10] )
 59 {
 60  for(int i = 0; i < 10; i++)         
 61  {
 62   for(int j = 0; j <10; j++)        
 63   {
 64    if( j < A[i])          
 65    {
 66     B[i][j] = '*';         
 67    }
 68    else
 69    {
 70     B[i][j] = ' ';        
 71    }
 72   }
 73  }
 74 
 75 }
 76 
 77 
 78 //Function "PrintArray" takes 1 Attribute B --> The Output Array and prints it
 79 //It Loops over all the Array "B" elements and print them all (The Histogram)
 80 void PrintArray(char B[10][10])
 81 {
 82  for(int i = 0; i < 10; i++)     
 83  {
 84   for(int j = 0; j < 10; j++)    
 85   {
 86    cout<<B[i][j];      
 87   }
 88   cout<<endl;        
 89 
 90  }
 91 
 92 }

download the 2DimArrayFrom1DimArray.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (6)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder
-TwoDimArray.cpp:
Problem Definition:
Write a code fragment that construct a two-dimensional array (name it B) of integers with
5 rows and 5 columns. Then:
-Fill-in the array B to contain the multiplication table from 1 to 5
-Find the sum of the numbers for each row
-Find the sum of all numbers in the array

[C++]
  1 /*  About The Simple Code "TwoDimArray.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3     
  4 
  5     This simple code is a free simple: you can redistribute it and/or modify 
  6     it under the terms of the GNU General Public License as published by 
  7     the Free Software Foundation, either version 3 of the License, or 
  8     (at your option) any later version. 
  9   
 10     This program is distributed in the hope that it will be useful, 
 11     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13     GNU General Public License for more details. 
 14   
 15     You should have received a copy of the GNU General Public License 
 16     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 17 
 18 
 19 #include <iostream>
 20 using namespace std;   
 21 
 22 
 23 /* Problem Definition: ... taken from the Quizes quiz D)d
 24 Write a code fragment that construct a two-dimensional array (name it B) of integers 
 25 with 5 rows and 5 columns. Then:
 26 -Fill-in the array B to contain the multiplication table from 1 to 5
 27 -Find the sum of the numbers for each row
 28 -Find the sum of all numbers in the array
 29 */
 30 
 31 //Prototypes
 32 void InsertIntoArray(int B[5][5]);
 33 void RowSum(int B[5][5]);
 34 void ArraySum(int B[5][5]);
 35 
 36 
 37 void main()
 38 {
 39  int B[5][5];    
 40  InsertIntoArray(B);   
 41  RowSum(B);     
 42  ArraySum(B);    
 43 
 44 }
 45 
 46 
 47 /* 2D Array Structure /*
 48 
 49 1 2 3 4 5
 50 2 4 6 8 10
 51 3 6 9 12 15
 52 4 8 12 16 20
 53 5 10 15 20 25
 54 
 55 */
 56 
 57 //Function InsertIntoArray is a Function that insert the values of 
 58 //the multiplication table from 1 to 5 and print them on the screen
 59 void InsertIntoArray(int B[5][5])
 60 {
 61  cout<<"Full Array"<<endl<<"=_==_==_==_==_==_==_==_==_="<<endl;
 62  for(int i = 0; i<5; i++)    
 63  {          
 64   for (int j = 0; j<5; j++)   
 65   {         
 66   B[i][j] = (i+1) * (j+1);   
 67   cout<<B[i][j];      
 68   } 
 69   cout<<endl;       
 70  }          
 71 }
 72 
 73 //Function RowSum is a Function that Print the Sum of each Row from the 2D Array on the Screen
 74 void RowSum(int B[5][5])
 75 {
 76  cout<<endl<<"Row Sum"<<endl<<"=_==_==_==_==_==_==_==_==_="<<endl;
 77  int sum = 0;         
 78  for(int i = 0; i<5; i++)      
 79  {
 80   for (int j = 0; j<5; j++)     
 81   {
 82   sum += B[i][j];        
 83   }
 84   cout<<sum<<endl;       
 85   sum=0;          
 86  }
 87 }
 88 
 89 
 90 //Function RowSum is a Function that Print the Sum of all the values in the 2D Array on the Screen
 91 void ArraySum (int B[5][5])
 92 {
 93  cout<<endl<<"Array Sum"<<endl<<"=_==_==_==_==_==_==_==_==_="<<endl;
 94  int sum = 0;       
 95  for(int i = 0; i<5; i++)    
 96  {
 97   for (int j = 0; j<5; j++)   
 98   {
 99   sum += B[i][j];      
100   } 
101  }
102  cout<<sum<<endl;      
103 }



download the TwoDimArray.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (5)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder
-ShapesAreas.cpp:
Problem Definition:
Write a program that take from the user "1" if Circle, "2" if Rectangle, "3" if Triangle,
"4" if Square & "5" if Parallelogram
then Calculate and Print the Area of the chosen Shape after taking the inputs from the
user.
Note:
Area of a:
                Circle = π × r2               (read r from the user and consider that π = 3.14)
                Rectangle = w x h                       (read w and h from the user)
                Triangle = 1/2 base x h         (read base and h from the user)
                Square = L2                             (read L from the user)
                Parallelogram = base * h         (read base and h from the user)

[C++]
  1 /*  About The Simple Code "ShapesAreas.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3 
  4     This simple code is a free simple: you can redistribute it and/or modify 
  5     it under the terms of the GNU General Public License as published by 
  6     the Free Software Foundation, either version 3 of the License, or 
  7     (at your option) any later version. 
  8   
  9     This program is distributed in the hope that it will be useful, 
 10     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12     GNU General Public License for more details. 
 13   
 14     You should have received a copy of the GNU General Public License 
 15     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 16 
 17 
 18 #include <iostream>
 19 #define PI 3.14
 20 using namespace std;            
 21 
 22 /*Problem Definition
 23 Write a program that take from the user "1" if Circle, 
 24 "2" if Rectangle, "3" if Triangle, "4" if Square & "5" if Parallelogram
 25 then Calculate and Print the Area of the chosen Shape after taking the inputs from the user.
 26 Note:
 27 Area of a:
 28     Circle = π × r2               (read r from the user and consider that π = 3.14)
 29     Rectangle = w x h    (read w and h from the user)
 30     Triangle = 1/2 base x h  (read base and h from the user)
 31     Square = L2     (read L from the user)
 32     Parallelogram = base * h  (read base and h from the user)
 33 */
 34 
 35 //Prototype(s)
 36 void ReadCalculatePrintArea(int choice);
 37 float CalculateCircleArea(int r);
 38 float CalculateRectangleArea(int w, int h);
 39 float CalculateTriangleArea(int base, int h);
 40 float CalculateSquareArea(int L);
 41 float CalculateParallelogramArea(int base, int h);
 42 
 43 void main()
 44 {
 45  int choice;
 46  cout<<"Please, enter 1 if Circle, 2 if Rectangle, 3 if Triangle, 4 if Square and 5 if Parallelogram : "<<endl;
 47     cin>>choice;             
 48  ReadCalculatePrintArea(choice);         
 49 }
 50 
 51 //ReadCalculatePrintArea is a function that take the Choice from the User then 
 52 //1. Reads the inputs from the user based on the chosen choice
 53 //2. Calls the Specific CalculateArea Function based on the chosen shape
 54 //3. Prints on the screen the Final Area Result taken from the specified Called CalculateArea Function
 55 void ReadCalculatePrintArea(int choice)
 56 {
 57 
 58 float Area;
 59 switch(choice)
 60  {
 61  case 1:                  
 62   int r;                 
 63   cout<<"Please Enter the Radius of the Circle : "<<endl;
 64   cin>>r;                 
 65   Area = CalculateCircleArea(r);           
 66   cout<<"The Area of the specified Circle is : "<<Area<<endl;    
 67   break;
 68 
 69  case 2:                  
 70   int w,h;                
 71   cout<<"Please Enter the Width and the Height of the Rectangle :"<<endl;
 72   cin>>w>>h;                
 73   Area = CalculateRectangleArea(w,h);          
 74   cout<<"The Area of the specified Rectangle is : "<<Area<<endl;   
 75   break;
 76 
 77  case 3:                  
 78   int base,h2;               
 79   cout<<"Please Enter the Base and the Height of the Triangle :"<<endl;
 80   cin>>base>>h2;               
 81   Area = CalculateTriangleArea(base,h2);         
 82   cout<<"The Area of the specified Triangle is : "<<Area<<endl;   
 83   break;
 84 
 85  case 4:                  
 86   int L;                 
 87   cout<<"Please Enter the Lenght of the Square : ";
 88   cin>>L;                 
 89   Area = CalculateSquareArea(L);           
 90   cout<<"The Area of the specified Square is : "<<Area<<endl;    
 91   break;
 92 
 93  case 5:                  
 94   int base2,h3;               
 95   cout<<"Please Enter the Base and the Height of the Parallelogram";
 96   cin>>base2>>h3;               
 97   Area = CalculateParallelogramArea(base2,h3);       
 98   cout<<"The Area of the specified Parallelogram is : "<<Area<<endl;  
 99   break;
100 
101  default:                 
102   cout<<"Invalid Choice";
103   break;
104  }
105 }
106 
107 //CalculateCircleArea is a function that return the Circle Area
108 float CalculateCircleArea(int r)
109 {
110  return PI * r * r;
111 }
112 
113 //CalculateRectangleArea is a function that return the Rectangle Area
114 float CalculateRectangleArea(int w, int h)
115 {
116  return w * h;
117 }
118 
119 //CalculateTriangleArea is a function that return the Triangle Area
120 float CalculateTriangleArea(int base, int h)
121 {
122  return 0.5 * base * h;
123 }
124 
125 //CalculateSquareArea is a function that return the Square Area
126 float CalculateSquareArea(int L)
127 {
128  return L * L;
129 }
130 
131 //CalculateParallelogramArea is a function that return the Parallelogram Area
132 float CalculateParallelogramArea(int base, int h)
133 {
134  return base * h;
135 }

download the ShapesAreas.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (4)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder

-ZeroSmaller.cpp: Problem Definition:
Write a function called ZeroSmaller() that is passed three int arguments by reference and 
then sets the smaller of the three numbers to "0"

[C++]
  1 /*  About The Simple Code "ZeroSmaller.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3 
  4     This simple code is a free simple: you can redistribute it and/or modify 
  5     it under the terms of the GNU General Public License as published by 
  6     the Free Software Foundation, either version 3 of the License, or 
  7     (at your option) any later version. 
  8   
  9     This program is distributed in the hope that it will be useful, 
 10     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12     GNU General Public License for more details. 
 13   
 14     You should have received a copy of the GNU General Public License 
 15     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 16 
 17 
 18 #include <iostream>             
 19 using namespace std;
 20 
 21 /*Problem Definition ... inspired from the sheets Quiz H)D) but a little bit more complex
 22 Write a function called ZeroSmaller() that is passed three int arguments by reference and 
 23 then sets the smaller of the three numbers to "0"
 24 */
 25 
 26 void ZeroSmaller (int &X, int &Y, int &Z);
 27 
 28 void main()
 29 {
 30  int X,Y,Z;
 31  cout<<"Please, Enter the 3 Numbers : "<<endl;
 32  cin>>X>>Y>>Z;          
 33  ZeroSmaller(X,Y,Z);         
 34  cout<<"First Number = "<<X<<endl<<"Second Number = "<<Y<<endl<<"Third Number = "<<Z<<endl;
 35 }
 36 
 37 /*
 38 ZeroSmaller is a function that Set the minimum number of the 3 Inputs numbers to "0"
 39 
 40 e.g.  if 
 41 Inputs:
 42 X = 3, Y = 5, Z = 1 (Minimum)
 43 
 44 Outputs:
 45 X = 3, Y = 5, Z = 0
 46 */
 47 void ZeroSmaller (int &X, int &Y, int &Z)
 48 {  
 51  (X < Y)? ((X < Z)? X = 0 : Z = 0) : ((Y < Z)? Y = 0 : Z = 0);
 52 
 53  /* Another Way to do the function ..Or The normal way *//*
 54           
 55 if(X < Y)
 56  {
 57   if (X < Z)
 58   {
 59    X = 0;
 60   }
 61   else
 62   {
 63    Z = 0;
 64   }
 65  }
 66  else
 67  {
 68   if(Y < Z)
 69   {
 70    Y = 0;
 71   }
 72   else
 73   {
 74    Z = 0;
 75   }
 76  }        
 77 
 78 */
 79  
 80 }



download the ZeroSmaller.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (3)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder

-EquationProblem.cpp:
Problem Definition:
Without Using MATH.h write a program that can solve the following equation and Display
"R" on the screen
R = X^Y + Y^Z - (X + Y)^2

[C++]
  1 /*  About The Simple Code "EquationProblem.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3 
  4     This simple code is a free simple: you can redistribute it and/or modify 
  5     it under the terms of the GNU General Public License as published by 
  6     the Free Software Foundation, either version 3 of the License, or 
  7     (at your option) any later version. 
  8   
  9     This program is distributed in the hope that it will be useful, 
 10     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12     GNU General Public License for more details. 
 13   
 14     You should have received a copy of the GNU General Public License 
 15     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 16 
 17 
 18 #include <iostream>             
 19 using namespace std;            
 20 
 21 /*Problem Definition
 22 Without Using MATH.h write a program that can solve the following equation and Display "R" on the screen
 23 R = X^Y + Y^Z - (X + Y)^2
 24 */
 25 
 26 
 27 float SolveEquation(int X, int Y, int Z);
 28 int Power(int Num, int Pow);
 29 
 30 void main ()              
 31 {
 32  int X,Y,Z;
 33  cout<<"Please enter X, Y and Z : ";
 34  cin>>X>>Y>>Z;             
 35  
 36  float R = SolveEquation(X,Y,Z);         
 37  cout<<"The Result is "<<R;          
 38 }
 39 
 40 
 41 /*SolveEquation is a function that Solve the equation >> R = X^Y + Y^Z - (X + Y)^2 */
 42 float SolveEquation(int X, int Y, int Z)
 43 {
 44  float r = Power(X,Y) + Power(Y,Z) - Power((X+Y),2);    
 45  return r;
 46 }
 47 
 48 /*Power is a function that take a Number and a Power Number and 
 49 returns the Number at the Power of the Power Number (Num^Pow) e.g. 2^3=8 */
 50 int Power(int Num, int Pow)
 51 {
 52  int r=1;
 53 
 54  for(int i = 0; i<Pow; i++)      
 55  {
 56   r*=Num;          
 57  }
 58  return r;          
 59 }

download the EquationProblem.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (1)


Yesterday, I’ve decided to write some simple C++ programs to help beginners to know how to write some code;
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder

1. –DynamicStars.cpp: Problem Definition:
Write a Program that Dynamically draw Stars * from "N" entered by the User to 1
 
e.g. 
 
Input: 3
 
Output:
 
***
**
*

[C++]
  1 /* About The Simple Code "DynamicStars.cpp"
  2 
  3 Copyright (C) 2013 Eng. Mohamed Adel (http://www.med-adel.com)
  4 
  5 This simple code is a free simple: you can redistribute it and/or modify 
  6 
  7 it under the terms of the GNU General Public License as published by 
  8 
  9 the Free Software Foundation, either version 3 of the License, or 
 10 
 11 (at your option) any later version. 
 12 
 13 This program is distributed in the hope that it will be useful, 
 14 
 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 
 16 
 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 18 
 19 GNU General Public License for more details. 
 20 
 21 You should have received a copy of the GNU General Public License 
 22 
 23 along with this program. If not, see <http://www.gnu.org/licenses/>.*/
 24 
 25 #include <iostream>
 26 
 27 using namespace std;
 28 
 29 /*Problem Definition
 30 
 31 Write a Program that Dynamically draw Stars * from "N" entered by the User to 1
 32 
 33 e.g. 
 34 
 35 Input: 3
 36 
 37 Output:
 38 
 39 ***
 40 
 41 **
 42 
 43 *
 44 
 45 */
 46 
 47 void DrawStars(int n);
 48 
 49 void main ()
 50 
 51 {
 52 
 53  int n;
 54 
 55  cout<<"Please enter the max number of stars to be drawn :";
 56 
 57  cin>>n;
 58 
 59  DrawStars(n); 
 60 
 61 }
 62 
 63 
 64 /*DrawStars is a function that draw Stars starting from N till 1 Star*/
 65 void DrawStars(int n)
 66 
 67 {
 68 
 69  for(int i = 0 ; i < n; i++)
 70 
 71  {
 72 
 73   for(int j=0; j < n-i; j++) 
 74   { 
 75    cout<<"*"; 
 76   }
 77 
 78   cout<<endl; 
 79 
 80  }
 81 
 82 }


download the DynamicStars.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Some C++ Problems for Beginners (2)


This Post has some Previous Posts, you can access the first Main Post here: Some C++ Problems for Beginners (1)
The code was written and tested on Visual Studio 2010 –> “Empty Windows Console Application” . if you don’t have Visual Studio, you can get the latest version from :
-Visual C++ 2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

note that, you can also use another IDEs like:
-Visual Studio Express 2012 for Windows Desktop: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products#product-express-summary
-CodeBlocks: http://sourceforge.net/projects/codeblocks
-GNU C++ compiler GCC(g++): http://gcc.gnu.org/
-MingW GCC port for windows: http://www.mingw.org/
-C++ Builder (Borland): http://www.embarcadero.com/products/cbuilder

1. -AlphabeticalModulus.cpp: Problem Definition:
Write a Program that read 2 Numbers from the user X & Y where 1<= Y <= 9 (if Y is not in
the specified range terminate the program)
Print R = X % Y (R = X Modulus Y) in English Letters

e.g. 
if 
R = 5 --> Print "Five"
 
note: R will always be a value between 0 and 9

[C++]
  1 /*  About The Simple Code "AlphabeticalModulus.cpp"
  2     Copyright (C) 2013  Eng. Mohamed Adel (http://www.med-adel.com)
  3 
  4     This simple code is a free simple: you can redistribute it and/or modify 
  5     it under the terms of the GNU General Public License as published by 
  6     the Free Software Foundation, either version 3 of the License, or 
  7     (at your option) any later version. 
  8   
  9     This program is distributed in the hope that it will be useful, 
 10     but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12     GNU General Public License for more details. 
 13   
 14     You should have received a copy of the GNU General Public License 
 15     along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 16 
 17 
 18 #include <iostream>             
 19 using namespace std;
 20 
 21 /*Problem Definition
 22 Write A Program that read 2 Numbers from the user X & Y 
 23 where 1<= Y <= 9 (if Y is not in the specified range terminate the program)
 24 Print R = X % Y (R = X Modulus Y) in English Letters
 25 e.g. 
 26 if 
 27 R = 5 --> Print "Five"
 28 
 29 note: R will always be a value between 0 and 9
 30 */
 31 
 32 char * ConvertToEnglish(int Num);
 33 
 34 
 35 int main ()
 36 {
 37  int X,Y,R;
 38  cout<<"Please Enter X then Y where (1<= Y <=9) :"<<endl;
 39  cin>>X>>Y;
 40  if(Y<1 || Y>9)
 41   {
 42    cout<<"Invalid Y Value";
 43    return 0;
 44   }
 45 
 46  R = X % Y;
 47  cout<<"The Result is : "<<ConvertToEnglish(R)<<endl;
 48  return 1;
 49 }
 50 
 51 
 52 //ConvertToEnglish is a function that convert the integer number to its corresponding 
 53 //English word and returns a Char* (array of chars/string) containing the English word
 54 //e.g. 1 --> One, 2 --> Two, etc...
 55 char * ConvertToEnglish(int Num)
 56 {
 57  switch(Num)
 58  {
 59  case 0:
 60   return "Zero";
 61   break;
 62  case 1:
 63   return "One";
 64   break;
 65  case 2:
 66   return "Two";
 67   break;
 68  case 3:
 69   return "Three";
 70   break;
 71  case 4:
 72   return "Four";
 73   break;
 74  case 5:
 75   return "Five";
 76   break;
 77  case 6:
 78   return "Six";
 79   break;
 80  case 7:
 81   return "Seven";
 82   break;
 83  case 8:
 84   return "Eight";
 85   break;
 86  case 9:
 87   return "Nine";
 88   break;
 89  default:
 90   return "Error";
 91   break;
 92  
 93  }
 94 
 95 }

download the AlphabeticalModulus.cpp  (Commented, Explained Code)

Download all the C++ Simples I’ve created : C++ Problems

Friday, September 28, 2012

What is Enterprise Search?

 

 

-Enterprise Search refers to “Search behind the corporate Firewall” or

It is the Search technology that the organization owns and controls

-Many applications could include search on a company’s website home page and tech support area, or e-commerce shopping sites.

-So Enterprise search engines could be defined as all search engines except the public ones like Yahoo, Google and MSN (BING).

 
  For More Info Please Visit: What is Enterprise Search?  

How do Enterprise Search Engines differ from Web Search Engines?

 


Many of us think that the Search Engines are all the same, but we have to know that Search Engines have different types that are totally Different and that there are many differences between for example the Enterprise Search Engines and the Normal Public Web Search Engines like Google and Bing such as:

 

1. The Enterprises world isn’t just a small Internet: 

–Many Enterprise Search Offering began life as a search engines to power generic Internet Portal Searching, Thus we should assume that if you could handle the internet, then of course you could handle a relatively puny private Enterprise NetworkIn Fact, It’s not true and this assumption is usually false, Thus.. Any Enterprise Search Engine should be customized and adjusted to work well in the non-Internet like networks.

 

2. Technical Differences in Search Requirements and Technologies:

-Aside from the difference in the architecture and data volume between Internet Search and Enterprise Search, There are also differences in how the infrastructure is used and functional requirements such as:

  • There is Usually a right document in the Enterprise Search (Whereas Google for example finds tens of thousands of pages relevant to almost any search you could imagine)
  • Security is Critical: On the Internet, content is public for anyone or everyone who may find it, but companies have many specific security requirements from “Company Confidential” to “Limited Distribution”, there may be sometimes some legal implications if a document is released to the public before a specific time.

3-Taxonomies and Vocabulary are critical: Companies always have a specific vocabulary such as: product names, projects, procedures and policies, Thus.. Taking advantages of these terms unique to the company is critical to making retrieval work better.

 

4-Dates are important:

-Internet search is generally unaware of document dates because content on the internet always lock this info.

e.g. if the corporate search for “Annual Reports” doesn’t return the Most recent document, The Employees will be unhappy for sure.

 

5-Corporate Data has Structure:

In a corporate database and even in web contents, companies have a specific structure that make some results authorized or accessed for some employees and not permitted for some others.

Thus, Enterprise Search Engines have to be able to apply the company’s rules and hierarchy on the outputs returned to the employees.

 

Conclusion:

There are dozens of things that make Enterprise Search Engines suprizingly difficult and that sometimes exceed the strength and size of the Public Engines created to empower the web such as Google, Yahoo and Bing.

 

 
  For More Info Please Visit: Another Difference Between Enterprise Search and Web Search  

Friday, October 7, 2011

Wake On LAN

 


Wake on LAN is something very useful, when thinking about not wasting energy, use Wake on LAN if you don’t like throwing money away to an always-on System.


1-Enable Wake on LAN in your BIOS:

 

-restart your computer and press and hold the

delete key (or whatever key to access your BIOS

settings)

-Once you are in the BIOS, go to the Power

Management section and search for the Wake on LAN settings.

Enable the Wake on LAN, Save and Exit.

-On some boards you may have to enable a "Power On

By PCI Devices" setting, others you won't find the

Wake on LAN option.

 

 

2-Enable Wake on LAN in Windows

 

-To Enable Wake on LAN in Windows, Right-Click on My Computer, select properties, then click on Device manager.
-Find your Network Card in the Hardware List, right click it and click properties.
-Go to Power Management tab in the Properties and tick the checkbox next to "Allow this device to wake the computer".

-Now Go to the Advanced tab and Change the "Wake From Shutdown" option to "On"
and the "Wake On Magic Packet" setting to "On".

Hit OK.

 

3-WAKE YOUR COMPUTER

//you can use the Magic Packet Sender Freeware to wake your computer from any device http://magicpacket.free.fr/

 

1-on the computer that you want to wake up, type the command in the CMD ipconfig/all.
take your internet connection ipv4 address and Physical address (MAC Address)

 


a-For Inner Network Remote Connections:

 

-Send a Magic packet with a host name = to the ipv4 of your computer "Internal IP Address", your computer's MAC address and your Subnet Mask should be 255.255.255.255

note: you have to use the UDP as your network protocol and port 9 as the sending port.

 


b-For Internet Connections:

 

-Send a Magic packet with a host name = to the external ipv4 of your computer (you can get it from www.whatismyip.com ), your computer's MAC address and your Subnet Mask should be 0.0.0.0

note: you have to use the UDP as your network protocol and port 9 as the sending port.

 

NOTE: you can also use www.dyndns.com  and create a free account to access your router and settings from the internet.


Good Luck ;)

 
  For More Info Please Visit: http://en.wikipedia.org/wiki/Wake-on-LAN  

Wednesday, September 28, 2011

Math Problem

One of the mathematical problems that I’ve seen today and decided to solve it :)
Problem:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

Solution (This is my own solution – you can solve it using another way)
-The nearest multiple of 3 below to 1000 is 999 then we have 999/3 = 333 multipliers –>1 –> “m”
-The nearest multiple of 5 below to 1000 is 995 then we have 995/5 = 199 multipliers –>2
--> from step “1” we have:
The sum of all multiples of a Number n = (the number in the set “n”) x (The mean of the Set “o”)
n = 3 ,  o = m(m + 1) / 2 = 333(333 + 1)/2 = 333 (334)/2 = 55611

then the sum = 3 * 55611 = 166833 –> 3
--> from step “2” we have:
n = 5, o = 199 (200) / 2 = 19900
then the sum = 5 * 19900 = 99500 –> 4
From step “3” and step “4” we have:
the total sum of all multiplies of 3 and not or 5 below 1000 = 166833 + 99500 = 266333
We want now to remove the common multipliers between the 3 and 5 –> 3 * 5 = 15 –> n = 15
-The nearest multiple of 15 below to 1000 is 990 then we have 990/15 = 66 multipliers
then the sum = 15 * 66(67)/2 = 33165

Finally we got, the total sum of all multiples of 3 or 5 below 1000 = 266333 – 33165 = 233168

hope you enjoyed it too;
Thanks;
Mohamed Adel
For More Info Please Visit: http://projecteuler.net

Wednesday, September 21, 2011

How to Block “Facebook” on all your browsers

 


Sometimes, Facebook is wasting a lot of our working, studying or life time;

I will talk today about how to block “Facebook” on all your browsers;

Sometimes, The Normal block method used from the “Internet Options” isn’t working on some sites like Facebook.

Today, I’ll teach you how to block the Facebook Site from the Host File;

1-Open the C:\Windows\System32\drivers\etc folder

2-Right Click on the hosts file and Open it with Notepad or any text editor

3-Search for this line in the file:  #    127.0.0.1       localhost

4-Add these 2 lines after it:

127.0.0.1 facebook.com
127.0.0.1
www.facebook.com

(See the Figure)


5-Save the file.

  • Sometimes you can’t overwrite the host file when saving, follow these steps:
  1. Save the host file after editing it on any location you know on you PC
  2. From Windows Explorer Open Tools –> Folder Options –> View then Uncheck the “Hide extensions for known file types”.
  3. remove any additional extensions added to the file that you have created e.g. hosts.txt –> hosts remove the .txt by renaming the file.
  4. copy your host file from the location you know and replace the file in the C:\Windows\System32\drivers\etc folder.
  5. Say ByeBye Facebook

Share it if you believe that it’s important.

 
  For More Info Please Visit: 10 Reasons to leave Facebook  

AI-Enabled Risk Scoring for TPPs in Open Banking: A Game Changer for Ecosystem Trust

As Open Banking ecosystems mature globally, traditional banks, fintech startups, and regulators face a growing challenge: how to trust the g...