Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
Photo
* * * * * 1 votes

Simple C++ Programs. simple programs for beginners.


17 replies to this topic

#1 khosro_php

khosro_php

    Newbie

  • Kontributors
  • Pip
  • 4 posts

Posted 25 April 2007 - 09:21 PM

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, 26 April 2007 - 12:48 AM.

  • 0

#2 jlhaslip

jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,159 posts
  • Gender:Not Telling
  • myCENT:47.16
  • Spam Patrol

Posted 26 April 2007 - 12:49 AM

might want to explain all these code snippets before a Mod does a plagiarism check.
  • 0

#3 osknockout

osknockout

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 399 posts
  • Location:Elysium
  • Interests:quantum mechanics, war, history, epidemiology, virology,mathematics, programming, D&amp;D/NetHack<br />...old skool :)

Posted 26 April 2007 - 09:58 PM

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:
  • 0

#4 hitmanblood

hitmanblood

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 788 posts
  • Gender:Male

Posted 06 May 2007 - 08:08 AM

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.
  • 0

#5 mahesh2k

mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,350 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:48.05
  • Spam Patrol

Posted 31 May 2007 - 03:54 PM

Oh i do have some graphics tutorial for beginners on my website that is hosted on computing host.at
http://onecore.net if you need some help with program plesae pm me.
  • 0

#6 osknockout

osknockout

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 399 posts
  • Location:Elysium
  • Interests:quantum mechanics, war, history, epidemiology, virology,mathematics, programming, D&amp;D/NetHack<br />...old skool :)

Posted 02 June 2007 - 03:49 PM

@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:
  • 0

#7 Blessed

Blessed

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 144 posts

Posted 03 June 2007 - 10:09 PM

Gretings

man i dont onderstand c++,
if you want a beginner to understand Your tutorials coukd you please add some comments to them
that would really help us thaks,

have a nice day :lol: bye
  • 0

#8 arza1

arza1

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 194 posts
  • Gender:Male
  • Location:Franklin, IN

Posted 03 June 2007 - 11:37 PM

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
  • 0

#9 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 04:56 AM

#include <iostream>

using namespace std;

int main()
{
cout << "Hello World!" << endl;
return 0;
}
  • 0

#10 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 04:59 AM

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,,,,,
  • 0

#11 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 05:03 AM

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.
  • 0

#12 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 05:17 AM

Hi ... i have told u the Simple programing logic...but the facit is that

:lol: hehehe

for real there is no easy way into coding
you have to know the code and you need a assembler thats all
a use MS vistual studio
  • 0

#13 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 05:17 AM

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 programming
Functions
-------------------------------------
next comes
Arrays
Pointers
structures
  • 0

#14 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 05:18 AM

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
  • 0

#15 nirmal_1288

nirmal_1288

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 08 June 2007 - 05:18 AM

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 java

So 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.
  • 0



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users