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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2ffat

Status
Not open for further replies.

joebeach

Programmer
Sep 12, 1999
13
0
0
US
Almost there 2ffat,<br>Pass word function is now working.&nbsp;&nbsp;Some little problem.&nbsp;&nbsp;&quot;Enter the nmae and ID of the student&quot; won't compute.&nbsp;&nbsp;Somehow, the cin.getline is not picking it up.<br>#include &lt;iostream.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>float calcAverage(float[], int);<br>void display(float[], int, float);<br><br>class Password&nbsp;&nbsp;&nbsp;&nbsp;// class declaration<br>{<br> public:<br> Password(); //{ bRetVal = 0;}<br> Password(char* szPassPhase)<br>{<br> length = strlen(szPassPhase);<br> szPassword = new char[length+1];<br> strcpy(szPassword , szPassPhase );<br>}<br><br> int check(void);<br> void setPassword(char*);<br> <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>{<br> strcpy(szPassword,string);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//<br> cout &lt;&lt; szPassword &lt;&lt; endl;<br>}<br><br>int Password :: check()<br>{<br><br> while(bRetVal != 0)<br> {<br> if(HasLowercase()&&HasUpperCase()&&HasDigit()&&length &gt;= 6)<br><br><br> cout&lt;&lt;&quot;Your password is correct. Please process &quot;&lt;&lt;endl;<br><br> break;<br> }<br> if(!bRetVal)<br> {<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><br> return bRetVal;<br><br>}<br><br>int Password::HasLowercase()<br>{<br>&nbsp;&nbsp;// bRetVal =0;<br> 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> return bRetVal;<br>}<br><br>int Password::HasUpperCase()<br>{<br> bRetVal = 0;<br><br> for(int x=0; x&lt;length;x++)//returns a no-zero<br> <br> if(isupper((int)szPassword[x]))<br> {<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;char idnum[10];<br>&nbsp;&nbsp;float testGrade[50];<br>};<br><br>int main()<br>{<br>char* string =&quot;B12c34 &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><br>a.setPassword(string);<br>a.check();<br><br><br><br>Student stud;<br><br>int i=0 , ch=0, num = 0;<br>float testGrade[50];<br>float average;<br><br>average=calcAverage(testGrade, ch);<br><br><br><br><br><br>}<br><br><br>float calcAverage(float testGrade[], int HowManyGrade )<br>{<br> int&nbsp;&nbsp;&nbsp;i=0,j, id;<br> int&nbsp;&nbsp;&nbsp;HowManyStud;<br> char student[20];<br> float total=0.00, average;<br> while(testGrade)<br> {<br><br> &nbsp;&nbsp;cout&lt;&lt;&quot;How many student are you going to record &quot;;<br> &nbsp;&nbsp;cin&gt;&gt;HowManyStud;<br><br> &nbsp;&nbsp;for(i =0; i &lt;= HowManyStud; ++i)<br> {<br><br> &nbsp;&nbsp;cout&lt;&lt;&quot;Enter the names and the IDs of the student: &quot;&lt;&lt;endl;<br> &nbsp;&nbsp;cin.getline(student, 20)&nbsp;&nbsp;&nbsp;;<br><br> &nbsp;&nbsp;cout&lt;&lt;&quot;How many grade are you going to record for this student: &quot;;<br> &nbsp;&nbsp;cin&gt;&gt;HowManyGrade;<br> for( j = 0; j &lt; HowManyGrade ; ++j)<br> {<br> cout&lt;&lt;&quot;Enter another grades for the students &quot;&lt;&lt;endl;<br> cin&gt;&gt;testGrade[j];<br><br> }<br> }<br> }<br> total = total + testGrade[j];<br> average = total /HowManyGrade ; //calculate and return average<br>&nbsp;&nbsp;&nbsp;return average;<br><br><br>}<br><br>void display(float nums[], int numel, float av)<br>{<br>&nbsp;&nbsp;int i = 0;<br>&nbsp;&nbsp;cout&lt;&lt;&quot;\nThe grades are: \n&quot;;<br>&nbsp;&nbsp;for (i=0; i&lt;numel; i++)<br> &nbsp;&nbsp;{<br> if(nums<i> &lt;(av) )<br> cout&lt;&lt;&quot;*&quot;;<br> else<br> cout&lt;&lt;&quot;&nbsp;&nbsp;&quot;;<br> cout&lt;&lt;nums<i> &lt;&lt;endl;<br> }<br><br><br>&nbsp;&nbsp;return;<br>&nbsp;}<br><br><br><br>
 
Check your earlier posting, I answered pointed this out. Your password is getting set by <i>Password a = Password(string);</i> and this string is what is getting checked.<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top