0% found this document useful (0 votes)
38 views

Programing Fundamental Lab Practice

Uploaded by

sheikhsahib353
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Programing Fundamental Lab Practice

Uploaded by

sheikhsahib353
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

.

Programing Fundamental Lab Practice

Explain the above code line by line


#include <iostream>
This line includes the <iostream> header file. The #include directive is used to
include the necessary C++ standard library headers. In this case, <iostream> is
included because we'll be using the input and output stream objects (e.g., cin and
cout) provided by the C++ standard library.

using namespace std;


This line includes the using namespace std; directive. It tells the compiler that we
want to use the std namespace without having to prefix objects from the std
namespace with std ::

int main() {
This line begins the main function, which is the entry point for C++ programs. The
int before main indicates that the function returns an integer value.

cout << "Hello, World!" << endl;


This line uses the cout object from the std namespace to display text on the
console. The << operator is used to insert the text "Hello, World!" into the output
stream. << endl is used to insert a newline character, which moves the cursor to the
next line after the text is displayed.

return 0;
This line is used to return an integer value (0 in this case) from the main function.
A return value of 0 typically indicates that the program executed successfully.

}
This line marks the end of the main function.
Variable Initialization Variable Declaration
Int A; int A = 10;
Memory

A A
10

Activity one
Display a right-angled triangle pattern of asterisks:
*
**
***
****
Create an inverted right-angled triangle pattern of numbers:
1
12
123
1234
Print a diamond pattern of stars:
*
***
*****
***
*
Generate a pattern of alternating numbers:
10101
01010
10101
Display a hollow square pattern of hash symbols:
#####
# #
# #
# #
#####
Create a pattern of letters:
A
BC
DEF
GHIJ
KLMNO
Print a right-angled triangle of alphabets:
A
AB
ABC
ABCD
ABCDE

Generate a staircase pattern of dollar signs:


$$$$$
$***
$$**
$$$*
$$$$

Display a pattern of numbers in a right-angled triangle:


1
22
333
4444
55555
Create a pattern of asterisks forming a pyramid:
*
***
*****
*******
*********
Assignment 1
1. Write a C++ program to display your name and a welcome
message using the "cout" statement.

2. Create a program that takes two integer inputs from the user
and displays their sum using "cout."

3. Write a C++ program that calculates the area of a rectangle.


Prompt the user for the length and width, and then display the
result using "cout."

4. Develop a program that converts a temperature in Celsius to


Fahrenheit. Prompt the user for the temperature in Celsius,
perform the conversion, and display the result using "cout."

5. Create a simple calculator program that takes two numbers


and an operator (+, -, *, /) as input and displays the result of
the operation using "cout."

6. Write a program to find the square of a given number. Prompt


the user for the input and display the square using "cout."
7. Implement a program that calculates the factorial of a positive
integer entered by the user and displays the result using
"cout."

8. Create a program that takes a character as input and displays


its ASCII value using "cout."

9. Write a program that prompts the user for their name and then
displays a personalized greeting using "cout."

10. Develop a program that simulates a simple shopping cart.


Allow the user to enter the names and prices of items, and
then display the total cost using "cout."

11. Create a program that displays the first 10 natural numbers


using "cout."

12. Write a C++ program that displays the multiplication table


of a number entered by the user using "cout."

13. Develop a program that converts a distance in kilometers to


miles and displays the result using "cout."

14. Create a simple menu-driven program that displays options


to the user and prints their choice using "cout."
15. Write a program to display a countdown from 10 to 1, each
number on a separate line using "cout."

16. Implement a program that displays the square roots of the


first 10 positive integers using "cout."

17. Create a program that calculates and displays the perimeter


of a rectangle. Prompt the user for the length and width using
"cout."

18. Write a program to display a pattern of even numbers from


2 to 20 using "cout."

19. Develop a program that displays the current date and time
using "cout."

You might also like