Aim: Downloading and Installing VS Code, (Hello World and Calculator program)
Algorithm:
~ HELLO WORLD PRG
-
Start the program.
-
Include the necessary header for input/output (iostream).
-
Begin the main function.
-
Print "Hello World" to the screen.
-
End the main function and terminate the program.
~ CALC PRG.
-
Start the program.
-
Declare three integer variables: num1, num2, and sum (initialize sum to 0).
-
Display "Enter first number:" and take input for num1.
-
Display "Enter second number:" and take input for num2.
-
Calculate the sum of num1 and num2, and store the result in sum.
-
Display "Sum of given numbers = " followed by the value of sum.
-
End the program.
~ Theory :
• "Hello World" is printed on the screen by the provided C++ code.
• In order to perform input and output operations using cin and cout, it first includes the header.
• The program can use elements from the standard namespace without prefixing them with std:: thanks to the statement using namespace std;.
• The program's entry point is the main() function. Within it, the string "Hello World" is sent to the standard output (typically the console) by cout << "Hello World";.
• Lastly, the successful completion of the program is indicated by return 0;. Note: The code needs to be corrected for a few minor syntax errors.
• The calculator program prompts the user to enter two numbers. It uses 'cin' to receive the inputs and saves them in 'num1' and 'num2'. Then, it calculates the sum by adding these two numbers and saves the result in the variable 'sum'. Finally, it shows the sum using 'cout'.
• This program illustrates basic input, output, and arithmetic operations in C++.
~ Conclusion: Both the programs use the basic structures of a C++ program, including input, output and simple operations.