Skip to content
Open

Lab11 #107

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions 4th Sem (Design and Analysis of algorithm)/lab1_student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Scanner;
public class Student
{
private String usn, name, branch, phone;
public Student(String usn, String name, String branch, String phone)
{
super();
this.usn = usn;
this.name = name;
this.branch = branch;
this.phone = phone;
}
@Override
public String toString()
{
return "Student [USN = " + usn + ", NAME = " + name + ", BRANCH = " + branch
+ ", PHONE NUMBER = " + phone + "]";
}
public static void main(String args[])
{
int i;
String usn, branch, name, phone;
Scanner s = new Scanner(System.in);
System.out.println("Enter number of Students: ");
int n = s.nextInt();
Student[] students = new Student[n + 1];
for(i = 1; i<= n; i ++)
{
System.out.println("Enter student "+ i +" details\n");
System.out.println("Give Student Details USN, Name, Branch, Phone Number");
usn = s.next();
name = s.next();
branch = s.next();
phone = s.next();
students[i] = new Student(usn, name, branch, phone);
}
System.out.println("DATABASE:");
for(i = 1; i <= n; i ++)
{
System.out.println(students[i]);
}
}
}
60 changes: 60 additions & 0 deletions 4th Sem (Design and Analysis of algorithm)/lab1b_stacks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.Scanner;
public class StackDemo
{
public static void main(String[] args)
{
int top = -1;
int n,element,i;
int[] a;
Scanner s = new Scanner(System.in);
System.out.println("Enter Stack Size");
n = s.nextInt();
a = new int[n+1];
System.out.println("Stack operations are" +"\t"+ "1.Push"+"\t"+ "2.POP"+"\t"+
"3.Display"+"\t"+ "4.Exit");
for(;;)
{
System.out.println("Enter your choice");
int choice = s.nextInt();
switch(choice)
{
case 1: if(top == n-1)
{
System.out.println("Stack overflow");
}
else
{
System.out.println("Enter element to be pushed");
element = s.nextInt();
a[top++] = element;
}
break;
case 2: if(top == -1)
{
System.out.println("Stack Underflow");
}
else

{
System.out.println("Popped element " + a[top--]);
}
break;
case 3: if(top== -1)
{
System.out.println("Stack Empty");
}
else
{
System.out.println("Elements in stack :");
for ( i = top; i >= 0; i--)
{
System.out.println(a[i]);
}
}
break;
case 4: System.exit(0);
break;
}
}
}
}
174 changes: 174 additions & 0 deletions 4th Sem (Design and Analysis of algorithm)/lab2a.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import java.util.Scanner;
class Staff
{
protected String staffId, name, ph;
protected float salary;
public Staff(String staffId, String name, float salary2, String ph)
{
super();
this.staffId = staffId;
this.name = name;
this.salary = salary2;
this.ph = ph;
}
@Override
public String toString()
{
return "Staff [staffId=" + staffId + ", name=" + name + ", salary="
+ salary + ", ph=" + ph + "]";
}
}
class Teaching extends Staff
{
private String domian, publication;
public Teaching(String staffId, String name, float salary, String ph,
String domian, String publication)
{
super(staffId, name, salary, ph);
this.domian = domian;
this.publication = publication;
}
@Override
public String toString()
{
return "Teaching [domian=" + domian + ", publication=" + publication
+ ", staffId=" + staffId + ", name=" + name + ", ph=" + ph
+ ", salary=" + salary + "]";
}
}
class Technical extends Staff
{
private String skills;
public Technical(String staffId, String name, float salary, String ph,
String skills)
{
super(staffId, name, salary, ph);
this.skills = skills;
}
@Override
public String toString()
{
return "Technical [skills=" + skills + ", staffId=" + staffId
+ ", name=" + name + ", ph=" + ph + ", salary=" + salary + "]";
}
}
class Contract extends Staff
{
private String period;
public Contract(String staffId, String name, float salary, String ph,
String period)
{
super(staffId, name, salary, ph);
this.period = period;
}
@Override
public String toString()
{
return "Contract [period=" + period + ", staffId=" + staffId
+ ", name=" + name + ", ph=" + ph + ", salary=" + salary + "]";
}
}
public class StaffDemo
{
public static void main(String[] args)
{
int i,choice;
String staffId, name, ph, domain, publication, skills, period;
float salary;
int teachingCount=0, technicalCount=0, contractCount=0;
Teaching[] teachingStaff = new Teaching[10];
Contract[] contractStaff = new Contract[10];
Technical[] technicalStaff = new Technical[10];
Scanner s = new Scanner(System.in);
System.out.println("1 Teaching Staff Entry");
System.out.println("2 Technical Staff Entry");
System.out.println("3 Contract Staff Entry");
System.out.println("4 Teaching Staff Details");
System.out.println("5 Technical Staff Details");
System.out.println("6 Contract Staff Details");
System.out.println("7.Exit");
for(;;)
{
System.out.println("enter your choice");
choice = s.nextInt();
switch(choice)
{
case 1: System.out.println("Enter Teaching
Details(StaffId,Name,Salary,PhoneNumber,Domain,Publication)");
staffId = s.next();
name = s.next();
salary = s.nextFloat();
ph = s.next();
domain = s.next();
publication = s.next();
teachingStaff[teachingCount]= new
Teaching(staffId,name,salary,ph,domain,publication);
teachingCount++;
break;
case 2: System.out.println("Enter Technical
staffDetails(StaffId,Name,Salary,PhoneNumber,Skills)");
staffId = s.next();
name = s.next();
salary = s.nextFloat();
ph = s.next();
skills = s.next();
technicalStaff[technicalCount] = new
Technical(staffId,name,salary,ph,skills);
technicalCount++;
break;
case 3: System.out.println("enter Contract staff
details(StaffId,Name,Salary,PhoneNumber,Period)");
staffId = s.next();
name = s.next();
salary = s.nextFloat();
ph = s.next();
period = s.next();
contractStaff[contractCount] = new Contract(staffId,name,salary,
ph ,period);
contractCount++;
break;
case 4: System.out.println("Teaching Staff Details");
if(teachingCount==0)
{
System.out.println("No teaching staff details
available");
}
else
{
for(i=0;i<teachingCount;i++)
{
System.out.println(teachingStaff[i]);
}
}
break;
case 5: System.out.println("Technical Staff Details:");
if(technicalCount==0)
{
System.out.println("No technical staff details available");
}
else
{
for(i=0;i<technicalCount;i++)
{
System.out.println(technicalStaff[i]);
}
}
break;
case 6: System.out.println("contract Staff Details:");
if(contractCount==0)
{
System.out.println("No contract staff details available");
}
else
{
for(i=0;i<contractCount;i++)
{
System.out.println(contractStaff[i]);
}
}
break;
case 7: System.exit(0);
}
}
}
}
43 changes: 43 additions & 0 deletions 4th Sem (Design and Analysis of algorithm)/lab2b.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Scanner;
import java.util.StringTokenizer;
class Customer
{
private String customerName,date;
public Customer(String customerName, String date)
{
super();
this.customerName = customerName;
this.date = date;
}
@Override
public String toString()
{
String returnValue = customerName+",";
StringTokenizer tokenizer = new StringTokenizer(date,"/");
System.out.println("The Customer details are ");
while(tokenizer.hasMoreTokens())
{
returnValue = returnValue+tokenizer.nextToken();
if(tokenizer.hasMoreElements())
{
returnValue = returnValue+",";
}
}
return returnValue;
}
}
public class CustomerDetails
{
public static void main(String[] args)
{
String customerName;
String date;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter customer name");
customerName = scanner.next();
System.out.println("Enter Date (dd/mm/yyy)");
date = scanner.next();
Customer customer = new Customer(customerName,date);
System.out.println(customer.toString());
}
}
55 changes: 55 additions & 0 deletions 6th sem (File Structure)/lab1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
char buf[20][20],infile[20],outfile[20],buf1[20];
char line[200];
int i,j,indx,x,y,ch;
fstream file,file1;
cout<<"Enter your choice\n1->file I/O\n2->standard I/O";
cin>>ch;
switch(ch)
{
case 1:{ cout<<"Enter the input file:"<<flush;
cin>>infile;
cout<<"Enter the output file:"<<flush;
cin>>outfile;
file.open(infile,ios::in);
file.unsetf(ios::skipws);
file1.open(outfile,ios::out);
while(1)
{
file.getline(line,200,'\n');
if(file.fail())
break;
else
{
} }
file.close();
for(i=strlen(line);i>=0;i--)
file1<<line[i];
file1<<"\n";
file1.close();
}
break;
case 2:{ cout<<"Enter the sequence of names or '0' to exit";
indx=0;
while(1)
{
cin>>buf[indx];
if(strcmp(buf[indx],"0")==0) break;
indx++;
}
for(i=0;i<indx;i++)
{
for(j=strlen(buf[i]);j>=0;j--)
cout<<buf[i][j];
cout<<endl;
}
}
break;
}
return 0;
}
Loading