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

PDF Basic Tasks!

The document provides examples of basic C++ programs to print statements, find sums, display data type sizes, convert hours to minutes, declare and assign variables, print patterns with asterisks and comments. It includes 14 tasks that each provide short code snippets to demonstrate simple C++ programs and asks the reader to fill in missing parts to complete the code for tasks like printing "Hello World", adding new lines, declaring variables, assigning and displaying values.

Uploaded by

Hira
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

PDF Basic Tasks!

The document provides examples of basic C++ programs to print statements, find sums, display data type sizes, convert hours to minutes, declare and assign variables, print patterns with asterisks and comments. It includes 14 tasks that each provide short code snippets to demonstrate simple C++ programs and asks the reader to fill in missing parts to complete the code for tasks like printing "Hello World", adding new lines, declaring variables, assigning and displaying values.

Uploaded by

Hira
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Basic C++ Programs

Task.1 Write a C++ program to print the following lines:


You are 10 years old.
You are too young to play the game (Hint use an int variable for age)
Program:
#include<iostream>
Using namespace std;

Int main()
{
Int x=10;
Cout <<”you are “<<x<<” years old\n”;
Cout <<”you are too young to play the game “
Return 0;
}

Task.2 Write a program in C++ to print the sum of two numbers.


Sample Output:
-----------------------------------
The sum of 29 and 30 is : 59
#include<iostream>
Using namespace std;
Int main()
{
Int a=2;
Int b=4;
Int sum;
Sum =a+b;
Cout <<”sum of 2 and 4 is “<<sum;
Return 0;
}

Task.3 Write a program in C++ to find Size of fundamental data types.

#Include<iostream>
Using namespace std;

Int main()
{
Int a ;
Cout <<”size of int = “<<sizeof a<<endl;

Float b ;
Cout <<”size of float = “<<sizeof b <<endl;

Char c ;
Cout <<”size of character = “<<sizeof c<<endl;

Bool d ;
Cout <<”size of bool = “<<sizeof d<<endl;
Return 0;
}

Task.4 Write a C++ program to declare an integer variable Hours and assign

it a value of your choice and Convert Hours in terms of minutes.

#include<iostream>

Using namespace std;

Int main()

Int hours =24;

Int minutes =60

Cout <<”24 hours = “<<hours*minutes<<

”minutes”;

Return 0;
}

Task. 5 Write a C++ program to declare two integers, one float variables and

assign 10, 15, and 12.6 to them respectively. It then prints these values on the

screen.

#include<iostream>

Using namespace std;

Int main()

Int a=10;

Int b=15;

Float c= 12.6;

Cout <<”value of a is “<<a<<endl;

Cout <<”value of b is “<<b<<endl;

Cout <<”value of c is “<<c<<endl;


Return 0;

Task.6 Write three C++ statements to print the asterisk pattern as shown

below.

*****
*****

#include<iostream>
Using namespace std;

Int main()
{
Cout <<”*****”<<endl;
Cout <<”*****”<<endl;
Cout <<”*****”<<endl;

Return 0;
}

Task.7 Write a program in C++ to check the upper and lower limits of
integer.

Task .8 Insert the missing part of the code below to output "Hello World!".

int main() {
<< "Hello World!";
return 0;
}
Cout
Task.9 Insert a new line after "Hello World", by using a special character:

int main() {
cout << "Hello World! ";
cout << "I am learning C++";
return 0;
}
\n
Task.10 Comments in C++ are written with special characters. Insert the missing parts:

This is a single-line comment


This is a multi-line comment

//
/*

Task. 11 Fill in the missing parts to create three variables of the same type, using a comma-
separated list:

x=5 y=6 z = 50;


cout << x + y + z;
Int _,_,
Task.12 Create a variable called z, assign x + y to it, and display the result.

int x = 5;
int y = 10;
= x + y;
cout <<
Int z; z
Task. 13 Write a program to print the following pattern:
C
i I
s s
b b
e e
s s
tsebsiCisbest
#include<iostream>
Using namespace std;

Int main()
{
Cout <<” c”<<endl;
Cout <<” I I”<<endl;
Cout <<” s s”<<endl;
Cout <<” b b”<<endl;
Cout <<” e e”<<endl;
Cout <<” s s”<<endl;
Cout <<”cisbes.sebsic”<<endl;
Return 0;
}

You might also like