Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password verifier 1

Status
Not open for further replies.

joebeach

Programmer
Sep 12, 1999
13
US
can some one help me finishing this problem.<br><br>#include &lt;iostream.h&gt;<br>#include &lt;iomanip.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;ctype.h&gt;<br><br>class Password&nbsp;&nbsp;&nbsp;&nbsp;// class declaration<br>{<br>&nbsp;&nbsp;public:<br> Password();<br> Password(char);<br> check();<br> void setPassword(char);<br>&nbsp;&nbsp;private:<br> HasUpperCase();&nbsp;&nbsp;&nbsp;//check&nbsp;&nbsp;for password<br> HasLowercase();<br> HasDigit();<br> char szPassword;<br>}<br><br>//implementation<br><br><br>Password::password()<br><br>Password::password(char szPassword)<br>{<br><br>&nbsp;&nbsp;szPassword = szPasssPhase;<br>}<br><br>Password::check()<br>{<br>&nbsp;&nbsp;while(bReturnValue != 0)<br> {<br> if((HasLowerCase()) &&<br> &nbsp;&nbsp;(HasUpperCase())&nbsp;&nbsp;&&<br> &nbsp;&nbsp;(Hasdigit())&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&&<br> &nbsp;&nbsp;(szPassword.length() &gt;=6))<br> cout&lt;&lt;&quot;Your password is correct. Please process &quot;&lt;&lt;endl;<br> }<br>&nbsp;&nbsp;while (bReturnValue =0)<br> {<br> cout&lt;&lt; &quot;Your password is incorrect.&nbsp;&nbsp;exit and try again. &quot;&lt;&lt;endl;<br> exit()<br> }<br>&nbsp;&nbsp;return bReturnValue;<br><br>}<br>Password::HasLowerCase()<br>{<br>&nbsp;int x;<br>&nbsp;bRetVal =0;<br>&nbsp;for(x=0;x&lt;=(szPassword.lenght()-1); x++0<br>&nbsp;{<br> if(islower((int)szPassword[x]))&nbsp;&nbsp;//return a non-zero value if true<br> {<br> &nbsp;&nbsp;bRetVal !=0;<br> &nbsp;&nbsp;break;<br> }<br>&nbsp;}<br><br>&nbsp;return bRetVal;<br><br>&nbsp;Password::HasUpperCase()<br>&nbsp;{<br> bRetVal = 0;<br> int x;<br><br> for (x=0;; x&lt;=(szPassword[x]))//returns a no-zero<br> &nbsp;&nbsp;{<br> if(isupper((int)szPassword[x]))<br> {<br> (bRetval !=0)<br> break;<br> }<br><br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;return bRetVal;<br> }<br><br>&nbsp;Password::HasDigit()<br>&nbsp;{<br> bRetVal =0;<br> int x;<br><br> for (x=0;x&lt;=(szPasswordl.length()-1)<br> {<br> &nbsp;&nbsp;if(isdigit((int)szPassword[x]))<br> &nbsp;&nbsp;{<br> bRetVal !=0;<br> break;<br> &nbsp;&nbsp;}<br> &nbsp;&nbsp;return bRetVa;;<br> }<br>&nbsp;int main()<br>&nbsp;{<br> Password a, b, c , d;<br> cout&lt;&lt;&quot;the password is: &quot;<br> a.Password()<br> b.Password(string):<br> c.Check();<br> d.setPassword(string;<br>&nbsp;}<br><br>I am stuck
 
I've rewritten your code please check it if it solves your problem. But you had a lot of syntax errors.<br><br>#include &lt;iostream &gt;<br>#include &lt;iomanip &gt;<br>#include &lt;string &gt;<br>//#include &lt;ctype&gt;<br>#include &lt;ctype.h&gt;<br>#include &lt;stdlib.h&gt;<br>using namespace std;<br><br>class Password&nbsp;&nbsp;&nbsp;&nbsp;// class declaration<br>{<br>public:<br> Password() { bRetVal = 0;} <br> Password(char* szPassPhase){<br> length = strlen(szPassPhase);<br> szPassword = new char[length+1];<br> strcpy(szPassword , szPassPhase );<br> }<br> int check(void);<br> void setPassword(char*);<br>private:<br> int HasUpperCase(void);&nbsp;&nbsp;&nbsp;//check&nbsp;&nbsp;for password<br> int HasLowercase(void);<br> int HasDigit(void);<br> char* szPassword;<br> int length;<br> int bRetVal;<br>};<br><br>//implementation<br><br>void Password::setPassword(char* string) {<br> strcpy(szPassword,string);<br> cout &lt;&lt; szPassword &lt;&lt; endl;<br>}<br><br>int Password :: check(){<br><br> while(bRetVal != 0){<br> if( (HasLowercase())&nbsp;&nbsp;&&<br> (HasUpperCase())&nbsp;&nbsp;&&<br> (HasDigit())&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&&<br> (length &gt;= 6))<br> cout&lt;&lt;&quot;Your password is correct. Please process &quot;&lt;&lt;endl;<br> }<br> if(!bRetVal) {<br> cout&lt;&lt; &quot;Your password is incorrect.&nbsp;&nbsp;exit and try again. &quot;&lt;&lt;endl;<br> exit(0);<br> }<br>&nbsp;&nbsp;return bRetVal;<br><br>}<br><br>int Password::HasLowercase(){<br>&nbsp;bRetVal =0;<br>&nbsp;for(int x=0;x &lt; length; x++) <br> if(islower((int)szPassword[x]))&nbsp;&nbsp;//return a non-zero value if true<br> {<br> bRetVal = 1;<br> break;<br> }<br>&nbsp;return bRetVal;<br>}<br><br>int Password::HasUpperCase() {<br> bRetVal = 0;<br> for(int x=0; x&lt;length;x++)//returns a no-zero<br> if(isupper((int)szPassword[x])){<br> bRetVal = 1;<br> break;<br> }<br> return bRetVal;<br>}<br><br>int Password::HasDigit() {<br> bRetVal =0;<br> for (int x=0;x&lt;=length;x++) <br> if(isdigit((int)szPassword[x]))&nbsp;&nbsp;{<br> bRetVal = 1;<br> break;<br> }<br> return bRetVal;<br>}<br><br><br>int main() {<br> char* string = &quot;h123&quot;;<br> Password a = Password(string) ;<br> cout&lt;&lt;&quot;the password is: &quot; &lt;&lt; endl;<br> a.check();<br> a.setPassword(string);<br> return 0;<br>}<br><br><br>
 
I got stuck in this program.&nbsp;&nbsp;I need to be able to access the program after the password is correct.&nbsp;&nbsp;Then I have to put in several student's name, student's id and their grades.&nbsp;&nbsp;I have to calculate their average grade earned. (Each students have few differents grades.)<br><br>#include &lt;iostream.h &gt;<br>#include &lt;iomanip.h &gt;<br>#include &lt;string.h &gt;<br>//#include &lt;ctype&gt;<br>#include &lt;ctype.h&gt;<br>#include &lt;stdlib.h&gt;<br>//using namespace std;<br><br>class Password&nbsp;&nbsp;&nbsp;&nbsp;// class declaration<br>{<br>public:<br>Password() { bRetVal = 0;} <br>Password(char* szPassPhase){<br>length = strlen(szPassPhase);<br>szPassword = new char[length+1];<br>strcpy(szPassword , szPassPhase );<br>}<br>int check(void);<br>void setPassword(char*);<br>private:<br>int HasUpperCase(void);&nbsp;&nbsp;&nbsp;//check&nbsp;&nbsp;for password<br>int HasLowercase(void);<br>int HasDigit(void);<br>char* szPassword;<br>int length;<br>int bRetVal;<br>};<br><br>//implementation<br><br>void Password::setPassword(char* string) {<br>strcpy(szPassword,string);<br>cout &lt;&lt; szPassword &lt;&lt; endl;<br>}<br><br>int Password :: check(){<br><br>while(bRetVal != 0){<br>if( (HasLowercase())&nbsp;&nbsp;&&<br>(HasUpperCase())&nbsp;&nbsp;&&<br>(HasDigit())&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&&<br>(length &gt;= 6))<br><br>cout&lt;&lt;&quot;Your password is correct. Please process &quot;&lt;&lt;endl;<br>break;<br>}<br>if(!bRetVal) {<br>cout&lt;&lt; &quot;Your password is incorrect.&nbsp;&nbsp;exit and try again. &quot;&lt;&lt;endl<br> &lt;&lt; &quot;Your password should be at least six characters long, &quot;&lt;&lt;endl<br> &lt;&lt; &quot;and the password should contain at least one uppercase and at least one lower case letter. &quot;&lt;&lt;endl<br> &lt;&lt; &quot;An example of the password is B12c34 &quot;&lt;&lt;endl;<br>exit(0);<br>}<br>&nbsp;&nbsp;return bRetVal;<br><br>}<br><br>int Password::HasLowercase(){<br>&nbsp;bRetVal =0;<br>&nbsp;for(int x=0;x &lt; length; x++) <br>if(islower((int)szPassword[x]))&nbsp;&nbsp;//return a non-zero value if true<br>{<br>bRetVal = 1;<br>break;<br>}<br>&nbsp;return bRetVal;<br>}<br><br>int Password::HasUpperCase() {<br>bRetVal = 0;<br>for(int x=0; x&lt;length;x++)//returns a no-zero<br>if(isupper((int)szPassword[x])){<br>bRetVal = 1;<br>break;<br>}<br>return bRetVal;<br>}<br><br>int Password::HasDigit() {<br>bRetVal =0;<br>for (int x=0;x&lt;=length;x++) <br>if(isdigit((int)szPassword[x]))&nbsp;&nbsp;{<br>bRetVal = 1;<br>break;<br>}<br>return bRetVal;<br>}<br><br>struct Student<br>{<br>&nbsp;&nbsp;char name[20];<br>&nbsp;&nbsp;int idnum[10];<br>&nbsp;&nbsp;int testGrade[];<br>}<br>void populate(Student *);<br>void possesInfo(Student *);<br>void display (Student *);<br><br><br><br><br>int main() {<br>char* string =&quot; &quot;;<br>Password a = Password(string) ;<br>cout&lt;&lt;&quot;Type in your password: &quot;;<br>cin.getline(string, 10);<br>cout&lt;&lt;&quot;the password is: &quot; &lt;&lt;string&lt;&lt; endl;<br>a.check();<br>a.setPassword(string);<br>return 0;<br>}<br><br>void populate(Student *record)<br>{<br>&nbsp;&nbsp;cout&lt;&lt; &quot;\nenter student information: &quot;;<br>&nbsp;&nbsp;cout&lt;&lt; &quot;\nStudent's name &quot;;<br>&nbsp;&nbsp;cin.getline(record-&gt;name, 10);<br>&nbsp;&nbsp;cout&lt;&lt; &quot;\nEnter the student's id unmber: &quot;;<br>&nbsp;&nbsp;cin&gt;&gt;record-&gt;idnum[10];<br>&nbsp;&nbsp;cout&lt;&lt; &quot;\nEnter The test grade &quot;;<br>&nbsp;&nbsp;cin&gt;&gt;record-&gt;testGrade[];<br><br>&nbsp;&nbsp;return;<br>}<br><br>void prossesInfo(Student *record)<br>{<br> int count;<br>&nbsp;&nbsp;&nbsp;float total, num, average;<br> cout &lt;&lt; &quot;Enter the name of the student: &quot;<br> cin.getline((record-&gt;name, 10);<br><br> for ( count = 0; count &lt; record-&gt;testGrade; count++)<br> {<br> count &lt;&lt;&quot;Enter a grade of this student: &quot;;<br> <br><br><br><br>can you help?<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top