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!

ssignh

Status
Not open for further replies.

joebeach

Programmer
Sep 12, 1999
13
US
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