Friday, 7 December 2012

Student Record in Java with Frame


import java.awt.*;
class a
{
public static void main(String as[])
{
Frame f=new Frame();
f.setSize(200,200);
f.setVisible(true);
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new GridLayout(7,1));
p2.setLayout(new GridLayout(7,2));
Button b1=new Button("First");
Button b2=new Button("Last");
Button b3=new Button("Next");
Button b4=new Button("First");
Button b5=new Button("Close");
Label l1=new Label();
Label l2=new Label();
Label l1=new Label("Enrollment No");
TextField t1=new TextField();
Label l2=new Label("Label 1");
TextField t2=new TextField();
Label l3=new Label("Father Name");
TextField t3=new TextField();
Label l4=new Label("Gender");
TextField t4=new TextField();
Label l5=new Label("Age");
TextField t5=new TextField();
Label l6=new Label("Phone");
TextField t6=new TextField();
Label l7=new Label("Email");
TextField t7=new TextField();
p1.add(l1);
p1.add(l2);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b5);
p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
p2.add(l3);
p2.add(t3);
p2.add(l4);
p2.add(t4);
p2.add(l5);
p2.add(t5);
p2.add(l6);
p2.add(t6);
p2.add(l7);
p2.add(t7);
f.add(p1,BorderLayout.EAST);
f.add(p2,BorderLayout.CENTER);
f.pack();
}}

Calculator in Java



import java.awt.*;
class saqlain
{
public static void main(String as[])
{
Frame f=new Frame("calculator");
f.setVisible(true);
f.setSize(200,200);
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new GridLayout(4,4,3,2));
p2.setLayout(new BorderLayout(3,3));
Button b1=new Button("7");
Button b2=new Button("8");
Button b3=new Button("9");
Button b4=new Button("+");
Button b5=new Button("4");
Button b6=new Button("5");
Button b7=new Button("6");
Button b8=new Button("-");
Button b9=new Button("1");
Button b10=new Button("2");
Button b11=new Button("3");
Button b12=new Button("*");
Button b13=new Button("0");
Button b14=new Button("=");
Button b15=new Button(".");
Button b16=new Button("/");
Button b17=new Button("Enter your text here");
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b5);
p1.add(b6);
p1.add(b7);
p1.add(b8);
p1.add(b9);
p1.add(b10);
p1.add(b11);
p1.add(b12);
p1.add(b13);
p1.add(b14);
p1.add(b15);
p1.add(b16);
p2.add(b17,BorderLayout.NORTH);
f.add(p1,BorderLayout.CENTER);
f.add(p2,BorderLayout.NORTH);
f.pack();
}}



Emloyee Record in C++


#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<ifstream.h>
struct employee
{
int code;
char fname[20],lname[20];
float sal;
};
void main()
{
employee edata;
ifstraem efile("c://tc//bin//emp.txt";ios::in/ios::binary);
employee data;
if(!efile){cout<<"file opening error";getche(); exit(0);}
while(efile)
{
efile.read((char*) & edata, size of edata);
cout<<edata.code<<"\t"<<edata.fname<<"\t"<<edata.lname<<"\t"<<edata.sal<<endl;
}
getch();
}

Student GPA in C++


#include<iostream.h>
#include<conio.h>
float gpa(int,int);
float gpa(int om,int tm)
{
float per ,g;
per=float(om)/tm*100;
g=(per>=80?4.00:per>=70?3.5:per>=60?3.0:per>=55?2.5:per>=50?2.0:0.0);
return g;
}
void main()
{
clrscr();
int nc,i,om,tm,ch,tch=0; float g,tg=0;
cout<<"Enter number of cources="; cin>>nc;
for(i=1;i<=nc;i++)
{
cout<<endl<<"Enter obtained marks="; cin>>om;
cout<<endl<<"Enter total marks="; cin>>tm;
cout<<endl<<"Enter credit hours="; cin>>ch;
g=gpa(om,tm);
tg+=g*ch;
tch+=ch;
}
cout<<endl<<"GPA="<<tg/tch;
getch();
}

Student Record in C++


#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct student
{
int rollno;
char fname[20], lname[20],city[20],dist[20];
long int contect;
char email[30];
};
void main()
{
clrscr();
ofstream efile("d:\\stdnt.txt",ios::out);
student edata;
abc:
cout<<"Enter student record(roll #,f name, lname, city,district,contect# & E-mail)";
cin>>edata.rollno>>edata.fname;
cin>>edata.lname>>edata.city>>edata.dist>>edata.contect>>edata.email;
efile<<edata.rollno<<"\t"<<edata.fname<<"\t"<<edata.lname<<"\t"<<edata.city<<"\t"<<edata.dist<<"\t"<<edata.contect<<"\t"<<edata.email<<"\n";
cout<<"press m for more.........";
char x;
x=getche();
if(x=='m')
goto abc;
getch();
}

Addition of Matrices in C++


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m1[20][20],m2[20][20],i,j,r,c,h,v;
cout<<"\t\t\t\tEnter matrix order";
cout<<"\n\n\n\tEnter number of rows="; cin>>r;
cout<<"\n\tEnter number of columns="; cin>>c;
cout<<"\n\tEnter 1st matrix=";
gotoxy(10,5);
 v=10;
for(i=0;i<r;i++)
 {
h=10;
  for(j=0;j<c;j++)
    {
     gotoxy(h,v);
     cin>>m1[i][j];
      h+=3;
    }
v+=2;
 }

gotoxy(50,8);
cout<<"enter 2nd matrix=";
v=10; h=50;
 for(i=0;i<r;i++)
 {
 h=50;
  for(j=0;j<c;j++)
  {
      gotoxy(h,v);
      cin>>m2[i][j];
      h+=3;
 }
v+=2;
}
gotoxy(30,30);
cout<<"sum of matrices=";
v=32;  h=30;
  for(i=0;i<r;i++)
  {
  h=30;
    for(j=0;j<c;j++)
    {
       gotoxy(h,v);
       cout<<m1[i][j]+m2[i][j];
       h+=3;
  }
v+=2;
}
getch();
}

Mutation Testing