|
|
|
|
![]() ![]() |
Dec 24 2007, 03:29 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 239 Joined: 10-December 07 From: India Member No.: 54,553 |
Hi any C++ programmer want to share C++ programs,then post the code here.But it would be good if the programs are not too long.So only short programs.
But post that code in bbcodes-don't forget that. Anyone who doesn't understand any programs that are posted can take any help here in this thread. Heres one : This is a program using class: CODE #include<iostream.h>
class sum { private: int a,b,c; public: sum() { a=5,b=6; } sum(int x,int y) { a=x,b=y; } void get() { cin>>a>>b; } void calc() { c=a+b; cout<<c; } }; void main() { sum s1,s2(2,3),s3; s1.calc(); s2.calc(); s3.get(); s3.calc(); } This post has been edited by musicmaza: Dec 24 2007, 03:32 PM |
|
|
|
Feb 26 2008, 07:54 PM
Post
#2
|
|
|
Newbie [Level 1] ![]() Group: [HOSTED] Posts: 22 Joined: 20-February 08 Member No.: 58,158 |
This is small program that generates a random number and asks you for it
If you guess it than it is right If you don't it will tell you if it is more or less It is in french but i think you'll understand the idea (may be i'll make another edition in english !) CODE /////////////////////////////////////////////////////////////////////////////// // Excellence micro systems® 2007© // // // // We are glad to present for you our "Plus ou moin v2.0" it is a little // //game running under a console for example ms-dos or Konsole ... The "Plus ou// //moin v1.1.exe" file runs under MS-dos and Windows console.. With the source// //code you can compile the application and make it work with any OS such as // //Windows , Linux , mac OS ... To see what's new on that version pleaze run // //the file named "what's new.txt" .... Now we wish for you a funy time;) // // // // To contact us please send a mail to Mr Dhia Eddine Chouchane // //"assir2@hotmail.fr" // //Or take a look at our main site : "http://excellence.247ihost.com" // /////////////////////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <time.h> //librairie qui permet de tirer un nombre au hazard int main(int argc, char *argv[]) { //Tout d'abord défénir les variables de l'environnement long nombreDevined = 0 , nombreMystere = 0 , nombreDeCoups = 0 , choix; int MAX = 100 , MIN = 1 , Jeu = 1; //L'intro! printf("Excellence micro systems presente :\n\nLe jeu de plus ou moin ..."); printf(" \n\n\n\n\n\n\n"); //Puis definir la fonction de choix aleatoire srand(time(NULL)); //Apres on commence dans le programme //On demande le choix de l'utilisateur printf("Que voulez vous faire?\n"); printf("\n1. Jouer\n"); printf("2. Quitter l'application\n"); printf("\n== Entrez le Numero de votre choix et puis ENTRER\n"); printf("\n\n\n\n\n\nREMARQUE : Pour quitter durant le jeu appuyer sur 0 puis sur ENTRER\n\n"); scanf("%ld", &choix); switch (choix) { case 1 :; break; case 2 : printf("Tu vas quitter le jeu !!\n\n\n"); Jeu = 0; break; default : printf("Ton choix ne figure pas dans la liste\n"); break; } // On entre dans une boucle pour pouvoir rejouer afin d'accomplir le jeu while (Jeu) { //Le programme charge un nombre au hasard nombreMystere = (rand() % (MAX - MIN + 1)) + MIN; /* On redefinie nombreDevined en 0 pour que ça ne pe jamais etre égal avec nombreMystere*/ nombreDevined = 0; while (nombreDevined != nombreMystere) { //On demande le nombre printf("Quel est le nombre ?"); scanf("%ld", &nombreDevined); nombreDeCoups++; //Puis on fait l'analyse if (nombreDevined == nombreMystere) { printf("Bravo, vous avez trouve le nombre mystere en %ld essais!!!\n\n" , nombreDeCoups); //On demande de l'utilisateur si il veux rejouer printf("Voulez vous jouer une deuxieme fois?\n"); printf("si oui tapez 1 puis ENTRER\n"); printf("si non tapez 2 puis ENTRER\n"); scanf("%ld", &choix); switch (choix) { case 1 : Jeu = 1; break; case 2 : Jeu = 0; break; default : printf("Ton choix ne figure pas dans la liste\n"); printf("Tu vas quitter le jeu\n"); break; } } //N'oublions pas que nous sommes toujours en analyse if (nombreDevined == 0) { printf("\n\nTus va quitter le jeu\n\n\n"); Jeu = 0; nombreDevined = nombreMystere; } else if (nombreDevined > nombreMystere) { printf("C'est moins !\n\n"); } else if (nombreDevined < nombreMystere) { printf("C'est plus !\n\n"); } else printf("Ce que tu a entre est faux ou tu a choisis de quitter l'application\n\n"); } } /*demander de l'utilisateur de taper une touche pour continuer afin qu'il peut voir ce qui c'est écrit*/ system("PAUSE"); return 0; } //////////////////////////////////////////////////////////////////////////////// // All rights reserved to Excellence micro systems® 18/08/2007© // // and to its owner Mr. Dhia Eddine Chouchane // //////////////////////////////////////////////////////////////////////////////// Now how about some optimizations ? |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 14th May 2008 - 02:48 AM |