Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

atjari Group Title

Can someone explain me the method of writing a C++ program?

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Vibhor16 Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    "->" is used to separate code from text .It is not used in C++(for this purpose) ->#include<iostream.h> 1)# is a pre-processor indicator 2)include is a pre processor command to "add" a file to your program. 3)<___> file name should come in pointing brackets. 4)iostream.h is the file which allows us to give output or take input. ->void main() -> { ->(body/commands/statement) -> } 1)void is a data type .It indicates that the function (main) will return nothing. other data types are int(for digits),char(for characters),float(for decimals). 2)main() is a function. generally functions are called by writing their name but main() is special is the first one to be called by the compiler itself.You can also write your own functions in C++. 3){} are also called blocks and contains the body of the function. 4)The empty space in the body is used to write commands. ->cout<<"Hi"; 1)cout<< is a keyword in iostream.h file that allows us to print output. 2)Anything to be printed comes within the " ". 3)Every C/C++ command ends with ; ->int v; v=5; 1)int is the data type for digits, 2)v is a variable.int indicates that it can hold only digits. 3)v is assigned the value 5. ->cin>>v; 1)cin>> is a keyword in iostream.h to take a value from user and store it in v. The value v can hold depends on its data type. Sample Code: ->#include<iostream.h> ->void main() -> { ->int no; ->cout<<"Enter your number : "; ->cin>>no; ->// Comments are written like this in c++ ->//coments are ignored by the compiler ->// to leave a space of a line in c++ use \n ->cout<<"\nWelcome number "<<v; -> } ALSO TRY THIS: a complete guide which will make you comfortable with theory part and understanding of C++ http://www.cplusplus.com/doc/tutorial/introduction/

    • 2 years ago
  2. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanx a lot.

    • 2 years ago
  3. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    void main? why? the C++ standard mandates that main() has an int return type (unless you're developing under some OS which cannot handle return values)

    • 2 years ago
  4. Vibhor16 Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    I prefer void over int for main though it does not makes any difference.Its just if you use int you will have to write "return 0;" at the end which is equivalent to void.I prefer int in functions with calculations but for a code such as : cout<<"Hello World"; it would make no difference in such cases.

    • 2 years ago
  5. agdgdgdgwngo Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    It's non-standard though and Stroustrup advises against it: http://www2.research.att.com/~bs/bs_faq2.html#void-main here are some more reasons: http://users.aber.ac.uk/auj/voidmain.shtml

    • 2 years ago
  6. Vibhor16 Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    OK.Good info.....

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.