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

EXP 5 Merged AP LAB (Nemesis)

The document outlines three programming experiments related to string manipulation in an Advanced Programming Lab. Experiment 5(A) focuses on determining if a given string is a pangram, Experiment 5(B) counts the number of words in a CamelCase string, and Experiment 5(C) checks the strength of a password based on specific criteria. Each experiment includes objectives, algorithms, implementation code, learning outcomes, and time and space complexity analyses.

Uploaded by

tusharsingh06.ts
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)
10 views10 pages

EXP 5 Merged AP LAB (Nemesis)

The document outlines three programming experiments related to string manipulation in an Advanced Programming Lab. Experiment 5(A) focuses on determining if a given string is a pangram, Experiment 5(B) counts the number of words in a CamelCase string, and Experiment 5(C) checks the strength of a password based on specific criteria. Each experiment includes objectives, algorithms, implementation code, learning outcomes, and time and space complexity analyses.

Uploaded by

tusharsingh06.ts
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/ 10

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 5(A)
Student Name: ZORO UID: 22BAI
Branch: CSE Section/Group:
Semester: 5 Date of Performance:
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314

1. Title: Pangrams

2. Aim: Pangram is a string that contains every letter of the alphabet. Given a sentence
determine whether it is a pangram in the English alphabet. Ignore case. Return either
pangram or not program as appropriate

3. Objective:

Complete the function pangrams in the editor below. It should return the string
pangram if the input string is a pangram. Otherwise, it should return not
pangram.pangrams has the following parameter(s):
string s: a string to test
It returns either pangram or not pangram

4. Algorithm:

 Initialize a boolean array of size 26 to false for tracking letter presence.

 Iterate through each character in the input string.

 Update the array at the index corresponding to the lowercase letter of each character.

 Check the boolean array to see if all entries are true.

 Return "pangram"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Implementation/Code

#include <bits/stdc++.h>
using namespace std;

string pangrams(string s) {
bool letters[26] = {false};
for (char c : s) {
if (isalpha(c)) {
letters[tolower(c) - 'a'] =
true;
}
}
for (bool present : letters) {
if (!present) {
return "not pangram";
}
}
return "pangram";
}
int main() {
string s;
getline(cin, s);
cout << pangrams(s) <<
endl;
return 0;
}
6. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

7. Learning Outcomes:

 Understand how to use boolean arrays to track the presence of


characters.
 Learn to efficiently check for the presence of all letters in a string.
Implement basic string and array operations for character counting and
validation.
8. Time Complexity: O(nl)

9. Space Complexity: O(1)


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 5(B)
Student Name: ZORO UID: 22BAI
Branch: CSE Section/Group:
Semester: 5 Date of Performance:
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314

1. Title: Pangrams

2. Aim: There is a sequence of words in CamelCase as a string of letters s, having the


following properties :
It is a concatenation of one or more words consisting of English letters.
All letters in the first word are lowercase.
For each of the subsequent words, the first letter is uppercase and rest of the letters are
lowercase.Given , determine the number of words in s
3. Objective:

Complete the camelcase function in the editor below.


camelcase has the following parameter(s):
string s: the string to analyze

4. Algorithm:

 Initialize a counter r to 1 for the first word.

 Iterate through each character in the string.

 Increment the counter r for each uppercase letter.

 Return the value of r.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Implementation/Code
#include <bits/stdc++.h>
using namespace std;

int camelcase(const string& s)


{
int r = 1;
for(int i = 0; i < s.size(); i++)
{
if (s[i] < 'a') {
r++;
}
}
return r;
}
int main() {
string s;
cin >> s;
cout << camelcase(s) <<
endl;
return 0;
}
Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
6. Learning Outcomes:

Understand how to count words in camelCase string using uppercase letters.

Learn to iterate through a string and detect specific character.

7. Time Complexity: O(n)

8. Space Complexity: O(1)


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 5(C)
Student Name: ZORO UID: 22BAI
Branch: CSE Section/Group:
Semester: 5 Date of Performance:
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314

1. Title: Strong Password

2. Aim:

Louise joined a social networking site to stay in touch with her friends. The signup
page required her to input a name and a password. However, the password must be
strong. The website considers a password be strong if it satisfies the following criteria:
Its length is at least 6.
It contains at least one digit.
It contains at least one lowercase English character.
It contains at least one uppercase English character.
It contains at least one special character. The special characters are: !@#$%^&*()-+

3. Objective:

Complete the minimumNumber function in the editor below.


minimumNumber has the following parameters:
int n: the length of the password
string password: the password to test
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Algorithm:

Initialize flags for uppercase letters, lowercase letters, digits, and special characters.

Iterate through each character in the password and set the appropriate flags.

Calculate the number of required character types by checking missing types.

Compute the number of characters to add to meet the minimum length of 6.

Return the maximum of the needed characters or the difference to reach length 6.

5. Implementation/Code

#include <bits/stdc++.h>
using namespace std;
int minimumNumber(int n,
const string& password) {
bool hasUpper = false;
bool hasLower = false;
bool hasDigit = false;
bool hasSpecial = false;

for (char c : password) {


if (isupper(c)) hasUpper =
true;
else if (islower(c))
hasLower = true;
else if (isdigit(c)) hasDigit
= true;
else if (c == '-' || c == '!' || c
== '@' || c == '#' || c == '$' ||
c == '%' || c == '^' || c == '&'
|| c == '*' || c == '(' || c == ')'
|| c == '+') {
hasSpecial = true;
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int requiredTypes = 4 -
(hasUpper + hasLower +
hasDigit + hasSpecial);
int add = max(0,
requiredTypes);
int res = n + add;
return (res >= 6) ? add : 6 -
n;
}
int main() {
int n;
cin >> n;
string password;
cin >> password;
cout << minimumNumber(n,
password) << endl;
return 0;
}

Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

6. Learning Outcomes:

Learn how to check for the presence of different char types in a password.
Understand how to determine the number of characters needed to meet
password strength criteria.
Implement logic for handling edge cases related to password length and
character requirements.

7. Time Complexity: O(n)

8. Space Complexity: O(1)

You might also like