Simple C++ Programs. - simple programs for beginners.

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #17) by nirmal_1288 on Jun 8 2007, 06:27 PM. (Line Breaks Removed)
Friends those who are good in c++ please help me in this problem if u have suggestions let me know it...I have two classes, call them class1 and class2. In my main(), I declare a new class object: class2 stepping_action = new class2;stepping_action has a variable called "contained" that is a boolean. What I need to do is change the value of this variable from within class1. When I try, i... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

Simple C++ Programs. - simple programs for beginners.

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

CODE
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




 

 

 


Reply

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

Reply

osknockout
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++ biggrin.gif

Reply

hitmanblood
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.

Reply

mahesh2k
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.

Reply

osknockout
@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. smile.gif

Reply

Blessed
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 biggrin.gif bye

Reply

arza1
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

Reply

nirmal_1288
#include <iostream>

using namespace std;

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

Reply

nirmal_1288
Friends smile.gif 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,,,,,

 

 

 


Reply

Latest Entries

nirmal_1288
Friends those who are good in c++ please help me in this problem if u have suggestions let me know it...


I have two classes, call them class1 and class2. In my main(), I declare a new class object:

class2 stepping_action = new class2;

stepping_action has a variable called "contained" that is a boolean.

What I need to do is change the value of this variable from within class1. When I try, it tells me that stepping_action is not in the right scope. I have tried declaring stepping_action outside of the main but I still get the same error.
How can I change this variable from class1?


Reply

nirmal_1288
Hi all,

I am working on a C++ program that converts a decimal to a fraction, finds the lowest common multiple, multiplies the numerator by the denominator, then reduces the fraction again so the fraction will be 'numerator/1'.

I am using this code in a larger program to change a floating point slope value to a whole value for slope-intercept equations and standard form equations.

The program will run but I tested almost 500 numbers and 20 numbers made the program crash (it stalled and did not finish the equation, I had to close the terminal and open it up again... )

These 20 numbers I had problems with:

2.36, 7.36, 1.11, 1.001, 1.66, 1.88, 2.22, 2.13, 3.24, 3,26, 3.32, 3.43, 3.49, 3.51, 3.57, 3.68, 3.74, 3.76, 3.82

(I am sure there are more...)

I have tried c-style casting and dynamic and static casting to try to resolve this issue. Can someone help me out and point out why these certain numbers make the program crash and offer a possible sloution?

I tried debugging this program on gdb and keep on getting this frustrating message..

(gdb) break 16
No line 16 in file "init.c".
(gdb)


Here is the program's code:

CODE


//example.cc
#include <iostream>
#include "reduce.h"
#include "decimal-to-fraction.h"
using namespace std;

int main()
{
double deci;
double n, d;

while(1) {
cout << "Enter a decimal to convert to a fraction ('0' to quit): ";
cin >> deci;
cin.ignore(INT_MAX, '\n');
if(!deci) exit(0);

dec_to_frac(deci, n, d);

if (n * d != n){
cout << '\n' << deci << " = " << n << '/' << d << "\n\n";
cout<<'\n' << d << " x " << n;
n = d * n;
cout<< " = " << n << "\n\n";
cout<<'\n' << n << '/' << d;
reduce(n, d);

cout << " = " << n << '/' << d << "\n\n";

cout<<'\n' << n << "\n\n";
}

else
cout<<'\n' << deci<< "\n\n";

}

return 0;
}

#ifndef _REDUCE_H_

#error You must include "reduce.h" before this file

#endif /* def _REDUCE_H_ */



#ifndef _DECIMAL_TO_FRACTION_H_

#define _DECIMAL_TO_FRACTION_H_



void dec_to_frac(double decimal, double &numerator, double &denominator)

{

//numerator = static_cast<int >(decimal);
//numerator = (int )decimal;
numerator = decimal;

denominator = 1;



while(numerator != (int)numerator) {

numerator *= 10;

denominator *= 10;

}

reduce(numerator, denominator);

}



#endif /* def _DECIMAL_TO_FRACTION_H_ */

#ifndef _REDUCE_H_

#define _REDUCE_H_



void reduce(double &numer, double &denom)

{

int i;



for(i=2; i<=numer; ++i) {


if( ((numer/i) == ((int )(numer/i))) && ((denom/i) == ((int)(denom/i))) ) {

numer /= i;

denom /= i;

--i;

}

}

}



#endif /* def _REDUCE_H_ */

Reply

nirmal_1288
Friends do remember this at the begginnig stage of learning C++ . this is regarding the virtual methods.When you have a virtual method, calling it will always call the most derived version of the method. You could however write a method for JSWidget like this:


JSWidget::BaseUpdate()
{
Widget::Update();
}

and then call jswidget->BaseUpdate().

Reply

nirmal_1288
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.

Reply

nirmal_1288
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. programming and "programs for beginners" - 453.40 hr back. (1)
  2. problems && programms of c - 575.79 hr back. (1)
  3. c programs for practice for beginners - 939.04 hr back. (3)
  4. c conio pixel - 1014.68 hr back. (1)
  5. simple c programs - 1015.22 hr back. (2)
Similar Topics

Keywords : simple, c, programs, simple, programms, begginers,

  1. Mouse Input In C Programs
    using checkbox etc (5)
  2. C++ Programmers
    So Post your C++ programs here (1)
    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() ....
  3. Learn C/c++ From The Beginning
    C/c++ tutorials for beginners and expert at the same time (11)
    Hello every one Today I’m going to write good c c++ tutorials The tutorials are mine showing my
    experience in c c++ i my be using some examples rote in some books (if i do i will pot a link or
    name of the book) And all the tutorials are at the main topic I don’t know how my topic count in
    this case because all I’m going to do is updates the same topic Any way lets just tray and see First
    sings first in order to compile your code you need compiler That compiler is an application that
    converts your code from human readable code to Binary cod or machine code There is all....
  4. Programs
    for games (4)
    first off i would like to announce this is my first time on here, i would like to know what kind of
    programs i need to edit my Pc games. i have been learning how to edit with just texts but i would
    like to know what i need for the text scripts i can't read? any information can help
    --thanks....
  5. Buffer Overflow In Action Tutorial
    Learn how to buffer overflow programs to change the program flow... (0)
    This tutorial will show you how to buffer overflow programs in order to change the flow of the
    application , even if this means executing your own code. A very well explained tutorial of buffer
    overflows ( not theory but practise ) + a 20 min video tutorial/demonstration + all the files needed
    for the tutorial.. Buffer Overflow In Action Tutorial LINK ....
  6. Beginners Guide To C/c++ Programming?
    (3)
    ok so I was wondering if anyone knows where I can find a good, c/c++ dummy friendly guide? my main
    reason for want to learn it so that I can make .cab files that do registry edits for ppc. I know
    this should be easy to do, Any help would be greatly appreciated. Thx in advanced, Mike....
  7. C/c++ Programming Experince
    How long does it take before programming useful programs? (3)
    I've been teaching my self C++, slowly but surely. Everything I try to program is just mediocre,
    and much simplier to use something already made. How long does it take before I can start
    programming useful decent programs?....
  8. Can't Compile Assembly Programs.
    (2)
    Hi, I'm trying to learn assembly but I can't compile any "hello world" programs... And I
    don'n know what I'm doing wrong... I downloaded NASM ,NASMW and TASM32. The program is like
    this: EXAMP1.ASM: ;title Hello World Program ; This program displays "Hello, World!"
    dosseg .model small .stack 100h .data hello_message db 'Hello,
    World!',0dh,0ah,'$' .code main proc mov ax,@data mov ds,ax
    mov ah,9 mov dx,offset hello_message int 21h mov ax,4C00h
    int 2....
  9. Dos Game Programming In C For Beginners
    (1)
    There are a number of tutorials available for the intermediate game programmer, but there are very
    few good tutorials for beginners who have never drawn a pixel on the screen. A quick search on the
    net reveals hundreds of sites devoted to 3D, polygons, texture- mapping and other advance topics,
    but the beginner has no where to get started. This tutorial is for C programmers who want to get an
    introduction to game programming. find this tutorial at Dos Game Programming in C for Beginners
    ....
  10. Simple C++ Programs
    programming C++ (13)
    what simple programs would a beginner should code in order to get some understanding the c++ along
    with leaning as well....

    1. Looking for simple, c, programs, simple, programms, begginers,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for simple, c, programs, simple, programms, begginers,

*MORE FROM TRAP17.COM*
advertisement



Simple C++ Programs. - simple programs for beginners.



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE