Computer Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Submitted by: Submitted to:

Nepali: Sabin Giri Bikas Parajuli


Roll no. :28 Department Of Computer
Class: XII(S4)
Faculty: Science
1. Insert values into student table withfield names using insert command. You
have to add 4 to 5 records in table student-detail , students ,marksheet,
employee.
 INSERT INTO student (detail , marksheet, employee) VALUES (Sabin, 670, engineer);
INSERT INTO student (detail , marksheet, employee) VALUES (sandeep,657,doctor);
INSERT INTO student (detail , marksheet, employee) VALUES (dhirendra,650,manager);
INSERT INTO student (detail , marksheet, employee) VALUES (sagar, 548, civil-engineer);
INSERT INTO student (detail , marksheet, employee) VALUES (Shiva, 460, conductor);

2. Display the table student using select command. you should display all
records from above table: student_detail, student_marksheet, employee.
 CRETE TABLE address(detail , marksheet, employee) ;
INSERT INTO student VALUES (sabin, 670, engineer);

3. Update student address in student_detail table using update command.


 UPDATE student
SET detail=’dharme’ where detail=’shiva’;

4. Create a MySQL Database Using MySQLi


The following example creates a database named “myDB”
 <?PHP
$servername=”localhost”;
$username=”root”;
$password=””;
// create connection
$con=new mysqli($servername, $username, $password);
//check connection
if($conn->connect_error)
{
die(“connection failed:”.mysqli_connect_error());
}
else{
echo”yes connected”; }
// create db
$sql=”CREATE DAABASE myDB”;
if($conn->query($sql===TRUE)
{ echo”database created successfully”;
} else
{ echo “Error creatring database:”.$conn->error; }
$conn->close();
?>
5. Create a MySQL Table using MySQLi
 <? php
$servername=”localhost”;
$username=”root”;
$password=””;
$dbname=””myDB”;
$con=new mysqli($servername, $username, $password); //create connection
if($conn->connect_error) //check connection
{
die(“connection failed:”.mysqli_connect_error());
}
else{
echo”yes connected”; }
//create table
$sql=”CREATE TABLE student(roll int,firstname varchar(50), lastname varchar(40), class int)”;
if(conn->query($sql)===TRUE)
{echo(“table created successfully”);
}
else{echo”Error creating table:”.$conn->error;
}
$conn->close();
?>

6. Insert Data into mysql using Mysqli.


 <? php
$servername=”localhost”;
$username=”root”;
$password=””;
$dbname=””myDB”;
$con=new mysqli($servername, $username, $password);//create connection
if($conn->connect_error) // check connection
{ die(“connection failed:”.mysqli_connect_error());
}
else{
echo”yes connected”; }
//sql to insert data in a table
$sql=”INSERT INTO student (roll, firstname, lastname, clas)
VALUES(2,’shyam’,’kumar’, 12)”;
if ($conn->query($sql===TRUE){
echo”inserted data successfully”;
}
else{
echo”Error insertingdata;”.conn->error; }
$conn->close();
?>

7. Displaying queries in tables


 <!docktype.html
<html>
<head>
</head>
<body>
<? php
$servername=”localhost”;
$username=”root”;
$password=””;
$dbname=””myDB”;
$con=new mysqli($servername, $username, $password);//create connection
if($conn->connect_error) //check connection
{
die(“connection failed:”.mysqli_connect_error());
}
$sql=”SELECT roll, firstname, lastname, class FROM student”;
$result=”$conn->query($sql);
if($result->num_rows0){
echo”<table><tr><th>Roll</th><th>name</th><th>class</th></tr>”;
while($row=$result->fetch_assoc()){
echo”<tr><td>”.$row[“roll”].”</td><td>”.$row[“firstname].””.$row[“lastname”].”</td><td>”.
$row[“class”].”</td></tr>”; }
echo”</table>”;
else
{
echo”0 results”;
}
$conn->close();
?>
</body>
</html>

8. Design a small webpage that contents at least five fields of form. Validate the user’s data using form
validation techniques of java script.
<doctype.html>
<html>
<head><title>
form validation</title></head>
<body>
<form action=”” method=”” values=”” onsubmit=”return(validate())”>
fullname<br>
<input type=”text” placeholder=”fullname” name=”fullname” id=”name” value=””/><br>
password<br>
<input type=”password” placeholder=”password” name=”password” id=”passcode” value=””/><br>
email<br>
<input type=”email” placeholder=”email” name=”email” id=”email” value=””/><br>
age<br>
<input type=”text” placeholder=”age” name=”enter your age” id=”age” value=””/><br>
gender<br>
<select><option=”male”>male</option>
<option=”female”>female</opotion>
</select>
<button type=”button”>submit</button>
</form>
<script type=”text/javascript>
function validate()
{
var fn=document.getElementBYId(“name”)
var pw=document.getElementById(“passcode”)
var a==document.getElementById(“age”)
if (fn.value==””)
{
alert(“fullname must not be empty”)
return false;
}
else if (is NaN(“a.value”))
{
alert(“age must be number “);
return false;
}
else if(pw.value.length<6)
{
alert(“password must have length more than 6”);
return false;
}
}
</script>
</body>
</html>
C PROGRAMMING

1. write a program to enter elements for 2*2 matrix and display their transpose.
#include <stdio.h>
void transpose(int m[][2];
int main() {
int m[2][2];
int i, j;
printf("Enter the elements of a 2x2 matrix:\n");
for(i=0; i<2; i++) {
for(j=0; j<2; j++) {
scanf("%d", &m [i][j]);
}
}
transpose(m);
}
void transpose(int m[][2])
{
int i,j;
printf("The output for 2*2 matrix is:\n");
for(i=0; i<2; i++) {
for(j=0; j<2; j++) {
printf("%d ", matrix[j][i]);
}
printf("\n");
}
}

// Display the transpose of the matrix


printf("The transpose of the matrix is:\n");
for(i=0; i<2; i++) {
for(j=0; j<2; j++) {
printf("%d ", matrix[j][i]);
}
printf("\n");
}
}

2. write a program to calculate and display sum of two matrices with respective size 3*3
 #include <stdio.h>
void Matrix(int x[][3], int y[][3]);
void main() {
int x[][3],y[][3],i,j;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{ printf(“\n Enter number for matrix:”);
scanf(“%d”,&x[i][j]);
}
}
for(i=0;i<3;i++)
{
for (j=0;j<3;j++)
{ printd (“\nEnter number for secoond matrix:”);
scanf(“%d”,&y[i][j]);
}
}
sum(x,y);
}
void sumu(int x[][3],int y[][3])
{ int sum[3][3],i,j;
for(i=0;i<3;i++)
{ for (j=0;j<3;j++)
{ sum[i][j]=x[i][j]+y[i][j];
printf(“%d”, sum[i][j];
}
printf(“\n”);
}
}

3. Write a program find sum and average of n numbers using array and function.
 #include <stdio.h>
void sum and average(float arr[], int n, float *sum, float *avg) {
*sum = 0;
for (int i = 0; i < n; i++) {
* sum += arr[i];
}
*avg = *sum / n;
}
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
float numbers[n];
for (int i = 0; i < n; i++) {
printf("Enter number %d: ", i+1);
scanf("%f", &numbers[i]);
}
float sum, avg;
sum_and_average(numbers, n, &sum, &avg);
printf("Sum = %f\n", sum);
printf("Average = %f\n", avg);
}
// copied
4. write a program to print greatest number among n numbers using array function.
 #include<stdio.h>
int max(int a[], int n);
void main()
{
int a[100],n,i;
printf(“\n enter number of item”);
scanf(“%d”,&n);
for(i=0;i,n;i++)
{ printf(“\n enter number”);
scanf(“%d”,&a[i]);
}
printf(“\nthe greastest number is %d”max(a,n));
}
int max(int a[], int n)
{
int m=a[0],i;
for(i=0;i,n;i++){
if(a[i]>m)
m=a[i];
}
return(m);
}

5. write a program that reads names and address of different students and rearrange them
in the basis of alphabetical order.
 #include<stdio.h>
#include<string.h>
void sorting(int n);
struct student
{ char name[20];
char address[20];
} s[100];
void main()
{
int i,n;
printf(“\n how many records do you qant to enter”);
scanf(“%d”,&n);
for (i=0; i<n;i++)
{ printf(“\nenter name and enter address”);
scanf(“%s%s”,s[i].name,s[i].address);
}
sorting(n); }
void sorting(int n)
{ struct student temp;
int i,j;
for(i=0;i<n-1;i++)
{ for (j=i+1;j<n;j++)
{ if(strcomp(s[i].name,s[j].name)>0
{ temp=s[i];
s[i]=s[j];
s[j]=temp; } }}
printf(“\n name and address in alphabetical order \n”);
for(i=0;i<n;i++)
printf(“\n %s and %s”,s[i].name,s[i].address);
}

6. write a program that takes name and marks of 20 students. Sort data according to
marks in descending order and display them.
 #include<stdio.h>
void sorting(int n);
struct student{
char name[20];
float marks;
} s[20];
void main()
{ int i,n;
pripnptf(“\nhow many records do you want to enter”);
scanf(“%d”,&n);
for (i=0;i<n;i++){
printf(“\n enter name, marks:”);
scanf(“%s%f”,s[i].name,&s[i].marks);
} dorting(n);
}
void sorting (int n)
{ struct student temp;
int i,j;
for(i=0;i<n-1;i++)
{ for (j=i+1;j<n;j++)
{ if(strcomp(s[i].name,s[j].name)>0
{ temp=s[i];
s[i]=s[j];
s[j]=temp; }
}}

printf(“\n Records in niDesecindng order on the basis of marks\n”);


for(i=0;i<n;i++)
printf(“\n %S %f”,s[i].name,s[i].marks);
}

7. Define array of structure student with members: sid, name, sub1, sub2, sub3, sub4,
sub5, and total. write an interactive program to perform the following options:Input
Records, Display records in Ascending order (on the basis of total marks), Display the
record of student scoring highest total marks, search the record of student by using sid
and exit.
 #include<stdio.h>
int menu();
void input(int n);
void display(int n);
void heighest(int n);
void search(int n,int key);
struct student
{ int sid, char fname[30],lname[30];
float sub1,sub2,sub3,sub4,sub5,total;
} s[100];
void main()
{ int n,ch,key,temp;
do{ ch=menu();
swith(ch)
{ case 1: printf(“\n enter how many records:”);
scanf(“%d”,&n);
input(n);
break;
case 2: display(n);
break;
case 3:highestmark(n);
break;
case 4: printf(“\n enter student id for searcing:”);
break;
case 5:printf(“\n thanks for using the program.”); break
}
while(ch!=5)
}
int menu()
{ int ch;
printf(“\n 1..>Input Records”);
printf(“\n 2..>display records”);
printf(“\n 3..>heighest markd”);
printf(“\n 4...>search records”);
printf(“\n 5..>exit”);
printf(“\n please select your choice:”);
scanf(“%d”,&ch);
return(ch);
}
void input(int n)
{ int i;
for(i=0;i<n;i++)
{
printf(“enter sid, first-name, last-name:”);
scanf(“%d%s%s”,&s[i].sid,s[i].fname,s[i].lname);
printf(“enter marks in English, nepali,chemistry,physics,computer:”);
scanf(“%d%d%d%d%d”,&s[i].sub1”,&s[i].sub2”,&s[i].sub3,&s[i].sub3,&s[i].s
u4&s[i].sub5);
}
}
void display(int n)
{ struct student temp;
int i,j;
for(i=0, ”,i<n-1;j++)
{ for(j=i+1;j<n;j++)
{
if(s[i].total>s[j].total)
{ temp=s[i];
s[i]=s[j];
s[j]=temp;

}}}

for(i=0;i<n;i++)

{ printf (“\n sid=%d\nfullname=%s%s”,s[i].sid,s[i].fname,s[i].lname);

printf(“\n english=%f\n nepali=%f\nchemistry=%f\nphysics=%f\ncomputer=


%f” ,s[i].sub1,s[i].sub2,s[i].sub3,s[i].sub4,s[i].dub5);

void higestmark(int n)

{ int i, max=s[0].total;

for(i=0;max=s[0].total;

for(i=0;i<i<n;i++)

{ if(s[i].total>max)

max=s[i].total;

for (i=0;i<n;’i++)

if(max===s[i].total)

{ printf(“\nsid=%d\nfullname=%s%s”,s [i].sid,s[i].fname,s[i].lname);
printf(“\n english=%f\n nepali=%f\nchemistry=%f\nphysics=%f\ncomputer=
%f” ,s[i].sub1,s[i].sub2,s[i].sub3,s[i].sub4,s[i].dub5);

}}

void searching(int n, int key)

int i,flag=0;

for(i=0;i<i<n;i++)

{ if (key==s[i].total)

{ flag=1;

break;

if(flag==0)

printf(“\n the searchis unsuccesseful”);

else

printf(“\n the search is successful at position%d”,i);

8. write a program to write and read successive records to/from a data file .
 #include<stdio.h>
#include<conio.h>
struct employee
{ int empid;
char fname[20],lname[20];
float salary;
} emp;

void man()
{ FILE*fp;
char ch=’y’
fp=fopen(“employee.txt”,”w”);
while(ch!=’n’)
{ printf(“\n enter employee id,first name, last name, salary”);
scanf(“%d%s%S%f”,&emp.empid,emp.fname,emp.lname,&emp.salary);
fprintf(fp,”\n employee id=%d, name=%s%s, salary=%f”,
emp.empid,emp.fname,emp.lname,emp.salry);
printf(“\ndo you want to add more record(y-yes/n-no):”);
ch=getche();
}
fclose(fp);
fp=fopen(“employee.txt”,”r”);
printf(“\n data from the file\n”);
while((fscanf(fp,”%d, %s%s,%f”, &emp.empid, emp.fname, emp.lname,
&emp.salary))!=EOF)
{
printf(“\n %d is employee id, %s%s is name,%f is salary”,
emp.empid,emp.fname,emp.lname,emp.salary);
}
fclose(fp);
}

9. Write a program to write, read and appen records to/from a data file.
 #include<stdio.h>
#include<conio.h>
void write;
void read;
void append;
struct employee
{ int empid;
char fname[20],lname[20];
float salary;
} emp;
FILE*fp;
void man()
{ int ch;
do{ printf(“\n1->write data\n2->read data\n3->append data\4->exit\n enter
your choice:”);
scanf(“%d”,&ch);
switch(ch){
case 1: write();
braek;
case 2:read();
break;
case 3: append();
break;
default: printf(“\n thanks for using this program”);
} while(ch!=4);
void write()
{ char ch=’y’;
fp=fopen(“employee.txt”,”w”);
while(ch!=’n’)
{ printf(“\n enter employee id,first name, last name, salary”);
scanf(“%d%s%S%f”,&emp.empid,emp.fname,emp.lname,&emp.salary);
fprintf(fp,”\n employee id=%d, name=%s%s, salary=%f”,
emp.empid,emp.fname,emp.lname,emp.salry);
printf(“\ndo you want to add more record(y-yes/n-no):”);
ch=getche();}
fclose(fp);
}
void read()
{ fp=fopen(“employee.txt”,”r”);
printf(“\n data from the file\n”);
while((fscanf(fp,”%d, %s%s,%f”, &emp.empid, emp.fname, emp.lname,
&emp.salary))!=EOF)
{
printf(“\n %d is employee id, %s%s is name,%f is salary”,
emp.empid,emp.fname,emp.lname,emp.salary);
}
fclose(fp);
}
void append()
{ char ch;
fp=fopen(“employee id”);
do{
printf(“\n pressy->append record/ \n->vo thankd:”);
if(ch==’y’)
{ printf(“\n enter employee id,first name, last name, salary”);
scanf(“%d%s%S%f”,&emp.empid,emp.fname,emp.lname,&emp.salary);
fprintf(fp,”\n employee id=%d, name=%s%s, salary=%f”,
emp.empid,emp.fname,emp.lname,emp.salry);
}
while(ch!=’n’);
fclose(fp);
}

You might also like