Popular Posts

Friday 5 April 2013

C++ friend functions and friend classes.

This is 1 of full programming  Example by using friend class function

#include <iostream>

using namespace std;

class CoreographMarks
{
    public:
    float points;
    float total;

    CoreographMarks()
    {
        total =30;
    }

    void setCgPoints()
    {
        cout<<"Enter Coreograph Marks   [max:30]: ";
        cin>>points;
    }

    friend class FigureSkater;

};


class ArtisticMarks
{
    public:
    float points;
    float total;

    ArtisticMarks()
    {
        total =20;
    }

    void setArtPoints()
    {
        cout<<"Enter Artistic Marks     [max:20]: ";
        cin>>points;
    }

    friend class FigureSkater;
};


class FigureSkater
{
    public:
    string name;
    int age;
    float finalpoints, cpoints, apoints, mpoint, m2point;
    CoreographMarks mark;
    ArtisticMarks mark2;

    void set_detail()
    {
        cin.clear();
        cin.ignore();
        cout << "Enter name      : ";
        getline(cin, name);
        cout << "Enter age       : ";
        cin>>age;
    }

    void calcFinalPoints()
    {
        mark.setCgPoints();
        mark2.setArtPoints();
        cpoints = (mark.points/mark.total)*100;
        apoints = (mark2.points/mark2.total)*100;
        finalpoints = ((mark.points+mark2.points)/(mark.total+mark2.total))*100;
    }

    int getAge()
    {
        return age;
    }

    string getName()
    {
        return name;
    }

    void displayScoreDetail()
    {
        cout << "Coregraphy   : "<<cpoints<<endl;
        cout << "Artistic     : "<<apoints<<endl;
        cout << "Final Score  : "<<finalpoints<<endl;
    }

};


int main()
{
    int num;
    CoreographMarks *core;
    ArtisticMarks *art;
    FigureSkater ska[100];
    cout << "Enter number of figure skaters"<<endl;
    cin>>num;

    core = new CoreographMarks[num];
    art = new ArtisticMarks[num];


    for(int i=0; i<num; i++)
    {
        cout<<"::::Setting details for figure skater::::"<<endl;
        ska[i].set_detail();
        ska[i].calcFinalPoints();
        cout <<"-------------------------------------------"<<endl;
        cout<<endl;
        cout<<"============================================"<<endl;
        cout << "Figure Skater "<<i+1<<endl;
        cout << "==========================================="<<endl;
        cout << "Name   = "<< ska[i].getName() <<endl;
        cout << "Age    = "<< ska[i].getAge() <<endl;
        cout<<endl;
        cout <<"::::Details of scoring::::"<<endl;
        cout<<endl;
        cout<<endl;
        ska[i].displayScoreDetail();
        cout<<endl;
        cout<<endl;
    }
        delete []core;
        delete []art;
    return 0;

}

Discussion of PHP programming language

Hi,

I'm new, I created this blog because I wanna share and discussion programming language to the world, I'm not a good programmer, but I would like to learn, hope by this blog can increase my programming skill and knowledge.

We all are programmer here, we know if any problem, we will Google Search to find solution, but some time those solution are too much or cannot understand. That the main point why I created this blog, we can share any programming language to share to the world.

I knew that also had a lot of this kind of blog or website, but more solution better then no solution. So, Let Share It together .

(sorry for my bad grammar)

Today I would like to share some of the php coding .......

Basic php coding ( add, delete , update and search)

Add function

if(isset($_POST["savebtn"]))
{
$subcode = $_POST["sub_code"];
$subname = $_POST["sub_name"];
$subcredit = $_POST["sub_credit_hr"];
$course = $_POST["course"];
mysql_query("insert into subject(sub_code,sub_name,sub_credit_hr,course)
values('$subcode','$subname','$subcredit','$course')");
}

Delete function

function confirmation()
{
answer = confirm("Do you want to delete this record?");
return answer;
}

</script>

</head>
<body>
<table border="1">
<tr>
<th>ID</th>
<th>SUBJECT CODE</th>
<th>SUBJECT NAME</th>
<th>SUBJECT CREADIT HOUR</th>
<th>COURSE</th>
<th>DELETE</th>
</tr>
<?php
$result = mysql_query("select * from subject");

while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row["ID"]; ?></td>
<td><?php echo $row["Sub_Code"]; ?></td>
<td><?php echo $row["Sub_Name"]; ?></td>
<td><?php echo $row["Sub_Credit_Hr"]; ?></td>
<td><?php echo $row["Course"]; ?></td>
<td><a href = "<?php echo $_SERVER['PHP_SELF'];?>?subid=<?php echo $row["ID"]; ?>" onclick="return confirmation();">Delete</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>

<?php
if(isset($_REQUEST["subid"]))
{
$subid = $_REQUEST["subid"];
mysql_query("delete from subject where ID = $subid");
header("Location: delete_subject.php");
}
?>

Update function


<?php

if (isset($_POST["updatebtn"]))
{
$aname = $_POST["aname"];
$auser = $_POST["auser"];
$apass = $_POST["apass"];

mysql_query("update admin set AD_NAME='$aname', AD_USER='$auser',AD_PASS='$apass'
where AD_ID=$aid");

header("Location: admin_dashboard.php");

}

?>

Search Function


<form name="searchfrm" action="" method="post">
<p>Subject Name : <input type="text" name="subname" /></p>
<p><input type="submit" name="searchbtn" value="Search Now!" /></p>
</form>

<?php 
if(isset($_POST["searchbtn"]))
{
$name = $_POST["subname"];
$query = mysql_query("select * from subject where Sub_Name like '%$name%'");
$numrows = mysql_num_rows($query);
if($numrows <1)
{
echo "No record found";
}
else
{
?>

<table border ="1">
<tr>
<th>ID</th>
<th>SUBJECT CODE</th>
<th>SUBJECT NAME</th>
<th>SUBJECT CREADIT HOUR</th>
<th>COURSE</th>
</tr>
<?php
while($row = mysql_fetch_assoc($query))
{
?>
<tr>
<td><?php echo $row["ID"]; ?></td>
<td><?php echo $row["Sub_Code"]; ?></td>
<td><?php echo $row["Sub_Name"]; ?></td>
<td><?php echo $row["Sub_Credit_Hr"]; ?></td>
<td><?php echo $row["Course"]; ?></td>
</tr>
<?php
}
}
}
?>
</table>

Hope can help for some of the beginner php learner especially some of the student .......

Thank you, if have any problem , please comment here ^^