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

Pages: 1, 2
free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

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

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

Reply

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

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

Reply

nirmal_1288
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

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

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



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" - 433.00 hr back. (1)
  2. problems && programms of c - 555.39 hr back. (1)
  3. c programs for practice for beginners - 918.64 hr back. (3)
  4. c conio pixel - 994.28 hr back. (1)
  5. simple c programs - 994.81 hr back. (2)
Similar Topics

Keywords : programs programs beginners

  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. 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...
  5. 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...
  6. 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 ...
  7. 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
    ...
  8. 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?...
  9. 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...
  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...



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