Military College of Signals
National University of Sciences
& Technology
COMPUTER PROGRAMMING, LAB
Submitted to: Maj Sarmad Idress, Lab Engr Ibtisam Anwar
Lab Report Number
02
Submission Date: 05 Mar2025
Section: BEE-61 A
Group Members:
S. No Names
1. Wania Ali
2. Rashid Aziz
3. Capt Hasnain Asghar
4. Capt Muhammad Umair Nasir
RUBRICS for Practical Implementation
Student Wania Ali Rashid Aziz Capt Hasnain Capt Umair
Name
R1 (3)
R2 (3)
R3 (3)
R4 (3)
R5 (3)
Total (15)
RUBRICS for Design presentation (Report) and viva
R1 (3)
R2 (3)
R3 (3)
R4 (3)
Total(12)
Grand Total (27)
Lab # 02
Getting Started with C++
Take a string input and print its length using string.length() or string.size(
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
// Taking string input from user
cout << "Enter a string: ";
getline(cin, input);
// Printing the length of the string using both functions
cout << "Length of the string using length(): " << input.length() << endl;
cout << "Length of the string using size(): " << input.size() << endl;
return 0;
}
Take the radius as input and calculate the perimeter using the formula P= 2 * pi * r
#include <iostream>
using namespace std;
int main() {
double radius, perimeter;
const double pi = 3.14159; // Approximate value of π
// Taking radius input from user
cout << "Enter the radius of the circle: ";
cin >> radius;
// Calculating perimeter
perimeter = 2 * pi * radius;
// Displaying the result
cout << "Perimeter of the circle: " << perimeter << endl;
return 0;}
Take the length of a cube’s side and compute its volume.
#include <iostream>
using namespace std;
int main()
{
double side, volume;
// Taking the side length as input
cout << "Enter the length of the cube's side: ";
cin >> side;
// Calculating the volume
volume = side * side * side;
// Displaying the result
cout << "Volume of the cube: " << volume << endl;
return 0;
}
Take a character input and print its ASCII value using int(ch)
#include <iostream>
using namespace std;
int main()
{
char ch;
// Taking character input from user
cout << "Enter a character: ";
cin >> ch;
// Printing ASCII value
cout << "ASCII value of '" << ch << "' is: " << int(ch) << endl;
return 0;
}
Take a lowercase character and convert it to uppercase using toupper()
#include <iostream>
#include <cctype> // For toupper()
using namespace std;
int main()
{
char lowercaseChar, uppercaseChar;
// Taking lowercase character input from the user
cout << "Enter a lowercase character: ";
cin >> lowercaseChar;
// Converting to uppercase
uppercaseChar = toupper(lowercaseChar);
// Displaying the result
cout << "Uppercase character: " << uppercaseChar << endl;
return 0;
}
Take an uppercase character and convert it to lowercase using tolower()
#include <iostream>
#include <cctype> // For tolower()
using namespace std;
int main() {
char uppercaseChar, lowercaseChar;
// Taking uppercase character input from the user
cout << "Enter an uppercase character: ";
cin >> uppercaseChar;
// Converting to lowercase
lowercaseChar = tolower(uppercaseChar);
// Displaying the result
cout << "Lowercase character: " << lowercaseChar << endl;
return 0;
}
Convert given hours into equivalent minutes and seconds.
#include <iostream>
using namespace std;
int main()
{
int hours, minutes, seconds;
// Taking input from user
cout << "Enter hours: ";
cin >> hours;
// Converting hours to minutes and seconds
minutes = hours * 60;
seconds = hours * 3600;
// Displaying the result
cout << hours << " hour(s) is equivalent to " << minutes << " minutes or " << seconds << "
seconds." << endl;
return 0;
}