Skip to main content

Posts

Showing posts from May, 2015

Data Form using PHP

SOURCE CODE:- <!DOCTYPE html> <html> <style> .error{ color:red; } body { font-family:arial; } </style> <body> <form method="post" action="<?php echo ($_SERVER["PHP_SELF"]);?>"> <!-- ($_SERVER["PHP_SELF"]) will return the filename of the currently executing script.--> <?php $name = $email = $gender = $address =$dob = ""; $nameError=$genderError=$emailError=""; if ($_SERVER["REQUEST_METHOD"] == "POST") {      if (empty($_POST["name"])) {      $nameError = "Name is required"; //Error if name is empty     } else {      $name = ($_POST["name"]);      if (!preg_match("/^[a-zA-Z ]*$/",$name)) {        $nameError = "Only letters and white space allowed"; //Error if name contains characters other than letters and white space.     }     }         $dob = ($_POST["dob"]);  

Tic Tac Toe Game using C++

TIC TAC TOE GAME using C++ One player will input 'O' and the other will input 'X' to fill the grid as above in order to get 3 in a row to win the game. SOURCE CODE: #include <iostream> using namespace std; int main() {         char x,y,z,w;         char arr[3][3];         cout<<"Start!"<<endl;         for(int i=0;i<3;i++)                 for(int j=0;j<3;j++)                 {                         cin>>arr[i][j];                 }         for(int l=0;l<3;l++)         {                 x=arr[l][0];                 z=arr[0][l];                 if(x==arr[l][1])                 {                         y=arr[l][2];                         if(y==x)                         {                                 cout<<y<<" WINS"<< endl;                         }                 }                 if(z==arr[1][l])                 {      

2D Arrays and Functions-To display the player with the highest average

#include <iostream> void inputdata(int data[][3],int rowSize,int colSize); int FindWinner(int data[][3],int rowSize,int colSize); using namespace std; int main () {         int arr[4][3];         inputdata(arr,4,3);         cout<<"Player "<<FindWinner(arr,4,3)<<endl;         return 0; } void inputdata(int data[][3],int rowSize,int colSize) {         for(int i=0;i<colSize;i++)         {                 cout<<"Round "<<i+1<<endl;                 for(int j=0;j<rowSize;j++)                 {                         cout<<"\tEnter the score of Player "<<100+j<<":";                         cin>>data[j][i];                 }         } } int FindWinner(int data[][3],int rowSize,int colSize) {         int tot=0,player=0;         float avg=0,avg1=0;         for(int k=0;k<rowSize;k++)         {                 av

2D arrays

i) Create a 4 x 4 2D integer array to store marks obtained for four modules  of four students as shown below. ii) Write a function called inputData () to input the marks to the array from  the keyboard. void inputData (int data [] [4] , int rowSize, int colSize) iii) Write a function called findHighestStudent () to print the student who has taken the highest marks for the given module. int findHighestStudent (int data[] [4],int rowSize,int colSize, int moduleID) (SLIIT-IPE-2013-Final Examination-1a) Source code: #include <iostream> int findHighestStudent (int data[][4],int rowSize,int colSize,int moduleID); void inputData (int data[][4],int rowSize,int colSize); using namespace std; int main () {         int arr[4][4];         inputData(arr,4,4);         cout<<"The student who obtained highest for Module 1002: student"<<findHighestStudent(arr,4,4,1002)<<endl;         cout<<"The student who obtained highest for Modu

Functions in C++

a) Write a c++ program to display the salary details of a worker of a c mpany. Name of the employee, year joined and basic salary should be entered from the keyboard. Save  your program as abc0l.cpp b) Workers with more than 5 year experience are considered as permanent. Write a function called checkPermanent() to check whether a worker is permanent or not. Year joined should be passed as a parameter to the function and it should return true if the employee is permanent and false otherwise. bool checkPermanent(int yearJoined); (Experience = current year - year joined) c) Write a function called calcBonus() to calculate the bonus amount of a worker. Bonus  is calculated as a percentage ofthe basic salary as shown in the table float calcBonus(float basicSal); Basic Salary                 Bonus Percentage Sal < 10000                         30% 10000<= Sal < 50000            35% Sal >= 50000                       40% d) Write a function called printSalSl

Use of nested if-else in C++

Sri Lanka Army Commando Regiment has established several projects for the civil people. Following table shows the information about the projects. Project Type     Description   Registration Fee   Monthly Fee POOl                  Swimming        2000/=               1000/= P002                  Psychology       3500/=               1000/= P003                  Counseling       9000/=               1000/= P004                  Gym                1500/=                 800/= a) Write a program to allow the user to enter the project type and the status of the user (RRegistered/ New User - N). A new user needs to pay an additional registration fee. Find the total price of the whole year for the selection. You should se nested selection statements. Save your program as Prg2.cpp b) Modify your program to display an error messages; • "Invalid Project Type", if the user inputs a wr ng product type which is not available in the list. • "Invalid Status", if t

Files in C++

Write a program to keep track of the batting performance of 5 cricketers who are playing a four match one day series. a) Create the data file shown below using vi editor and save it as scores.txt 78 10 -999 30 81 13 -67 10 6 0 0 -999 -999 -999 56 -78 20 22 -90 5 Note: -999 means "did not bat" Positive number is the score the batsman scored. Eg ; 78 Other negative number is to indicate the batsman was not out Eg : - 67 means the batsman got 67 without getting out b) Write a program to do the following. Save this program as abc04.cpp i) Read the scores.txt file and find how many times the batsman played in the one day series. Write the details in to innings.txt file. Sample output Batsman           Inning 1                          3 2                          4 3                          3 4                          2 5                          4 Note: - -999 means did not bat. ii) Find how many times the batsman w