I have this project where we have to take a rule off of this website https://uic.edu/apps/strong-password/ and calculate the number of points for each Column and we have to do the first 5 of each section. I was able to do the number of characters one pretty easily but I was wondering if somebody could give me advice on how to do the one for uppercase letters. The code I have done so far is done below.
#include <iostream>
#include <string>
usingnamespace std;
class Validatestring
{
public:
string password;
int rate;
int count;
int bonus;
virtualint GetCount() = 0;
virtualvoid CalculateRate() = 0;
};
class myabstractclass
{
public:
string password;
myabstractclass() {};
void setpassword(string s) { password = s; };
};
class NumberOfCharacters : public Validatestring
{
public:
int GetCount();
void CalculateRate();
};
int NumberOfCharacters::GetCount()
{
return password.length();
}
void NumberOfCharacters::CalculateRate()
{
bonus = GetCount() * 4;
}
class UpperCase : public myabstractclass
{
public:
int GetUpperCase()
{
int counter = 0;
for (int i = 0; i < password.length(); i++)
if (isupper(password[i]))
counter++;
return counter;
}
int GetUpperBonus()
{
int x = GetUpperCase();
return ((password.length() - x) * 2);
}
};
class LowerCase : public myabstractclass
{
public:
int GetLowerCase()
{
int counter = 0;
for (int i = 0; i < password.length(); i++)
if (islower(password[i]))
counter++;
return counter;
}
int GetLowerBonus()
{
int x = GetLowerCase();
return ((password.length() - x) * 2);
}
};
class Numbers : public myabstractclass
{
public:
int GetNumbers()
{
int counter = 0;
for (int i = 0; i < password.length(); i++)
if (isdigit(password[i]))
counter++;
return counter;
}
int GetNumberBonus()
{
int x = GetNumbers();
return (x * 4);
}
};
class Symbols : public myabstractclass
{
public:
int GetSymbols()
{
int counter = 0;
for (int i = 0; i < password.length(); i++)
if (ispunct(password[i]))
counter++;
return counter;
}
int GetSymbolBonus()
{
int x = GetSymbols();
return (x * 6);
}
};
I tried your recommendation by doing the code below, but it's still not quite coming out quite right. I got -2 instead of 0. Any recommendations or solutions? Do y'all think I need an if else statement?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class LettersOnly : public myabstractclass
{
public:
size_t GetLettersOnly() {
size_t counter{};
for (constunsignedchar ch : password)
counter += isupper(ch);
return counter;
}
int GetLettersOnlyBonus()
{
int x = GetLettersOnly();
return -(x);
}
};