0% found this document useful (0 votes)
1 views10 pages

PF Assignment 5

The document contains multiple programming tasks written in C++. Each task demonstrates different functionalities such as converting decimal to hexadecimal, creating overloaded functions, performing array addition, reversing digits of numbers, and counting words, letters, and spaces in a string. The code snippets are accompanied by prompts for user input and display results accordingly.

Uploaded by

Malik Saab
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)
1 views10 pages

PF Assignment 5

The document contains multiple programming tasks written in C++. Each task demonstrates different functionalities such as converting decimal to hexadecimal, creating overloaded functions, performing array addition, reversing digits of numbers, and counting words, letters, and spaces in a string. The code snippets are accompanied by prompts for user input and display results accordingly.

Uploaded by

Malik Saab
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/ 10

pf assignment 5

Name: Muhammad Zaid Sohail


Roll No:22F-3809
Task 1:

#include<iostream>

#include<string>

using namespace std;

int main()

int n, temp = 0;

string a = "";

char x[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };

char ans=0;

do

cout << "Enter a decimal number: ";

cin >> n;

while (n > 0)

int temp = 0;

temp = n % 16;

a = x[temp] + a;

n = n / 16;

cout << "The hexadecimal number is: " << a << endl;

} while (temp!=0);

return 0;

Result:
Task 2:

#include<iostream>

using namespace std;

void line();

void line(char);

void line(char, int);

void line(char, char, int);

int main() {

int n;

char ch, ch2;

cout << "The First line Function is" << endl;

line();

cout << "The Second line Function " << endl;

cout << "Enter charachter to be printed" << endl;

cin >> ch;

line(ch);

cout << "The second line Function " << endl;

cout << "Enter charachter to be printed" << endl;

cin >> ch;

cout << "Enter the limit" << endl;

cin >> n;

line(ch, n);

cout << "The second line Function " << endl;

cout << "Enter 1st charachter to be printed" << endl;

cin >> ch;


cout << "Enter 2nd charachter to be printed" << endl;

cin >> ch2;

cout << "Enter the limit" << endl;

cin >> n;

line(ch, ch2, n);

void line() {

for (int i = 0; i < 80; i++) {

cout << "+";

cout << endl;

void line(char ch) {

for (int i = 0; i < 80; i++) {

cout << ch;

cout << endl;

void line(char ch, int n) {

for (int i = 0; i < n; i++) {

cout << ch;

}
cout << endl;

void line(char ch, char ch2, int n) {

for (int i = 0; i < n; i++) {

cout << ch;

cout << endl;

for (int i = 0; i < n; i++) {

cout << ch2;

cout << endl;

Result:
Task 3:

#include<iostream>

#include<time.h>

#include<cstdlib>

using namespace std;

int* addition(int arr1[5], int arr2[5]);

int main()

srand(time(0));

int arr3[5], arr2[5], arr1[5];

int* p;

for (int i = 0; i < 5; i++) {

arr1[i] = rand() % 10;

arr2[i] = rand() % 10;

p = addition(arr1, arr2);

cout << "arr3" << endl;

for (int i = 0; i < 5; i++) {

cout << *(p + i) << endl;

int* addition(int arr1[5], int arr2[5]) {

static int arr3[5];

for (int i = 0; i < 5; i++) {

arr3[i] = arr1[i] + arr2[i];


}

return arr3;

Result:

Task 4:

#include<iostream>

using namespace std;

int main()

int sum = 0;

int arr1[3], rem, a = 0;

int arr2[3], b = 0;

cout << "Enter value 1: ";

cin >> a;

cout << "Enter value 2: ";

cin >> b;

for (int i = 0; i < 3; i++)

rem = a % 10;

a = a / 10;
arr1[i] = rem;

rem = 0;

for (int i = 0; i < 3; i++)

rem = b % 10;

b = b / 10;

arr2[i] = rem;

rem = 0;

for (int i = 2; i >= 0; i--)

sum = sum * 10;

sum = sum + arr1[i];

for (int i = 2; i >= 0; i--)

sum = sum * 10;

sum = sum + arr2[i];

cout << sum << endl;

}
Result:

Task 5:

#include <iostream>

#include <stdio.h>

#include <conio.h>

using namespace std;

int main()

char phrase[100];

int i;

int words = 1, letters = 0, space = 0, characters = 0;

cout << "Please enter the string \n";

gets(phrase);

for (i = 0; phrase[i] != '\0'; i++)

if (phrase[i] == ' ' || phrase[i] == '\r')

if (phrase[i] == ' ' && phrase[i - 1] != ' ' && phrase[i - 1] != '\0') {

words++;

if (phrase[i] == ' ') {

space++;

else if (phrase[i] != ' ')


{

letters++;

characters = space + letters;

cout << "total word count: " << words << endl;

cout << "total letter count: " << letters << endl;

cout << "total character count: " << characters << endl;

cout << "spaces: " << space;

return 0;

Result:

You might also like