• (3 Pages)
  • +
  • 1
  • 2
  • 3

Getting Started In Microsoft Visual Studio 2008 Building basic console applications. Rate Topic: ****- 8 Votes

#1 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Posted 20 April 2008 - 11:23 AM

*
POPULAR

Getting Started in Microsoft Visual Studio 2008 Console Application Tutorial
----------By Polymath


Table of Contents:
----------Part 1: Introduction
----------Part 2: Opening, Coding, Testing, and Final Work
----------Part 3: Line-By-Line Breakdown of the C++ Code Supplied


Introduction


This Tutorial assumes that you have little-to-no knowledge of the C++ Programming Language and are using Microsoft Visual Studio as you first compiler to create a CONSOLE application. The "Help" documentation provided with the piece of software was not helpful to a non-C++ savvy programmer (me at the time), so I had to start from scratch. I couldn't find a sufficiently easy step by step tutorial for creating basic first-time applications, so I wanted to help any similarly-situated people by writing a concise, easy-to-follow, step-by-step w/screenshots tutorial. Plain and Simple.

Due to the uselessness and waste of memory of such programs as "helloworld.exe", in this tutorial we are going to create an EXTREMELY SIMPLE calculator that can add two numbers together. An added advantage of using this program for the tutorial is that it allows me to demonstrate more aspects of C++. Since this tutorial does not cover object-oriented-programming or other C++ -only functions, this could technically be considered a C tutorial, but it works for C++.

All that aside, let's begin.


Opening, Coding, Testing, and Final Work

Step 1. First, if you haven't already, download Microsoft Visual C++ Studio 2008 Express Edition for free at The Microsoft Visual Studio Downloads Page. This download may take a while to install.

Step 2. Register and Launch Microsoft Visual C++ Studio 2008 (from here-on-out I will refer to this as Visual C++). The registration process is quick and easy.

Step 3. In Visual C++, select "File Menu-->New-->Project" (as shown).
Attached Image

Step 4. In the dialog box that pops up, click on "Win32" in the side pane and select "Win32 Console Application." Make sure that the "Create Directory for Solution" box is NOT checked and leave the default path the same (as shown---You can leave the Create Directory for Solution box checked and change the default path, but for purposes of this tutorial, leave it at the settings shown)
Attached Image

Step 5. The Win32 Application Wizard will pop up (as shown). Click "Next."
Attached Image

Step 6. Make sure that the following are checked (as shown):
----------1. Under "Application type": Console Application
----------2. Under "Additional Options": Empty Project
----------Then: Press "OK"
Attached Image

Step 7. Go to the "Solution Explorer" on the left side and right-click on "AddCalc" but be sure not to right click on "Solution AddCalc (1 project)." Once you have right clicked on AddCalc select "Add-->New Item"


Step 8. In the Dialog Box that appears, on the left pane select "Visual C++" and on the top section choose "C++ file (.cpp)" and change the name to AddCalc (as shown). Press "OK".


Step 9. A blank screen will appear showing the contents of "AddCalc.cpp" (as shown in SS1). Copy and Paste the following code into this blank white area (for a line-by-line breakdown of the code, go to part 3):
// initializing C++
#include <iostream>
using namespace std;

// declaring function prototypes
float addition (float a, float b);

//main function
int main ()
{
	float x;		//
	float y;		//declares variables
	float n;		//
	int b;
	b = 1;			//sets value of b to 1
	cout << "Simple Addition Calc- First Program";		//displays info about program
	while (b==1)										//creates loop so the program runs as long as the person wants to add numbers
	{
		//following code prompts the user for 2 numbers to add and calls function addition to display results
		cout << "\n" << "Type a number to add (can also use negetive, decimals, etc.): ";
		cin >> x;
		cout << " Second number: ";
		cin >> y;
		n = addition (x,y);
		cout << "Ans: " << x << " + " << y << " = " << n << "\n";
		//following code sets b to the value the user imputs to determine if the loop is broken to end the program
		cout << "Solve another operation? (1=yes, 2=no): ";
		cin >> b;
		cout << "\n";
		if (b==2)
		cout << "Terminating application.";
	}
	//ends the main function of the code
	return 0;
	}
//following function adds the numbers
float addition (float a, float b)
{
	float c;
	c = a+b;
	return (c);
}
//END C++ CODE

Step 9. (con.) The blank area with the code in it is shown in SS2 along with the SAVE ALL button highlighted (you may wish to save your work here).
SS1:
Attached Image
SS2:
Attached Image

Step 10. Go to the Build Menu and select "Build Solution" (as shown).
Attached Image

Step 11. Your Output Screen (near the bottom of the page) should show the following (the most important being: *Build: 1 succeeded, 0 failed, 0 skipped, 0 up-to-date*):
Attached Image

Step 12. PRESS F5 on you keyboard, and a small box should pop up that is running your program that will add 2 numbers together (as shown). This is command to debug your application, which for our purposes is synonymous to testing.
Attached Image

Step 13. The Debug window should work. Assuming it does, to save your program to AddCalc.exe, first go to the drop down menu near the top of the screen which says "Debug" and change it to "Release" (as shown).
Attached Image

Step 14. Go to the Build menu and select "Rebuild" (as shown). This should give output that is SIMILAR, not the SAME as the output from Step 11.
Attached Image

Step 15. Go to Windows Explorer and go to:
"C:\Documents and Settings\your_username_here\My Documents\Visual Studio 2008\Projects\AddCalc\Release"
(as shown below) Double click on AddCalc.exe, and if it runs, you can delete the other files in this directory.
Attached Image


Line-by-Line breakdown of the AddCalc.exe code

Some notes: There are some basic things about C++ that you should know beforehand. First, in C++ all spacings are equivilant (space, tab, enter), and you can have any number of the spacings, so an enter and a space both together means the same thing as a single enter or a single space. Second, a line that has // in it has a comment in it. The comment is whatever is in that line of code after the // untill there is an enter character (this is the only case in which an enter character is not the same as a tab or a space). I will ignore all comments in this code. Finally, all lines of code should end with a semicolon.

And without further ado, let's begin. I ignored comments because the comment will be the explination aligned to the right of the line it is in.

LINE-BY-LINE

#include <iostream> // this tells c++ that we want to use the normal imput and output library NO ; REQUIRED

using namespace std; // this tells c++ that we are using the standard section of this library and the C++ language

float addition (float a, float b); //this says that after the main function we will have a seperate function "addition"

int main () //says that the next block of code is the main code to be executed.

{ //the curly brace starts the main function's block of code

float x; //declares a variable that can use numbers with decimels and negetives

float y; //declares variables that is the same as above

float n; //declares a variable, same type as x

int b; //declares a variable that can only use whole numbers

b = 1; //sets value of b to 1

cout << "Simple Addition Calc- First Program"; //displays info about program

while (b==1)
//creates loop so the program runs as long as the person wants to add numbers (when b=1)

{ //curly brace starts the loop block of code


cout << "\n" << "Type a number to add (can also use negetive, decimals, etc.): ";
// prints a newline "/n" and outputs for the user to specify a number
cin >> x; // provides imput for x after the string in the previous line.

cout << " Second number: "; // outputs "Second number: "

cin >> y; // provides imput for y after previous string

n = addition (x,y); // sets n to the value returned by addition for x and y

cout << "Ans: " << x << " + " << y << " = " << n << "\n"; // Displays answer

//following code sets b to the value the user imputs, and b is the variable for the loop above

cout << "Solve another operation? (1=yes, 2=no): "; //output

cin >> b; //imput

cout << "\n"; //Outputs new line

if (b==2) //if the user imput is 2

cout << "Terminating application."; //output

} //curly brace sends ends the loop and then it is reassesed whether or not b fits the loop to go again.

return 0; //ends the main function of the code

} //curly brace ends main function



float addition (float a, float b) //creates a function returning a decimal value
//this function requires two variables in its call of type float.

{ //starts function

float c; //creates a variable called c

c = a+b; //stores the value a+b as c

return ( c ); //c is the value given to the function call for addition

} //ends function


And thats it! the basics of c++ are very simple. For those of you who prefer a list of commands and definitions:

#include <library> --------------- says you are using commands from a library of c++ commands

using namespace [namespace] ------------- says you are using a subset of commands called namespace

cin >> variable ----------- stores user imput to variable

cout << variable/"string" << variable/"string" << ... ---------------------- outputs

varType function ([paramaters]) -----------------defines a function later in the program, or with {} creates
function commands

varType = value --------------------defines variable

while (variable==value) {}-------creates a loop that repeats as long as the variable is the same as the value

if (variable==value) [if more than one command: {}] ----------------------- runs a conditional statement

functionName ([paramaters]) --------------"calls" a function, the value of the call= the "return" of the function

return (variable)/value ------------------says what value the function should send back to its "caller"

This is only the very basics, I would suggest you go to the cplusplus.com C++ Language Tutorial for a more complete reference of the language that includes commands not used in the AddCalc.exe program and a better syntax reference. Otherwise, this should be simple egnough for learning how to use a new interface (the basis of this tutorial).

Is This A Good Question/Topic? 15
  • +

Replies To: Getting Started In Microsoft Visual Studio 2008

#2 aqshaf  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 77
  • Joined: 18-August 08

Posted 08 March 2009 - 09:36 PM

Thanks Dear Friend, for your great effort in order to learn Visual C ++,
Really I enjoyed it very much.......
Was This Post Helpful? 1
  • +
  • -

#3 farhana1279  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-March 09

Posted 24 March 2009 - 03:10 AM

Thank you very much. At first I dont know how to write a simple c++ code into the microsoft visual studio 2008 (as I left this for a long time!). The setting before we create a c++ file really help me.
Was This Post Helpful? 0
  • +
  • -

#4 <KHuFu>  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 09

Posted 19 May 2009 - 02:45 AM

thanks very useful information for beginners like myself.
Was This Post Helpful? 0
  • +
  • -

#5 arnold C  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 21-May 09

Posted 21 May 2009 - 09:42 PM

thank you very much for this tuts!, :^: :)
I hope you could bring more tuts related to Visual Studio 2008
Was This Post Helpful? 0
  • +
  • -

#6 ashrafzm77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-April 09

Posted 26 May 2009 - 02:15 PM

Thanks alot realy great effort done , thanks again :^:

and hope to find more Tutorials on C++ Data structure , with that same cute method my teacher :)
Was This Post Helpful? 0
  • +
  • -

#7 Aparna.N  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-June 09

Posted 09 June 2009 - 10:26 PM

thank you very much sir.really helpful task for new users like us.
Was This Post Helpful? 0
  • +
  • -

#8 Kunden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 09

Posted 21 July 2009 - 11:45 PM

Thxs so much!
Was This Post Helpful? 0
  • +
  • -

#9 AcroneShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-December 08

Posted 23 July 2009 - 02:30 AM

change
return 0;


to

cout << result << endl;


"endl" just means endline. Like as if you just hit enter when you are making a reply for example.
I find that it makes it easyer to read when you are running it.

Great guide by the way.

This post has been edited by AcroneShadow: 23 July 2009 - 02:31 AM

Was This Post Helpful? 0
  • +
  • -

#10 kempachi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-August 09

Posted 01 August 2009 - 06:12 AM

Im a newbe in C++. Thanks for the tutorial , its very useful for me to starting.
Was This Post Helpful? 0
  • +
  • -

#11 dlong241950  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-September 09

Posted 18 September 2009 - 11:20 PM

Bless you my friend! I enrolled in an online class at my local community college (with an excellent e-textbook - Deitel), but they don't cover the IDE that Microsoft has in C++ VS 2008! (or any other). I hadn't a clue of how to make even the simplest program work in Visual C++ MS 2008 (I am an experienced Visual Basic programmer - this is quite different!!!!). You solved that for me with this tutorial (in two minutes flat) and I will be forever greatful to you!
Was This Post Helpful? 0
  • +
  • -

#12 0pt1cKill3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-October 09

Posted 18 October 2009 - 07:01 AM

i was really helped from line by line explanation
Was This Post Helpful? 0
  • +
  • -

#13 wowelf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 24-October 09

Posted 30 October 2009 - 07:00 PM

Learning.
Was This Post Helpful? 0
  • +
  • -

#14 sanle  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 30-September 08

Posted 20 November 2009 - 07:50 PM

Thanks soooo much, in 5 minutes I had my first little program running after spending hours with other tutorials.
Was This Post Helpful? 0
  • +
  • -

#15 mary20022  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-December 09

Posted 10 December 2009 - 07:33 PM

Thank you very much for this tutorial. It was very helpfull. I'd like to ask you something more. If I want to add some libraries in which folder should I put them so that my project can link to them?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3