new student
05-23-2007, 04:37 PM
السلام عليكم و رحمة الله و بركاته
ارجو ممن لديه الخبرة في لغة البرمجة php..ان يساعدني في كتابة هذا الكود
الكود هو عبارة عن صفحتين..الأولى هي الفورم و هي عبارة عن اختبار مكتوب بلغة ال htmlو الثاني هو التصحيح للامتحان مكتوب بلغة ال php...اجبت على المسألة بطريقتي و لكن المطلوب الآن هو حلها بطريقة اخرى وفق شروط معينة...الشروط مكتوبة في ملف ال php
..لكن المشكلة اني لا استطيع ارفاق الملف...:smailes7:
كود ملف الاختبار "html"..:
<html>
<h1>PHP Quiz</h1>
<p>Answer all of the questions on the quiz, then select the Score button to grade the quiz. </p>
<form action="phpquiz.php" method="get">
<h3>A.Select the right answer</h3>
<p><b>1. Which element is required in the <head> element?</b></p>
<p>
a.<input type="radio" name="question1" value="a" /><hr> <br />
b.<input type="radio" name="question1" value="b" /><meta> <br />
c.<input type="radio" name="question1" value="c" /><body><br />
d.<input type="radio" name="question1" value="d" /><title> <br />
</p>
<p><b>2. The host portion of a URL is usually_____________________.</b></p>
<p>
a.<input type="radio" name="question2" value="a" />web <br />
b.<input type="radio" name="question2" value="b" />ftp <br />
c.<input type="radio" name="question2" value="c" />http <br />
d.<input type="radio" name="question2" value="d" />www <br />
</p>
<p><b>3. The final part of a domain name, known as the _____________________, identifies the type of institution or organization.</b></p>
<p>
a.<input type="radio" name="question3" value="a" />domain<br />
b.<input type="radio" name="question3" value="b" />domain identifier <br />
c.<input type="radio" name="question3" value="c" />protocol <br />
d.<input type="radio" name="question3" value="d" />IP address <br />
</p>
<p><b>4. Domain names are stored in a master database that is maintained by ___________________.</b></p>
<p>
a.<input type="radio" name="question4" value="a" />Microsoft<br />
b.<input type="radio" name="question4" value="b" />Higher Colleges of Technology<br />
c.<input type="radio" name="question4" value="c" />the W3C<br />
d.<input type="radio" name="question4" value="d" />InterNIC<br />
</p>
<p><b>5. Which of the following belongs in the first line of an XHTML ********? </b></p>
<p>
a.<input type="radio" name="question5" value="a" /><html><br />
b.<input type="radio" name="question5" value="b" /><xhtml><br />
c.<input type="radio" name="question5" value="c" /><title><br />
d.<input type="radio" name="question5" value="d" /><!DOCTYPE><br />
</p>
<h3>B.True/False</h3>
<p><b>1. The file used for configuring PHP is called httpd.conf</b></p>
<p>
a.<input type="radio" name="question6" value="a" />True<br />
b.<input type="radio" name="question6" value="b" />False<br />
</p>
<p><b>2. The information contained within an element's opening and closing tags is referred to as its attribute</b></p>
<p>
a.<input type="radio" name="question7" value="a" />True<br />
b.<input type="radio" name="question7" value="b" />False<br />
</p>
<p><b>3. A system consisting of a client and a server is known as a two-tier system</b></p>
<p>
a.<input type="radio" name="question8" value="a" />True<br />
b.<input type="radio" name="question8" value="b" />False<br />
</p>
<p><b>4. The port number that is reserved for HTTP communications is 8080</b></p>
<p>
a.<input type="radio" name="question9" value="a" />True<br />
b.<input type="radio" name="question9" value="b" />False<br />
</p>
<p><b>5. To separate multiple arguments that are passed to a function you should use a comma</b></p>
<p>
a.<input type="radio" name="question10" value="a" />True<br />
b.<input type="radio" name="question10" value="b" />False<br />
</p>
<p><input type="submit" value="Score" /></p>
</form>
</body>
</html>
كود ملف التصحيح .."php"..:
<?php
<h1> Quiz Results </h1>
/************************************************** ***************
* redo the "ScoreQuiz" php file with the following requirements:
* Replace the 10 "scoring" functions with only 1. That is, there
should only be one function to do the scoring of all questions.
* In order to do so, one way would be would be to use arrays for
question "names" and correct answers, which will be passed to
the function.
* Call the function n times using a loop, where n is the number
of questions.
* There should still be only 1 "GET" per question.
* Upon displaying the result, give the user an option to "retake"
the quiz.
************************************************** ***************/
$total_score = 0;
//defining functions
function scoreQuestion1() {
echo "<p>Question 1: ", $_GET["question1"];
if ($_GET["question1"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question1"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question1"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (correct)</font></p>";}
}
function scoreQuestion2() {
echo "<p>Question 2: ", $_GET["question2"];
if ($_GET["question2"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question2"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question2"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion3() {
echo "<p>Question 3: ", $_GET["question3"];
if ($_GET["question3"] == "a")
{echo " <font color=#FF0000>(Incorrect)</font></p>";}
else if ($_GET["question3"] == "b")
{echo "<font color=#008080> (Correct)</font></p>";}
else if ($_GET["question3"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
function scoreQuestion4() {
echo "<p>Question 4: ", $_GET["question4"];
if ($_GET["question4"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>"; }
else if ($_GET["question4"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question4"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion5() {
echo "<p>Question 5: ", $_GET["question5"];
if ($_GET["question5"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question5"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question5"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion6() {
echo "<p>Question 6: ", $_GET["question6"];
if ($_GET["question6"] == "a")
{echo "<font color=#008080> (Correct)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
function scoreQuestion7() {
echo "<p>Question 7: ", $_GET["question7"];
if ($_GET["question7"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion8() {
echo "<p>Question 8: ", $_GET["question8"];
if ($_GET["question8"] == "a")
{echo " <font color=#008080>(Correct)</font></p>";}
else {echo " <font color=#FF0000>(Incorrect)</font></p>";}
}
function scoreQuestion9() {
echo "<p>Question 9: ", $_GET["question9"];
if ($_GET["question9"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion10() {
echo "<p>Question 10: ", $_GET["question10"];
if ($_GET["question10"] == "a")
{echo "<font color=#008080> (Correct)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
//calculating the score
if ($_GET["question1"] == "d")
{$total_score++;}
if ($_GET["question2"] == "d")
{$total_score++;}
if ($_GET["question3"] == "b")
{$total_score++;}
if ($_GET["question4"] == "d")
{$total_score++;}
if ($_GET["question5"] == "d")
{$total_score++;}
if ($_GET["question6"] == "a")
{$total_score++;}
if ($_GET["question7"] == "b")
{$total_score++;}
if ($_GET["question8"] == "a")
{$total_score++;}
if ($_GET["question9"] == "b")
{ $total_score++;}
if ($_GET["question10"] == "a")
{$total_score++;}
//calling functions
echo " <b>Multiple choice answers:</b></br>";
scoreQuestion1();
scoreQuestion2();
scoreQuestion3();
scoreQuestion4();
scoreQuestion5();
echo "</br></br>";
echo " <b>True/False answers:</b>";
scoreQuestion6();
scoreQuestion7();
scoreQuestion8();
scoreQuestion9();
scoreQuestion10();
echo "</br></br>";
echo " <b>Total score is $total_score out of 10</b></br>";
if ($total_score == "10")
{echo "<b><h3>Well Done (^-^)</h3></b>";}
else if ($total_score >6 & $total_score < 10 )
{echo "<b><h3>You have to be proud of your self (*-*)</h3></b>";}
else {echo "<b><h3>Try again (-_-)</h3></b>";}
?>
ارجو ممن لديه الخبرة في لغة البرمجة php..ان يساعدني في كتابة هذا الكود
الكود هو عبارة عن صفحتين..الأولى هي الفورم و هي عبارة عن اختبار مكتوب بلغة ال htmlو الثاني هو التصحيح للامتحان مكتوب بلغة ال php...اجبت على المسألة بطريقتي و لكن المطلوب الآن هو حلها بطريقة اخرى وفق شروط معينة...الشروط مكتوبة في ملف ال php
..لكن المشكلة اني لا استطيع ارفاق الملف...:smailes7:
كود ملف الاختبار "html"..:
<html>
<h1>PHP Quiz</h1>
<p>Answer all of the questions on the quiz, then select the Score button to grade the quiz. </p>
<form action="phpquiz.php" method="get">
<h3>A.Select the right answer</h3>
<p><b>1. Which element is required in the <head> element?</b></p>
<p>
a.<input type="radio" name="question1" value="a" /><hr> <br />
b.<input type="radio" name="question1" value="b" /><meta> <br />
c.<input type="radio" name="question1" value="c" /><body><br />
d.<input type="radio" name="question1" value="d" /><title> <br />
</p>
<p><b>2. The host portion of a URL is usually_____________________.</b></p>
<p>
a.<input type="radio" name="question2" value="a" />web <br />
b.<input type="radio" name="question2" value="b" />ftp <br />
c.<input type="radio" name="question2" value="c" />http <br />
d.<input type="radio" name="question2" value="d" />www <br />
</p>
<p><b>3. The final part of a domain name, known as the _____________________, identifies the type of institution or organization.</b></p>
<p>
a.<input type="radio" name="question3" value="a" />domain<br />
b.<input type="radio" name="question3" value="b" />domain identifier <br />
c.<input type="radio" name="question3" value="c" />protocol <br />
d.<input type="radio" name="question3" value="d" />IP address <br />
</p>
<p><b>4. Domain names are stored in a master database that is maintained by ___________________.</b></p>
<p>
a.<input type="radio" name="question4" value="a" />Microsoft<br />
b.<input type="radio" name="question4" value="b" />Higher Colleges of Technology<br />
c.<input type="radio" name="question4" value="c" />the W3C<br />
d.<input type="radio" name="question4" value="d" />InterNIC<br />
</p>
<p><b>5. Which of the following belongs in the first line of an XHTML ********? </b></p>
<p>
a.<input type="radio" name="question5" value="a" /><html><br />
b.<input type="radio" name="question5" value="b" /><xhtml><br />
c.<input type="radio" name="question5" value="c" /><title><br />
d.<input type="radio" name="question5" value="d" /><!DOCTYPE><br />
</p>
<h3>B.True/False</h3>
<p><b>1. The file used for configuring PHP is called httpd.conf</b></p>
<p>
a.<input type="radio" name="question6" value="a" />True<br />
b.<input type="radio" name="question6" value="b" />False<br />
</p>
<p><b>2. The information contained within an element's opening and closing tags is referred to as its attribute</b></p>
<p>
a.<input type="radio" name="question7" value="a" />True<br />
b.<input type="radio" name="question7" value="b" />False<br />
</p>
<p><b>3. A system consisting of a client and a server is known as a two-tier system</b></p>
<p>
a.<input type="radio" name="question8" value="a" />True<br />
b.<input type="radio" name="question8" value="b" />False<br />
</p>
<p><b>4. The port number that is reserved for HTTP communications is 8080</b></p>
<p>
a.<input type="radio" name="question9" value="a" />True<br />
b.<input type="radio" name="question9" value="b" />False<br />
</p>
<p><b>5. To separate multiple arguments that are passed to a function you should use a comma</b></p>
<p>
a.<input type="radio" name="question10" value="a" />True<br />
b.<input type="radio" name="question10" value="b" />False<br />
</p>
<p><input type="submit" value="Score" /></p>
</form>
</body>
</html>
كود ملف التصحيح .."php"..:
<?php
<h1> Quiz Results </h1>
/************************************************** ***************
* redo the "ScoreQuiz" php file with the following requirements:
* Replace the 10 "scoring" functions with only 1. That is, there
should only be one function to do the scoring of all questions.
* In order to do so, one way would be would be to use arrays for
question "names" and correct answers, which will be passed to
the function.
* Call the function n times using a loop, where n is the number
of questions.
* There should still be only 1 "GET" per question.
* Upon displaying the result, give the user an option to "retake"
the quiz.
************************************************** ***************/
$total_score = 0;
//defining functions
function scoreQuestion1() {
echo "<p>Question 1: ", $_GET["question1"];
if ($_GET["question1"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question1"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question1"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (correct)</font></p>";}
}
function scoreQuestion2() {
echo "<p>Question 2: ", $_GET["question2"];
if ($_GET["question2"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question2"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question2"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion3() {
echo "<p>Question 3: ", $_GET["question3"];
if ($_GET["question3"] == "a")
{echo " <font color=#FF0000>(Incorrect)</font></p>";}
else if ($_GET["question3"] == "b")
{echo "<font color=#008080> (Correct)</font></p>";}
else if ($_GET["question3"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
function scoreQuestion4() {
echo "<p>Question 4: ", $_GET["question4"];
if ($_GET["question4"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>"; }
else if ($_GET["question4"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question4"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion5() {
echo "<p>Question 5: ", $_GET["question5"];
if ($_GET["question5"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question5"] == "b")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else if ($_GET["question5"] == "c")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion6() {
echo "<p>Question 6: ", $_GET["question6"];
if ($_GET["question6"] == "a")
{echo "<font color=#008080> (Correct)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
function scoreQuestion7() {
echo "<p>Question 7: ", $_GET["question7"];
if ($_GET["question7"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion8() {
echo "<p>Question 8: ", $_GET["question8"];
if ($_GET["question8"] == "a")
{echo " <font color=#008080>(Correct)</font></p>";}
else {echo " <font color=#FF0000>(Incorrect)</font></p>";}
}
function scoreQuestion9() {
echo "<p>Question 9: ", $_GET["question9"];
if ($_GET["question9"] == "a")
{echo "<font color=#FF0000> (Incorrect)</font></p>";}
else {echo "<font color=#008080> (Correct)</font></p>";}
}
function scoreQuestion10() {
echo "<p>Question 10: ", $_GET["question10"];
if ($_GET["question10"] == "a")
{echo "<font color=#008080> (Correct)</font></p>";}
else {echo "<font color=#FF0000> (Incorrect)</font></p>";}
}
//calculating the score
if ($_GET["question1"] == "d")
{$total_score++;}
if ($_GET["question2"] == "d")
{$total_score++;}
if ($_GET["question3"] == "b")
{$total_score++;}
if ($_GET["question4"] == "d")
{$total_score++;}
if ($_GET["question5"] == "d")
{$total_score++;}
if ($_GET["question6"] == "a")
{$total_score++;}
if ($_GET["question7"] == "b")
{$total_score++;}
if ($_GET["question8"] == "a")
{$total_score++;}
if ($_GET["question9"] == "b")
{ $total_score++;}
if ($_GET["question10"] == "a")
{$total_score++;}
//calling functions
echo " <b>Multiple choice answers:</b></br>";
scoreQuestion1();
scoreQuestion2();
scoreQuestion3();
scoreQuestion4();
scoreQuestion5();
echo "</br></br>";
echo " <b>True/False answers:</b>";
scoreQuestion6();
scoreQuestion7();
scoreQuestion8();
scoreQuestion9();
scoreQuestion10();
echo "</br></br>";
echo " <b>Total score is $total_score out of 10</b></br>";
if ($total_score == "10")
{echo "<b><h3>Well Done (^-^)</h3></b>";}
else if ($total_score >6 & $total_score < 10 )
{echo "<b><h3>You have to be proud of your self (*-*)</h3></b>";}
else {echo "<b><h3>Try again (-_-)</h3></b>";}
?>
