Jump to content
xisto Community
Sign in to follow this  
khosro_php

Simple C++ Programs. simple programs for beginners.

Recommended Posts

if you want to start c++ programing read and train this simple programs.

 

1."using ? command."#include <iostream.h>#include <conio.h>int main(){clrscr();float a,b,c,d;cin >>a>>b>>c>>d;a=(a>c+d)?(a*c) : (b*d);cout <<"a="<<a;getch();return 0;}[/indent][indent]2."using of while loop command."#include <iostream.h>#include <conio.h>int main(){clrscr();float a,b,c,d;cin >>a>>b>>c>>d;a=(a>c+d)?(a*c) : (b*d);cout <<"a="<<a;getch();return 0;}[/indent][indent]3."using of for loop"#include <iostream.h>#include <conio.h>int main(){clrscr();float a,b,c,d;cin >>a>>b>>c>>d;a=(a>c+d)?(a*c) : (b*d);cout <<"a="<<a;getch();return 0;}[/indent][indent]4."conwerting a secund to hour and minute and secund."#include <iostream.h>#include <conio.h>int main(){clrscr();float a,b,c,d;cin >>a>>b>>c>>d;a=(a>c+d)?(a*c) : (b*d);cout <<"a="<<a;getch();return 0;}[/indent][indent]5."calculate numbers of a data"#include <iostream.h>#include <conio.h>int main(){clrscr();int a,b,c=0;cout <<"enter number:";cin >>a;while(a>0){b=a%10;c+=b;a/=10;}cout <<"result="<<c;getch();return 0;}[/indent][indent]6."simple working with numbers"#include <iostream.h>#include <conio.h>int main(){clrscr();int a,b,c,i=1,j=0;cout <<"enter a num:";cin >>a;c=a;while(c>0){c/=10;j++;}c=0;while(a>0){b=a%10;i=1;while(i<j){b*=10;i++;}j--;c+=b;a/=10;}cout <<"Maghloob="<<c;getch();return 0;}
Notice from jlhaslip:

bbcode code tags are required

 

 

 

 

Edited by jlhaslip (see edit history)

Share this post


Link to post
Share on other sites

You might also want to explain how that's simple. There's no way a newbie to C/C++ could get through that as it is. I myself learned the conditional operator after operator overloading.Oh yeah, and you're missing a label for everything as "C++" and the use std commands.Gets errors on ANSI-strict compilers such as Dev-C++ :unsure:

Share this post


Link to post
Share on other sites

I would agree these are not really programs for the beginners and as there is no comment present I think beginners will not have any help from it. As one way or the other they want understand what have you done in certain parts of code.

Share this post


Link to post
Share on other sites

@mahesh2k: Aww... only Turbo C++ graphics stuff? I'd love to see some stuff we all use.

(*cough* gcc *cough*) Or maybe it's just that this internet connection's slightly rickety right now

and I can't find the other C++ graphics tutorials.

 

However, nice site. I look forward to checking it out when I have time. :lol:

Share this post


Link to post
Share on other sites

Gretingsman i dont onderstand c++,if you want a beginner to understand Your tutorials coukd you please add some comments to themthat would really help us thaks,have a nice day :lol: bye

Share this post


Link to post
Share on other sites

i am a newbie at c++, but i think easyc is the best begginer program for programing. playing around on that really help me to understand c++ programing

Share this post


Link to post
Share on other sites

Friends :lol: here i am to explain to u abt writing a simple C++ program -Hope this will be useful to u ...Every C++ program contains one or more functions, one of which must be named main . A function consists of a sequence of statements that perform the work of the function. The operating system executes a program by calling the function named main. That function executes its constituent statements and returns a value to the operating system.Here is a simple version of main does nothing but return a value: int main() { return 0; }The operating system uses the value returned by main to determine whether the program succeeded or failed. A return value of 0 indicates success.The main function is special in various ways, the most important of which are that the function must exist in every C++ program and it is the (only) function that the operating system explicitly calls.We define main the same way we define other functions. A function definition specifies four elements: the return type, the function name, a (possibly empty) parameter list enclosed in parentheses, and the function body. The main function may have only a restricted set of parameters. As defined here, the parameter list is empty; Section 7.2.6 (p. 243) will cover the other parameters that can be defined for main.The main function is required to have a return type of int, which is the type that represents integers. The int type is a built-in type, which means that the type is defined by the language.The final part of a function definition, the function body, is a block of statements starting with an open curly brace and ending with a close curly: { return 0; }The only statement in our program is a return, which is a statement that terminates a function.bye,,,,,

Share this post


Link to post
Share on other sites

next let us study abt the output stat in C++...tis is so simple...One of the most basic things that you can do in a program is to write some output to the screen. In C++ this is usually done with cout as in the following example:cout << "This is the message that would appear on screen." << endl;Note that a message string is enclosed in double quotes. The << symbols point in the direction of data flow: from the message string to the cout output stream. The endl moves the cursor to the beginning of the next line on the screen. Finally, note that the command, like all C++ statements, ends with a semicolon.

Share this post


Link to post
Share on other sites

Hi ... i have told u the Simple programing logic...but the facit is that:lol: hehehefor real there is no easy way into codingyou have to know the code and you need a assembler thats alla use MS vistual studio

Share this post


Link to post
Share on other sites

no Real shortcut for programming...you can start from Turbo C++ or with VC++ from Microsoft...U need to understand bare minimum just to write simple code---------------------------------------------Datatypes.Procedural programming/Object Oriented programmingFunctions-------------------------------------next comesArraysPointersstructures

Share this post


Link to post
Share on other sites

you want to learn C/C++ by yourself?! I took a introductory class on it in hs and thought it was hella hard. I'm sure I'm not the only one...let's say there was a bit of copying going on the programming assignments :lol

Share this post


Link to post
Share on other sites

Know C or C++ -> you know Java (but never use it wink.gif )Know java -> C++ and especially C is difficult for you because it is more low level than javaSo it all depends upon which one you start with, and starting with C is much more advantageous.C is the standard for programming today, maybe someday it'll be java, but hopefully not! Anyways, you can't really compare C with Java since Java works in a completely different way.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.