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

Ritik Kumar EXP 5 Merged AP LAB (Nemesis)

Uploaded by

kr.ankushyadav
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)
22 views10 pages

Ritik Kumar EXP 5 Merged AP LAB (Nemesis)

Uploaded by

kr.ankushyadav
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: Ankush Kumar UID: 22BCS10661
Branch: CSE Section/Group: 608/A
Semester: 5 Date of Performance: 21/08/24
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. Givena sentence
determinewhether it is a pangram in the English alphabet. Ignorecase. Returneither
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.pangramshasthefollowingparameter(s):
string s: astring 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: Ritik Kumar UID: 22BCS10767
Branch: CSE Section/Group: 608/B
Semester: 5 Date of Performance: 21/08/24
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 morewordsconsisting of English letters.
Allletters in the firstword are lowercase.
For each of thesubsequentwords, the first letter is uppercaseandrest of the letters are
lowercase.Given, determine the number of words in s
3. Objective:

Complete the camelcase function in the editor below.


camelcasehas the followingparameter(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: Ritik Kumar UID: 22BCS10767
Branch: CSE Section/Group: 608/B
Semester: 5 Date of Performance: 21/08/24
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
pagerequiredher to inputa nameanda password. However, thepasswordmust be
strong. Thewebsiteconsidersa password be strong if it satisfies thefollowingcriteria:
Its length is at least 6.
It contains at least one digit.
It contains at leastonelowercase Englishcharacter.
It contains at leastoneuppercase Englishcharacter.
It contains at leastonespecialcharacter. The special characters are: !@#$%^&*()-+

3. Objective:

Complete the minimumNumberfunction in the editor below.


minimumNumberhasthefollowingparameters:
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

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