Jump to content

Recommended Posts

Posted

السلام عليكم ورحمة الله بركاتة

كيف حال الشباب ان شاء اللـه تكونو في أتم الصحة والعافيه 

استفساري القوي (بنسبة لي ههه) هو

كيف اسوي دالة مثل 

setTimer 

C++ بال

او اذا كان في من الاساس ايش هي 

Posted
#include <iostream>
#include<ctime>
using namespace std;
 
typedef void (*Func)();
 
 
void function_1() 
{
	cout << "hello world" << endl;
}
 void function_2 ()
 {
 	cout << "yay :D" << endl;
 }
void setTimer(int tim , Func fun) 
{
	int start = time(NULL);
	for (true;; ) 
	{
		int end = time(NULL);
		if ((end - start) >= tim) 
		{
			fun();
			return ;
		}
	}
}
int main() {
	setTimer(1 , function_2);
	setTimer(2 , function_1);
}

تم حل المشكلة 

للي بده يستفيد

Posted (edited)
#include<ctime>
// setTimer ( time , the function , Number of times done )
void setTimer(int tim, Func fun , int num)
{
	double much = 0;
	int start = time(NULL);
	for (true;; ){
		double end = time(NULL);
		if (num == 0) {
			fun();
		}
		else if (num > 0) {
			double much = (tim/num);
			if ( much == (end - start) ){
				
				fun();
				if (num > 1) {
					num--;
				}
				else {
					break;
				}
			}
		}
		if ((end - start) >= tim){
			break;
		}
	}
}

الان صار نفسه setTimer 

Edited by D7mas
  • Like 1
  • 3 weeks later...
Posted
On 01/10/2019 at 02:05, D7mas said:

#include<ctime>
// setTimer ( time , the function , Number of times done )
void setTimer(int tim, Func fun , int num)
{
	double much = 0;
	int start = time(NULL);
	for (true;; ){
		double end = time(NULL);
		if (num == 0) {
			fun();
		}
		else if (num > 0) {
			double much = (tim/num);
			if ( much == (end - start) ){
				
				fun();
				if (num > 1) {
					num--;
				}
				else {
					break;
				}
			}
		}
		if ((end - start) >= tim){
			break;
		}
	}
}

الان صار نفسه setTimer 

وعليكم السلام 

شغلك كويس 

بس للعلم دالة Time بشتشغل على الثواني 

يعني اذا حطيت الوظيفة تتنفذ مرتين خلال خمس ثواني رح تتنفذ اول ثانيتين و بعد ثلالث ثواني مرة ثانية 

المفروض 2.5 كل مره 

 

  • 10 months later...
Posted
On 01/10/2019 at 01:05, D7mas said:

الان صار نفسه setTimer 

اقدر جهدك لكن هذي خبصه يا غالي

الفنكشن اولا لازم يكون له نوع معرفه وهو

asynchronous

او الغير متزامن اتوقع كذه ترجمته

المهم لصاحب الموضوع تفضل هالرابط بيفيدك باذن الله

https://stackoverflow.com/questions/33234403/using-setinterval-in-c

بالتوفيق للجميع

Skype 01100001 01101100 01101001 01011111 01101101 01110100 00110001 00111001 00111001 00111001

every thing is gonna be alright

every thing is gonna be okay

it's gonna be a good good life

that's what my therapist say

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...