الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

بعض الدوال المهمة والمفيدة

بدأه security professional في 21 أكتوبر 2012 · 3 رد · 776 مشاهدة · في لغة C و ++C
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذه بعض الدوال المهمة والمفيدة من برمجتي فقد تستطيع استعمالها والاستفادة منها :

                                                // My Header Made By Ameen Ali Ali All Right's Reseved (C) 2012 # 
											   //                    For Begginer's Only :D                     #  
											  //################################################################# 
#include <iostream>
#include <cmath>
#incldue <string>
#include <iomanip>
#include <fstream>
using namespace std ;
/*##########################################################################
#                                                                          #
#                     Function's Prototype                                 #
#                                                                          #
###########z################################################################*/
int Largest(int , int) // Find The Largest Number In Two Number's .
void Reverse(int) // Revrse The Number Digit's For Example The Number : 123456 After This Call The Number Will Be Like This 654321
int Smallest(int , int) // Find The Smallest Number Between Two Number's
void Draw_Line(int) // Draw A Line With A Specific Tall
int Sum_Of_All_Digits(int) // Return The Sum Of All The Number Digit's Fo Exmaple : 123 = 1 + 2 + 3 = 6
void Print_Individual_Digits(int) // Output The Individual Digits For Example : 123 Would Be : 1 2 3 
void Lower_To_Upper(string &) // Convert From LowerCase String To UpperCase String For Example : ameen -> AMEEN 
void Upper_To_Lower(string &) // Convert From The UpperCase String To UpperCase String For Example : AMEEN -> ameen
void UpperToLower_Char(char &) // Convert From UpperCase Char To LowerCase Char For Example : A -> a
void LowerToUpper_Char(char &) // Convert From LowerCase Char To UpperCase Char For Example : a -> A 
void Print_Clock(void) // Print The Clock With This Formula : hh : mm : ss The Time Starts At 0 : 0 : 0
void Print_Clock_OverLoaded(int , int , int) ; // Print The Clock With A Specific Time So You Must Pass The Folowing Paramters To The Function : Hour's , Minutes , Seccond's
void Wait(int Secconds) // This Function Take Number Of Seccond's To Wait As A Parameter
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-#
#                                                        #
#                  Function's Defintion                  #
#                                                        #
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
int main()
{
   return 0 ;
}
// Function Number One The Goal Of This Function Is : Find The Largest Number In Two Number's .
int Largest(int a , int b) // Function ProtoType
{
  int Max ; // Declare The Max Varible
  Max = (a > b) ? a : b ; // Testing The Largest Number And Put It Into The Max Varible
  return Max ; // Return The Max Value
}
/* Note On The Function Number One You Can Use This Function To Find The Largest Number Between Any Number Of Number's Just By Using A Loop 
         For Example Consider This Code That Find The Largest Number In 10 Number's And You Will UnderStatnd What I Mean : 
#        int max , number ;                               #
#        cin >> number ;                                  #
#        max = number ;                                   #
#        for(int i = 1 ; i < 10 ; i++)                    #
#        {                                                #
#             cin >> number ;                             #
#           max = Largest(max , number) ;                 #
#                 }                                       #
#               cout << max << endl ;                     #
#                                                         */
 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*
 // Function Number Two The Goal Of This Function Is : Revrse The Number Digit's For Example The Number : 123456 After This Call The Number Will Be Like This 654321
  void Reverse(int a)
  {
   int Number = 0 ; // Declare Number To Be Int Varible
   while(a != 0) // Testing a Not Equal To 0
   {
      Number = a % 10 ; // Putting The Mode Value Of The Expression a % 10 To The Number Varible
	  cout << Number ; // Printing The Value Of The Varible Number
	  a /= 10 ; // Div A By 10
   }
     cout << endl ; // Printing New Line 
  }
  // Function Number Three The Goal Of This Function Is : Find The Smallest Number Between Two Number's
  int Smallest(int a , int b)
{
  int Small ; // Declare Max To Be An Int Varible
  Small = (a > b) ? b : a ; // Testing The Smallest Value Betwenn a and b And Puting It Into Max Varible
  return Small ; // Return The Smallest Value
}
// Function Number Four The Goal Of This Function Is : Draw A Line With A Specific Tall
void Draw_Line(int x)
{
  for(int i = 1 ; i <= x ; i++) // The Loop
       cout << "_" ; // Printing A _
	 cout << endl ; // Printing A New Line
}
// Function Number Five The Goal Of This Function Is : Return The Sum Of All The Number Digit's Fo Exmaple : 123 = 1 + 2 + 3 = 6
int Sum_Of_All_Digits(int x)
{
   int Sum = 0 ; // Decalre Sum To Be Int Varible
   while(x != 0)// Testing If x Not Equal To 0
   {
     Sum += x % 10 ; // Update The Value Of Sum By Adding The Result Of The Expression x % 10
	 x /= 10 ; // Div x By 10
   }
      return Sum ;
}
// Function Number Six The Goal Of This Function Is : Output The Individual Digits For Example : 123 Would Be : 1 2 3 
void Print_Individual_Digits(string x)
{
	char ch ;
	int i = x.length() ;
	int d = 0 ;
	while(d < i)
	{
		ch = x.at(d) ;
		cout << ch << " " ;
		d++ ;
	}
	cout << endl ;
}
// Function Number Seven The Goal Of This Function Is : Function Convert From LowerCase String To UpperCase For Example : ameen -> AMEEN 
void Lower_To_Upper(string &s)
{
		char ch ;
	int i = s.length() ;
	int ss = 0 ;
	int n ; 
	while(ss < i )
	{
		ch = s[ss] ;
		n  = static_cast<int>(ch) ;
		if( (n >= 97 ) && ( n <= 122) )
		{
			ch = static_cast<char>(n - 32) ;
		s[ss] = ch ;
		}
		ss++ ;
	}
	// Function Number Eight The Goal Of This Function Is : To Convert From The UpperCase String To UpperCase String For Example : AMEEN -> ameen
void Upper_To_Lower(string & String)
{
	int Length = String.length() ;
	char ch ; 
	int s = 0 ;
	int Number ;
	while(s < Length)
	{
		ch = String ;
		Number = static_cast<int>(ch) ;
		if( (Number >= 65) && (Number <= 90) )
		{
			Number = Number + 32 ;
			ch = static_cast<char>(Number) ;
			String = ch ;
		}
		s++ ;
	}
	// Function Number Nighn The Goal Of This Function Is : To Convert From UpperCase Char To LowerCase Char For Example : A -> a
	void UpperToLower_Char(char& a)
{
	int Number ;
	Number = static_cast<int>(a) ;
	if ( (Number >= 65) && (Number <= 90) )
	{
		a = static_cast<char>(Number + 32) ;
	}
}
    // Function Number Ten The Goal Of This Function Is : To Convert From LowerCase Char To UpperCase Char For Example : a -> A
void LowerToUpper_Char(char& a)
{
	int Number ;
	Number = static_cast<int>(a) ;
	if ( (Number >= 97) && (Number <= 122) )
	{
		a = static_cast<char>(Number - 32) ;
	}
}
    // Function Number Eliven The Goal Of This Function Is : To Print The Clock With This Formula : hh : mm : ss The Time Starts At 0 : 0 : 0
void Print_Clock()
{
	int hh = 0 ; 
	int mm = 0 ; 
	int ss = 0 ;
	int i = 0 ;
	while(true)
	{
		system("CLS");
		ss++ ;
		if(ss == 200)
		{
			ss = 0 ;
			i++ ;
		}
		if(i == 60)
		{
			i = 0 ;
			mm++ ;
		}
		if(mm == 60 )
		{
			mm = 0 ;
			hh = 1 ;
		}
		cout << hh << " : " << mm << " : " << i << endl ;
}
}
    // Function Number Twelv The Goal Of This Function Is : To Print The Clock With A Specific Time So You Must Pass The Folowing Paramters To The Function : Hour's , Minutes , Seccond's
void Print_Clock_OverLoaded(int hh , int mm , int ss)
{ 
    while(mm > 60)
	{
		mm = mm - 60 ;
		hh++ ;
	}
	while(ss > 60)
		{
			ss = ss - 60 ;
			mm++ ;
		}
	int sss = 0 ;
	while(true)
	{
		system("CLS");
		sss++ ;
		if(sss == 200)
		{
			sss = 0 ;
			ss++ ;
		}
		if(ss == 60)
		{
			ss = 0 ;
			mm++ ;
		}
		if(mm == 60 )
		{
			mm = 0 ;
			hh++ ;
		}
		cout << hh << " : " << mm << " : " << ss << endl ;
}
}
     /*####################################################################################################################################################     
     #   Note About The Function Number Twelv This Function Is An OverLoaded Function So The Function Number Eliven Is The Same As Function Number Twelv  #
     #                        But The Diffrence Is That The Function Number Twelv Has Three Parameters                                                    #
     #                        So This Function Will Start Counting The Time Printing From This :                                                          #
     #                        hh:mm:ss So If You Called The Function Print_Clock With This :                                                              #
     #                        Print_Clock(12,25,44) The Function Will Print The Time Starting From 12:25:44                                               #
     #####################################################################################################################################################*/  
     // Function Number Therteen The Goal Of This Function Is : This Function Take Number Of Seccond's To Wait As A Parameter	 
void Wait(int Secconds)
{ 
	int i = 0 , m = 1 ;
	while( m < Secconds)
	{
		system("cls") ;
		i++ ; 
		if(i == 200)
		{
			i = 0 ;
			m++ ;
		}
	}
} 
/* Note About The Function Number Therteen The Call Formula To This Function Is Like This : Wait(Number Of Seccond's To Wait) : Wait(10)
                                  This Call Will Wait 10 Seccon'ds Before Executin The Next Statment's */
#2

السلام عليكم

هل الموضوع مفتوح للنقاش ؟ :)

إذا كان كذلك فدعنا نبدأ بالدوال, الواحدة تلو الآخرى ..

و نتناقش حول جودة الكود و الإضافات التي يُمكن أن تُحسنه.

إذا كان الموضوع للقراءة فقط (Read-Only) فأعتذر عن الإزعاج :happy:

#3

هههههههههههههههههههههههههههه

لا فأنا لم اجد نوع الموضوع المناسب او الخيار المناسب لذالك وضعته للنقاش

#4

إذا كان الأمر كذلك ، فإليك دالتي الغبية التي تقوم بنسخ ملف من مكان إلى آخر ،،، smile.gif



int CopyFile(char *_From, char *_To)
{
char Data;
FILE *From, *To;
From = OpenFile(_From,"rb");
if(From == NULL)return 0;
else{
To = OpenFile(_To,"wb");
do{
fread(&Data,sizeof(Data),sizeof(Data),From);
fwrite(&Data,sizeof(Data),sizeof(Data),To);
}while(!feof(From));
CloseFile(From);
CloseFile(To);
return 1;
}

laugh.gif ...

تقوم بنسخ الملف بايت تلو بايت

rS3eY.png

مواضيع مشابهة