c c++
Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit). No database should be used. All data must be stored in one or two files. Listing records should print the names of the users in alphabetical order. And the important thing is, total file should not be re-written for every add/delete operation.
View Answers
December 24, 2009 at 3:48 PM
Hi Friend,
Try the following code:
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
class StudentApplication {
JFrame f;
JPanel p1,p2,p3,p,p4;
JTabbedPane tp;
ImageIcon btnimg1,btnimg2;
JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JScrollPane sp1;
JButton savebtn,resetbtn,editbtn1,editbtn2,delBtn,viewBtn;
StudentApplication(){
f=new JFrame("Form");
p=new JPanel(new GridLayout(2,1));
p1=new JPanel(new GridLayout(5,2));
p2=new JPanel(new GridLayout(5,2));
p3=new JPanel(new GridLayout(2,2));
p4=new JPanel();
tp=new JTabbedPane();
l1=new JLabel("ID:");
l2=new JLabel("Name:");
l3=new JLabel("Age:");
l4=new JLabel("Notes:");
l5=new JLabel("Enter ID to delete Record:");
l7=new JLabel("ID:");
l8=new JLabel("Name:");
l9=new JLabel("Age:");
l10=new JLabel("Notes:");
tf1=new JTextField(12);
tf2=new JTextField(12);
tf3=new JTextField(12);
tf4=new JTextField(12);
tf5=new JTextField(12);
tf6=new JTextField(12);
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
savebtn=new JButton(" Add ");
resetbtn=new JButton(" Reset");
editbtn1=new JButton(" Edit ");
editbtn2=new JButton(" Save");
delBtn=new JButton("Delete");
viewBtn=new JButton("View");
final JTextArea area=new JTextArea(10,20);
final JScrollPane pane=new JScrollPane(area);
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(savebtn);
p1.add(resetbtn);
p2.add(l7);
p2.add(tf7);
p2.add(l8);
p2.add(tf8);
p2.add(l9);
p2.add(tf9);
p2.add(l10);
p2.add(tf10);
p2.add(editbtn1);
p2.add(editbtn2);
p3.add(l5);
p3.add(tf5);
p3.add(delBtn);
p.add(p3);
p4.add(pane);
p4.add(viewBtn);
pane.setVisible(false);
resetbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
});
savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=tf1.getText();
String value2=tf2.getText();
String value3=tf3.getText();
String value4=tf4.getText();
try{
File file=new File("school.txt");
FileWriter fstream = new FileWriter(file,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(value1+" "+value2+" "+value3+" "+value4);
out.newLine();
out.close();
JOptionPane.showMessageDialog(null,"Data is successfully inserted.");
}
catch(Exception e){}
}
});
December 24, 2009 at 3:49 PM
continue..
delBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
File f1=new File("new.txt");
File f2=new File("school.txt");
try{
String value=tf5.getText();
BufferedWriter output= new BufferedWriter(new FileWriter(f1));
BufferedReader freader =new BufferedReader(new FileReader(f2));
String s;
while ((s=freader.readLine())!=null){
String []f = s.split(" ");
String id = f[0];
String name = f[1];
String c = f[2];
String note = f[3];
if (!id.equals(value) ){
output.write(s );
output.newLine();
}
}
freader.close();
output.close();
}
catch(Exception e){}
f2.delete();
f1.renameTo(f2);
}
});
editbtn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value=tf7.getText();
File f=new File("school.txt");
try{
BufferedReader freader =new BufferedReader(new FileReader(f));
String s;
while ((s=freader.readLine())!=null){
String []st = s.split(" ");
String id = st[0];
String name = st[1];
String c = st[2];
String note = st[3];
if (id.equals(value) ){
tf7.setText(id);
tf8.setText(name);
tf9.setText(c);
tf10.setText(note);
}
}
freader.close();
}
catch(Exception e){}
}
});
editbtn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String t1=tf7.getText();
String t2=tf8.getText();
String t3=tf9.getText();
String t4=tf10.getText();
File f3=new File("new.txt");
File f4=new File("school.txt");
try{
BufferedWriter output= new BufferedWriter(new FileWriter(f3));
BufferedReader freader =new BufferedReader(new FileReader(f4));
String s;
while ((s=freader.readLine())!=null){
String []f = s.split(" ");
String id = f[0];
String name = f[1];
String c = f[2];
String note = f[3];
if (!id.equals(t1) ){
output.write(s );
output.newLine();
}
}
freader.close();
output.write(t1+" "+t2+" "+t3+" "+t4);
output.close();
}
catch(Exception e){}
f4.delete();
f3.renameTo(f4);
}
});
viewBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
pane.setVisible(true);
try{
FileReader fr = new FileReader("school.txt");
BufferedReader myInput = new BufferedReader(fr);
String s;
StringBuffer b = new StringBuffer();
while ((s = myInput.readLine()) != null) {
b.append(s);
b.append("\n");
}
area.setText(b.toString());
}
catch(Exception e){}
}
});
f.getContentPane().add(tp);
tp.addTab("View Record",p4);
tp.addTab("Add Record",p1);
tp.addTab("Edit Record",p2);
tp.addTab("Delete Record",p);
f.setSize(450,180);
f.setVisible(true);
}
public static void main(String z[]){
StudentApplication app=new StudentApplication();
}
}
Hope that it will be helpful for you.
Thanks
Related Tutorials/Questions & Answers:
C++C++ How can i write this in dev
c C++C++ How can i write this in dev
c Advertisements
c#c# how to find out the size of the BMP image in
C c++c++ use a prgrm as an example to xplain-:
a)class
b)object
c)message
d)cope resolution operator
c++c++ write a programme that calculates the area and circumference of a rectangle
c#c# how to find out the size of the BMP image
c++c++ i use turbo
c++...i want to change the background color...what is the command for it and the header file used
c++c++ i use turbo
c++...i want to change the background color...what is the command for it and the header file used
c++c++ i use turbo
c++...i want to change the background color...what is the command for it and the header file used
C++C++ dear sir
How to create windows form application for login screen using
C++?
USER Name -TESTADMIN
Password -testuser
c++c++ differenciate btw.-a)local & public variables
b)pre-defined & user defined functions
c)fnctn prototype,defination & fnctn code.use code examples
C++C++ differenciate btw.-a)local & public variables
b)pre-defined & user defined functions
c)fnctn prototype,defination & fnctn code.use code examples
c++c++ differenciate btw.-a)local & public variables
b)pre-defined & user defined functions
c)fnctn prototype,defination & fnctn code.use code examples
c++c++ write a prgrm tht accepts 3 integer values,then with a function to swap the values
C++C++ Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
C++C++ Trace the bubble sort using the following integers,which represent the elements
in an array.
5,7,3,8,6,7,3
C++C++ I have been asked to write a programme that gets five values,gets the sum,average and product please help me
C#C# i need a code that will make program perform the basic operations upon the data Listview save, update and cancel
c++ c++ write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed
c++c++ write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area
C++C++ write a prgrm tht gets five values,gets the sum,average &...;
#include <conio.h>
void main()
{
clrscr();
int a,b,
c,d,e,sum;
float average...;>b>>c>>d>>e;
sum=a+b+
c+d+e;
average=sum/5;
product=a*b*
c*d
c++c++ .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++c++ Consider the following function:
int funcExercise7(int list[], int size)
{
int sum = 0;
for (int index = 0; index < size; index++)
sum = sum + list[index];
return sum
c++c++ Consider the following declarations:
class xClass
{
public:
void... private members does class xClass have?
c. How many constructors does class xClass.... Write a
C++ statement that prints the values of the data members of
the object
C#C# register form i want to generate a user id automatically after filling their register form and i want to show their id to their email?
please reply me soon
c++c++ Consider the following declarations:
class xClass
{
public:
void func();
void print() const;
xClass ();
xClass (int, double);
private:
int u... private members does class xClass have?
c. How many constructors does class xClass
c++c++ Write a console based
C++ program that reads student information from a text file, build an array of objects of type class StudentInfo... name with the minimum GPA
7) Display Student GPAs as Letter Grades (A, B,
C, D
c++c++ .write a prgrm tht accepts 5 subjects of a student,it shld hv a function to calculate the average & another function to grade.grade shld be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++c++ Characterize the following algorithm in terms of Big-O notation. Also find
the exact number of additions executed by the loop. (Assume that all
variables are properly declared.)
for (int i = 1; i <= n; i++)
sum = sum + i
c++c++ Characterize the following algorithm in terms of Big-O notation.
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= n; k++)
cout << i + j + k
C++C++ . Consider the definition of the following class:
class CC
{
public:
CC(); //Line 1
CC(int); //Line 2
CC(int, int); //Line 3
CC(double, int); //Line 4
.
.
.
private:
int u;
double v
c++c++ Write the definition of the class dayType that implements the day of the
week in a program. The class dayType should store the day... on an object of type dayType:
a. Set the day.
b. Print the day.
c. Return the day
C++C++ Hi I do not understand the question stated below. Does anyone... and the second row are the two generated numbers.
b g
c z k e <- letter index... for clarification on the above question.
Element a b
c ��� x y z
Index 0 1 2
c++ c++ Assume vector "x" of integers with values of 7, 3, 5, 8, 1, 9, 0, 4, 2, 6.
Second, assume integer variables "a," "b" and "y" with values of 3, x.size()-5 and 0, respectively.
Third, assume a for-loop header which: 3.1
c++c++ write a programme that calculates the area and circumference of a rectangle
#include<conio.h>
#include<iostream.h>
class rect
{
int l,b;
int area;
int peri;
public:
void get_rect()
{
cout<<"\n
C,C++C,
C++ Sir,
100&30 gives output 4 in
C++ and
100|30 gives output 116
How & and | gives output 4 and 116
C,C++C,
C++ int i=100,j=20;
int
c=i&j;
int r=i|j;
printf("%d",
c);
printf("%d",r);
#include<stdio.h>
#include<conio.h>
void main(){
int i=100,j=20; int
c=i&j; int r=i|j;
printf("%d",
c);
printf("%d",r
C/C++ - Development processC/
C++ I need the code for playing the backgammon game using
C/
C++.Im using turbo
C. I`ve already design the board.I badly need the code for playing this game
basic c/c++ questionsbasic
c/
c++ questions Are the Control statements like if(),while() in built functions?
if no, why not as they satisfy all the properties of a function
basic c/c++ questionsbasic
c/
c++ questions Are the Control statements like if(),while() in built functions?
if no, why not as they satisfy all the properties of a function
C/C++ QUESTIONSC/
C++ QUESTIONS â??Write a function for finding out the occurences of repeated word from a sentence. This
function would return an array of duplicate words.â
c/c++ - Development processc/
c++ Ive been asked to develop a backgammon game using
C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
c/c++ - Development processc/
c++ Ive been asked to develop a backgammon game using
C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
c or c++ - Java Beginnersc or
c++ Write a program for a two user chess game(Users must be on different systems)? please send me this source code to my mail id with step by step explanation
c c++ - Java Beginnersc c++ Write a Multi-user chat server and client Hi Friend,
Please visit the following link:
http://www.roseindia.net/chatserver/index.shtml
Hope that it will be helpful for you.
Thanks
C/C++ QUESTIONSC/
C++ QUESTIONS "Write a function for finding out highest and lowest marks obtained by a student from an
array contained student name and marks".
For Example :
GetHighestLowestMarks{Student{n}, Marks{n}} returns
C# questionC# question In
C#, string is a class or primitive type. Explain