We have discussed different things regarding SoftwareCoding in lectures from 28-
ID: 3612257 • Letter: W
Question
We have discussed different things regarding SoftwareCoding in lectures from 28-35. Writing a maintainable code makesthe product with High Quality. Here you are given a scenario whereyou have to write a maintainable code for the givenproblem.
Scenario:
Virtual Solutions is an IT solution provider company. It has hiredyou as a Software Engineer. Your job is to write code, but at thesame it should be of High Quality. Your Team Lead has askedyou to write a very small code of user login functionality. Thecode should be of High Quality.
You are required to
a. Write correct code for the user loginin Java or C++ following the guidelines for writing code discussedin the lectures
b. Make use of Hungarian Notation forcoding purpose
Explanation / Answer
1) Login page injsp <%@ page language ="java" import="java.sql.*" %><html> <bodybgcolor="pink"> <form name="f1"method="post"> <table> <tr> <td>UserName</td> <td><inputtype="text" name="t1" ></td> </tr> <tr> <td>Password</td> <td><inputtype=""password"" name="t2"></td> </tr> <tr> <td></td> <td><input type="submit" name="b1"value="LogIn"></td> </tr> </table> <form> <body> <% Stringuser=request.getParameter("t1"); Stringpass=request.getParameter("t2"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connectioncon=DriverManager.getConnection("jdbc:odbc:mydsn", "jp","jp"); Statementst=con.createStatement(); ResultSetrs=st.executeQuery("select username,password from userlog"); while(rs.next()) { Stringusername=rs.getString(1); Stringpassword=rs.getString(2); if(user.equals(username) && pass.equals(password)) { %> <jsp:forward page="/…/LoginSuccess.jsp" /> <% } else out.println("Login Failed,Please try Againe"); %> <% } } catch(Exception e1) { } %> </form> </body> </html>
2) Use of Hungarian Notation for coding purpose Hungarian Notation and Functions : Functionsdon’t use the Hungarian notation prefixes or underscores, thefirst letter of each sub-name is capitalised and the function namebegins with a capital letter. Here are some examples:
int 2DPointSum(int ix1, int iy1, int ix2,int iy2) void *ClearBuffers(void) Hungarian Notation and Classes : All classnames are prefixed with a capital C and the first letter of eachsub-name is capitalised. class CMatrixMath { }; Hungarian Notation and Variables : The prefixcodes given in table A.1 are used extensively in the naming ofvariables. Again, as with the naming of classes and functions, eachsub-name of a variable starts with a capital letter: int*lpiTempValue; //32-bit pointer to an integer char*szString; //pointer to a 0 byte terminated string Final word on the Hungarian Notation : Acoding convention is a personal choice and many of us develop ourvery own style as we go along, the Hungarian notation is noexception. It was developed by Charles Simonyi and got adoptedbecause it worked. Also, the Hungarian notation shouldn’t beseen as the Holy Grail of programming conventions, it is just oneof the many standards out there. The only important thing withregard to a coding convention is consistency.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.