0% found this document useful (0 votes)
26 views20 pages

PF Assignment 2

The document contains a C++ program that tests students on 100 questions to assess their knowledge. The program asks for student information upfront, checks if they are eligible based on percentage, and then prompts the student to begin the test. It loops through 100 questions, displays each question, takes the student's answer as input, checks if it is correct and keeps track of correct and incorrect answers. At the end it displays the student's progress.

Uploaded by

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

PF Assignment 2

The document contains a C++ program that tests students on 100 questions to assess their knowledge. The program asks for student information upfront, checks if they are eligible based on percentage, and then prompts the student to begin the test. It loops through 100 questions, displays each question, takes the student's answer as input, checks if it is correct and keeps track of correct and incorrect answers. At the end it displays the student's progress.

Uploaded by

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

FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY

Sindh Madressatul Islam University (SMIU) University Karachi

PROGRAMMING FUNDAMENTALS
ASSIGNMENT # 02

STUDENT NAME: MUHAMMAD YASIR ISHFAQ


STUDENT ID: BSE-23F-003
YEAR: 2023
SEMESTER: 1ST
SECTION: 1A
SPRING/FALL: FALL 2023
ANNOUNCED DATE: 09/12/2023
SUBMISSION DATE: 16/12/2023
COURSE TEACHER: MR SAJID ALI

DEPARTMENT OF SOFTWARE ENGINEERING

1
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

Q1. Write a C++ code to examine newly students after asking hundred of questions and answers using
maximum functions and modular techniques. Make a suitable format on console, ask ont to hundred
questions and every answer given by candidate code will aware to candidate, answer is correct
otherwise code will print correct answer, in the end code will display candidate progress.
SOURCE CODE:
#include<iostream>
#include<string>//For String
#include<iomanip>//For Setw
#include<cstring>//For Strcmp

using namespace std;

// Function to input student information


void inputStudentInfo(char name[], char father_name[], char std_id[], int& age,
char gender[], char grade[], float& percentage) {
// Display prompts and get input for student information
cout << setw(20) << left << "Name:";
cin.ignore(); // Ignore any previous newline characters in the input buffer
cin.getline(name, 30);
cout << setw(20) << left << "Father's Name:";
cin.getline(father_name, 30);
cout << setw(20) << left << "Student ID:";
cin.getline(std_id, 10);
cout << setw(20) << left << "Age:";
cin >> age;
cout << setw(20) << left << "Gender:";
cin >> gender;
cout << setw(20) << left << "Grade:";
cin >> grade;
cout << setw(20) << left << "Percentage:";
cin >> percentage;
cout << endl << endl;
}

// Function to check eligibility based on percentage


bool checkEligibility(float percentage) {
if (percentage >= 65) {
cout << "You are ELIGIBLE for this test!!" << endl << endl << endl;
return true;
} else {
cout << "Sorry, You are not ELIGIBLE for this test!!";
return false;
}
}

// Function to ask if the student is ready for the test

2
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

bool askReadyForTest() {
// Display a note and get input for readiness
cout << "Note:" << endl;
cout << "Are you ready for the test (Yes/No). " << endl;
char option[4];
cin.ignore();
cin.getline(option, 4);
return (strcmp(option, "Yes") == 0);
}

// Function to display question, get user's answer, and check it


void getAnswerAndCheck(int i, int& total_marks, int& correct_answers, int&
wrong_answers) {
cin.ignore(); // Ignore any previous newline characters in the input buffer
char user_ans[10000];
string Q[100] = {"What are your rights, that you fulfil?" , "What are your
responsibilities, that you fulfil?" , "Define Citizenship?" , "What is meant by
Human Rights?" , "What is meant by etiquettes?" , "Write two common etiquette?" ,
"What is the importance of freedom of speech?" , "Name the ways to promote peace?"
, "What is the National dress Of Pakistan?" , "Name any six languages spoken in
Pakistan?" , ". What is meant by Culture?" , "What are the diverse culturals
groupsliving in Pakitsan?" , "Which Languages do the people of Gilgit Baltistan
speak?" , ". Which Languages do the people of Kashmir speak?" , "What is meant by
means of communication?" , "What are the Two advantages of Internet?" , "What are
the two disadvantages of Internet?" , "Which means of communication do you use to
get educational information?" , "Why the crafts of Pakistan are most famous?" ,
"What is meant by Multicultural Society?" , "What are the advantages of
multicultural society?" , "What are the disadvantages of multicultural society?" ,
". In which region of Pakistan do you live?" , "Write some cultural
characteristics of your region?", "Which means of communication are used in
ancient time?" ,"Which means of communication do you use?" , "What is meant by
social media?" , "What is the importance of Social Media?" , "What is the role of
radio in communication?" , "What is the role of television in communication?" ,
"What is mass media?" , "Write the examples of mass media?" , "What is Monarchy?"
, "What is Democracy?" , "Write down two benefits of Democracy?" , "Why Federal
Government is needed?" , " Write down any two rights of the citizen according to
the 1973 Constitution?" , " Make a list of the powers of a Provincial Government?"
, " How do the constitution and its implementation ensures the provision of the
Basic Human Rights?" , "Describe the functions of the political parties?" , " What
is called civilization?" , "Name any three of the old civilizations?" , "To which
country did Alexander the Great belong?" , "Which two were the largest cities of
the ancient Greek?" , "How were these cities different from each other?" , "When
and where were the Olympic games started?" , "Which type of clothes were worn by
the people of ancient Greek and Rome?" , "Which is your favorite historical
personality? And why?" ,"Name some important historical personalities of
Pakistan?" , "What is meant by Two Nations Theory?" , "Who is called the founder
of this theory (idea)?" , "Who coined the name of our country, Pakistan and When?"
, "Who Established Islamia College, Peshawar?" , "What is the importance of
Islamia College, Peshawar?" , "What do you know about the Roman Architecture?" ,

3
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

"What was the Religion of the people of Gandhara Civilization?" , "What services
did Sir Syed provide to awaken the Muslims of the Sub- Continent?" , "Write points
on Begum Rana Liaqat Ali Khan's political and social services?" , "How did the
people of Khyber Pakhtoonkhwa decide for comprising in Pakistan?" , "Name the
important personalities who played vital role in the Pakistan Movement?" , "Name
the elements of a map?" , " Which are called the lines of latitude?" , " How many
lines of latitude are there?" , "How many lines of longitude are there?" ,"What is
mean by Equator?" , "What is mean by Prime Meridian?" , "Where is the mountainous
region of Pakistan located?" , "Write down the names of important desert areas of
Pakistan?", "What is called a physical region?" , "Name the important rivers
present in Balochistan Plateau?" , "What is the importance of Gawadar sea port?" ,
"What is the highest peak of Karakoram mountain?" , "What is the highest peak of
Himalayas mountain?" , "What is the highest peak of Hindu Kush mountain?" , "What
are the Important passes of Pakistan?" , "What is the largest salt mine of
Pakistan?" , "The highest peak of Koh-e-Suleman?" , "What are the Important sea-
ports of Pakistan?" , "What is the weather of Hilly areas?" ,"What is the weather
of Plain areas?" , ". Which instrument is used to measure the temperature?" ,
"What is Weather?" , "What is Climate?" , "Why there is difference of Climate in
Murree and Karachi?" , "What are the Natural Disasters?" , "Give examples of
Natural Disasters." , "What is meant by Growth Rate?" , "What is called Population
Density?" , "How can we find out Population Density?" , "How you are effected by
increasing the number of students in your class?" , "What is topographic map?" ,
"What is Road Map?" , "Why is scale used on map?" , "Name the types of scale?" ,
"What is Census?" , "What is Goods?" , "What are services?" , "What is Public
Goods?", "What is Private Goods?"};
string A[100] = {"Right to Vote, Freedom Of Speech." , "Civic duty and voting,
Jury Duty." ,"The legal right to belong to any country is called Citizenship."
,"Every human being has been gifted with some rights by the state. These right are
called human rights." , "Etiquettes are the formal manners and the rules to be a
good citizen." , "Use sidewalks when walking along the road., Listen to Parents,
Teachers and Elders carefully." , "It shapes a diversified society, It helps to
promote democracy" , "Show tolerance in daily life, Take care of others, Be honest
with all." , "Shalwar and Kameez" , "Urdu, Punjabi, Shushki, Pashto, Hindko,
Sindhi" , "Culture is the way of life language, dress, food, religious belief,
customs and traditions of the people in a society." , "Punjabi, Sindhi, Pahtoon,
Gilgit-Baltistani, Kashmiri, Balochi" , "Shushki" , "Kashmiri" , "Means of
Communication are the ways by which we transfer messages and information to
others." , "It brings information quickly, It brings people close together." ,
"Some people use internet for cybercrimes., Over use of internet is wastage of
time and money." , "Facebook, Whatsapp, Youtube, Internet" , "Ornaments of
Pakistan are very famous in the world, Sindh is famous for Sindh Cap and Ajrak." ,
"A society consisting of many different cultures is called multicultural society."
, "It can fulfill all kinds of needs of people, It increases the economy of the
country." , "It needs tolerance, It can decrease the brotherhood." , "Sindh" ,
"Languages = Sindhi and Urdu, Dress = Shalwar Kameez, Food = Biryani, Halwa Puri,
Paratha, Simple Roti, Professions = Jobs Business, Games = Hockey, Cricket,
Football" , "Pigeons, Horse Riders, Letter Writing" , "Telephone, Mobile phone,
Telivision, E-mail" , "Social media is modern mean of communication. For example
Whatsapp, Facebook, Twitter." , "It is used to broadcast information quickly, It

4
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

is easy to access and use social media." , "We listen educational and informative
programs, We listen match commentaries." , "We watch news and talks shows, We
watch matches." , "The media used to spread information and communication on a
large scale is termed as mass media." , "Newspapers and Magzines, Telvision and
Radio." , "In this system, country is ruled by kings, queens or emperors." , "In
this system, people select the government by voting." , "Opinion of the publice is
given importance. It makes policies for the betterment of general public." , "It
looks after the national economy, It runs the national administration." ,
"Protection of life and property, Provision of health and educationa Right to
vote." , "It looks after the provincial revenue, It controls the provincial
policies." , "Protection of life and property, Provision of health and educational
facilities. Right to vote, Religious independence," , "Political parties work as
per their charter, They gather the people on the basis of their charter." , "An
organized life or a society in any area is called civilization. The marks of
civilizations are trade, celebrations, architecture, life style and customs." ,
"Greek civilization, Roman civilization, Gandhara civilization" , "Alexander the
Great belonged to Greek (326 B.C)." , "Athens and Sparta" , "They fought with each
other and sometimes united to defend the Greek from the invaders." , "Olympic
games were introduced by the ancient Greek. Olympic games were started in 776 B.C
at Olympia, a city of Greek." , "People wore white togas, made from wool or
linen." , "My historical personality is Quaid-e-Azam Muhammad Ali Jinnah. He is
the founder of our beloved country, Pakistan." , "Quaid-e-Azam Muhammad Ali
Jinnah, Begum Rana Liaqat Ali Khan, Chaudary Rehmat Ali, Allama Iqbal" , "The
Hindus and the Muslims are two separate nations because both the nations differ in
their religion, history, culture and civilization. They cannot remain together" ,
"Sir Syed Ahmed Khan is known as the founder of two Nation Theory." , "Chaudary
Rehmat Ali, on 28th January, 1933" , "Sir Sahibzada Abdul Qayum established the
Islamiya College, Peshawar." , "The students of islamiya college Peshawar took
part in the Pakistan Movement and they favoured the Pakistan Resolution." , "They
were high quality engineers and architectures, They included dome-shaped and
arched structures in their buildings." , "Buddhism was the official religion of
Gandhara Civilization." , "He realized that the modern education was the key
solution for all Muslims, He warned the Muslims that the Congress was a therefore
Muslims should refrain from joining it." , "She worked with her husband, Liaqat
Ali Khan during the struggle for Pakistan, She managed the health facilities for
the refugees." , "Islamic College, Peshawar awoke the political awareness among
the Pakhtoon students and they participated in Pakistan Movement." , " Quaid-e-
Azam Muhammad Ali Jinnah, Fatima Jinnah, Sir Abdullah Haroon, Begum Abdullah
Haroon, Begum Rana Liaqat Ali Khan" , "Border, Title, Orientation Scale, Legend."
, "The imaginary lines to find the location of any area or country on globe or map
are called lines of latitude." , "There are 180 latitudes in number." ,
"Longitudes are imaginary lines drawn from North to South." , "There are 36
longitudes in number." , "The O latitude is called the Equator." , "The O
longitude is called the Prime Meridian." , "They are located in the North and
Northwest regions of Pakistan." , "Thal, Thar and Kharan" , "A physical region
have common structure of the external earth, climate, plants, civilization of the
people etc" , "Zob, Hub, Dasht, Hangol" , "It is located in Baluchistan. In
future, it will become an important economic center. It is an important part of
CPEC (China Pakistan Economic Corridor)." , "K-2" , "Nanga Purbat" , "Turch Mir" ,

5
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

"Khyber Pass, Kurram Pass, Tochi Pass, Bolan Pass" , "Khewra (District Jhelum)" ,
"Takht-e-Suleman." , "Karachi Port, Pashni Port, Bin Qasim Port, Jewani Port,
Gawadar Port" , "In hilly areas, it is very cold in winter, as it snows. In summer
the weather is moderate there." , "In plain areas the weather is moderate all the
year" , "An Thermometer." , "The atmospheric conditions at a given time and place
" , "The temporary weather conditions of a place for a short period of time." ,
"Because Murree is located at high altitude from the sea level and located in
Northern mountains. While Karachi is coastal area, so there is a difference of
climate in Murree and in Karachi." , "Natural events that cause great damage or
loss of life are called natural disasters." , "Flood, Famine Earthquake, Volcanic"
, "The annual increase in population of a country or region is called Growth
Rate." , "The number of people residing in one square kilometer of a region is
called Population Density." , "Density = Total Population / Total area of the
region" , "The teacher cannot concentrate on a large strength of the class. More
students will create a noise and disturb the class discipline." , "These maps show
important natural and cultural features such as relief, vegetation, cultivated
lands, settlements and transportation etc." , "Road maps is one of the most widely
used maps. Road maps or route maps are basically used for an navigation purposes."
, "When we draw a map of an area or a place, there is always a ratio between the
actual size on the Earth and the size on the map. In geography this ratio is
called scale." , "Linear scale, Statement Scale, Fractional Or Ratio Scale" ,
"Census is a count of the population of a country. During census, information
about people living in a country is collected." , "Goods is something that anyone
needs or wants." , "Service is an activity that someone does for us." , "The
government provides different facilities to its citizens. For example, schools,
hospitals, roads, post offices, public parks and banks etc. These are called
public goods." , "Private goods are possessed by the people. For example, House,
food, clothes, car, motor cycle etc."};

cout << i + 1 << ". " << Q[i] << endl;


cin.getline(user_ans, 10000);

if (user_ans == A[i]) {
cout << "Correct Answer!" << endl << endl;
correct_answers++;
total_marks += 1;
cout << "Marks till now: " << total_marks << endl;
} else {
cout << "Wrong Answer!" << endl << endl;
wrong_answers++;
cout << "Do you want to see the correct answer? (Yes/No): ";
char see_answer_option[4];
cin.getline(see_answer_option, 4);
if (strcmp(see_answer_option, "Yes") == 0) {
cout << "Correct Answer: " << A[i] << endl;
}
cout << "Marks till now: " << total_marks << endl;
}
}

6
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

// Function to conduct the test


void conductTest() {
int total_marks = 0;
int correct_answers = 0;
int wrong_answers = 0;

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


getAnswerAndCheck(i, total_marks, correct_answers, wrong_answers);
}

// Display results
cout << "\n=== RESULTS ===" << endl;
cout << "Total Correct Answers: " << correct_answers << endl;
cout << "Total Wrong Answers: " << wrong_answers << endl;
cout << "Total Marks: " << total_marks << endl;

// Reset total marks after the test


total_marks = 0;
}

int main() {
char name[30], father_name[30], gender[10], grade[2], std_id[10];
int age;
float percentage;

// Display header
cout << "=============== PAKISTAN STUDIES EXAM ===============" << endl <<
endl;
cout << "100 QUESTIONS OF PST (CLASS 5)" << endl;
cout << "=============== STUDENT'S BIO DATA ===============" << endl << endl;

// Get student information


inputStudentInfo(name, father_name, std_id, age, gender, grade, percentage);

// Check eligibility

if (checkEligibility(percentage)) {
// Ask if ready for the test
if (askReadyForTest()) {
cout << "Start the Test Please" << endl << endl << endl;
conductTest();
} else {
cout << "Invalid option. Test aborted." << endl;
}
}

return 0;
}

7
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

OUTPUT:

8
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

9
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

10
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

11
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

12
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

13
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

Q2. Briefly describe all given topics in term of bullets, write and implement code of each topic
using C++ high level language in IDE with every single line comment.
a) Function
1. Paremeter pass by value
• Makes a copy of actual parameter
• Passes copy of contents
• Original variable’s content DO NOT change
• How? Do nothing. Default
• Safer
SOURCE CODE:

#include<iostream>
using namespace std;
void swapThemByVal(int num1, int num2) {
int temp = num1;

14
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

num1 = num2;
num2 = temp;
}
int main() {
int i = 10, j = 20;
swapThemByVal(i, j);
cout<<endl<<endl<<endl;
cout << i << " " << j << endl; // displays 10 20
cout<<endl<<endl<<endl;
return 0;
}
OUTPUT:

2. Paremeter pass by reference


• Passes address of actual parameter
• Accesses original variable’s contents (via address)
• Original variable’s content DO change
• How? Add ampersand(&) before paremeter name in header and prototype
• More efficient
SOURCE CODE:

#include<iostream>
using namespace std;
void swapThemByRef(int& num1, int& num2) {
int temp = num1;
num1 = num2;
num2 = temp;
}
int main() {
int i = 30, j = 50;
swapThemByRef(i, j);
cout<<endl<<endl<<endl;
cout << i << " " << j << endl; // displays 20 10
cout<<endl<<endl<<endl;
return 0;
}
OUTPUT:

3. Returning Value

15
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

By definition, a value-returning function returns a single value; this value is returned via the return
statement. Use void functions with reference parameters to return (modify) more than one value.
SOURCE CODE:

#include<iostream>
using namespace std;
int myFunction(int x, int y) {
return x + y;
}

int main() {
int z = myFunction(5, 3);
cout<<endl<<endl<<endl;
cout << z;
cout<<endl<<endl<<endl;
return 0;
}
OUTPUT:

4. Function Overloading
Same name of function but there is a difference in:
• No. of arguments, Types Of Arguments

SOURCE CODE:
#include <iostream>
using namespace std;
void add(int a, int b, double c)
{
cout<<"Addition: "<<a+b+c<<endl;
}
void add(char x, double y, int z)
{
cout<<"Addition: "<<x+y+z<<endl;
}
void add(double m, int n, char o)
{
cout<<"Addition: "<<m+n+o<<endl;
}

int main(){
add(3, 'X', 5.5);
add('Y', 8.5, 4);
add(6.4, 8, 'Z');
return 0;

16
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

}
OUTPUT:

b) String
1. Cin.getline.
In C++, the cin object also allows input from the user, but not multi-word or multi-line input.
SOURCE CODE:

#include <iostream>
using namespace std;
int main() {
char input[50];
cout << "Enter a line of text: ";
cin.getline(input, 50);
cout<<"You entered: "<<input<<endl;
return 0;
}
OUTPUT:

2. Cin.get.
The cin. get() in C++ is used for accessing the character array from the user that the user provides as
the input.

SOURCE CODE:

#include <iostream>
using namespace std;
int main() {
char ch;
cout << "Enter a character: ";
ch = cin.get();
cout << "You entered: " << ch << endl;
return 0;
}
RESULT:

3. Gets.
The gets() function reads characters from stdin and stores them in str until a newline character or end of
file is found.
SOURCE CODE:

17
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

#include <iostream>
using namespace std;
int main() {
char input1[50];
char input2[50];
cout << "Enter Number 1: ";
gets(input1);
cout << "Enter Number 2: ";
gets(input2);
int num1 = atoi(input1);
int num2 = atoi(input2);
cout<<"Addition Of "<<num1<<" and "<<num2<<" is: "<<num1+num2<<endl;
return 0;
}
OUTPUT:

4. Puts.
The puts() function in C/C++ is used to write a line or string to the output( stdout ) stream
SOURCE CODE:

#include <iostream>
using namespace std;
int main() {
char input1[50];
char input2[50];
cout << "Enter Number 1: ";
gets(input1);
cout << "Enter Number 2: ";
gets(input2);
// int num1 = atoi(input1);
// int num2 = atoi(input2);
cout<<"Number 1 you entered is"<<endl;
puts(input1);
cout<<"Number 2 you entered is"<<endl;
puts(input2);
return 0;
}

RESULT:

5. Strcat.
The strcat() function concatenates string2 to string1 and ends the resulting string with the null character.

18
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

SOURCE CODE:

#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char dest[50] = "Hello, Welcome to";
char src[50] = " Dark Web";
strcat(dest, src);
cout << dest ;
return 0;
}
OUTPUT:

6. Strncmp.
strncmp() function in C++ lexicographically compares not more than count characters from the two null-
terminated strings and returns an integer based on the outcome.
SOURCE CODE:

#include <iostream>
#include <cstring>
using namespace std;
int main (){
char str1[20] = "Hello World!";
char str2[20] = "Hello";
int retval = strncmp(str1, str2, 5);
if(retval != 0)
cout<<"First 5 characters of str1 and str2 are not equal."<<endl;
else
cout<<"First 5 characters of str1 and str2 are equal"<<endl;
cout<<"Value returned by the function: "<<retval <<endl;
return 0;
}
OUTPUT:

7. Strcpy.
strcpy() is a standard library function in C++ and is used to copy one string to another.
SOURCE CODE:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
char src[] = "Welcome to Sindh Madressat-ul-Islam University.";
char dest[20];
strcpy(dest,src);

19
FACULTY OF ENGINEERING SCEINCE AND TECHNOLOGY
Sindh Madressatul Islam University (SMIU) University Karachi

cout << dest;


return 0;
}
OUTPUT:

8. Strlen.
The strlen() function determines the length of string excluding the ending null character.
SOURCE CODE:

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char song[] = "Be dili kiya yunhi din guzar jayein ge, sirf zinda rhey ham to mar
jayein ge";
cout << strlen(song);
return 0;
}
OUTPUT:

9. Strrev.
The strrev() function is a built-in function in C and is defined in string. h header file. The strrev()
function is used to reverse the given string.
SOURCE CODE:

#include <algorithm>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str = "Yasir Khanzada";
reverse(str.begin(), str.end());
cout<<"\n"<<str;
return 0;
}
OUTPUT:

20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy