Posts

12. Write a Java program which will demonstrate a concept of cohesion and coupling of the various modules in the program.

 -------------------------Coupling--------------------------- import java.lang.*; import java.util.*; class Box { public int vol; Box( int l , int b , int h) { this.vol = l*b*h; } } class Volume { public static void main(String args[]) { Box b = new Box(5,5,5); System.out.println("VOLUME : " + b.vol); } }     -------------------------Cohesion--------------------------- import java.util.*; import java.lang.*; class Name { String name; public String getName(String name) { this.name = name; return name; } } class Age { int age; public int getAge(int age) { this.age = age; return age; } } class Number { int num; public int getNum(int num) { this.num = num; return num; } } public class Student { public static void main(String args[]) { Name n = new Name(); System.out.println("NAME : " + n.getName("Shreyas")); Age a = new Age(); System.out.println("Age : " + a.getAge(20)...

11. Any application defining scope of Formal parameter, Global parameter, Local parameter accessing mechanism and also relevance to private, public and protected access. Write a Java program which demonstrates the scope rules of the programming mechanism.

import java.util.*; class employee { public String e_name; protected int e_id; String e_add; double salary; employee() { e_name = "abc"; e_id = 0; e_add = "xyz"; salary = 0; } } class Company extends employee { private long ph_no; void get() { Scanner in = new Scanner(System.in); System.out.println("ID : "); e_id = in.nextInt(); System.out.println("NAME : "); e_name = in.next(); System.out.println("ADDRESS : "); e_add = in.next(); System.out.println("SALARY : "); salary = in.nextDouble(); System.out.println("PHONE NO. : "); ph_no = in.nextLong(); } void put() { System.out.println("ID : " + this.e_id); System.out.println("NAME : " + this.e_name); System.out.println("ADDRESS : " + e_add); System.out.println("SALARY : " + salary); System.out.println("PHONE NO. : " + ph_no); } public static void m...

10. Implement the Heap/Shell sort algorithm implemented in C++/Java demonstrating heap/shell data structure with modularity of programming language.

#include<iostream> #include<cstring> using namespace std; #define size 20 class heap { public: void accept() { int n; cout<<".. .. .. .. .. .. .. .. .. .. .. "<<endl; cout<<": ENTER NUMBER OF STUDENTS = "; cin>>n; int a[size]; cout<<": ENTER MARKS OF EACH STUDENTS :"<<endl; for(int i = 1 ; i <= n ; i++) { cout<<"Roll NO. "<<i<<" = "; cin>>a[i]; } heapsort(a,n); display(a,n); } void max_heapify(int a[] , int i , int n) { int temp,left,right,large; large = 0; left = 2*i; right = 2*i+1; if( (left <= n) && (a[left] > a[i])) large = left; else large = i; if( ( right <= n ) && ( a[right] > a[large] ) ) large = right; if(large != i) { temp = a[i]; a[i] = a[large]; a[large] = temp; max_heapify(a,large,n); } } void heapsort(in...

9. Department maintains a student information. The file containsrollnumber, name, division and address. Allow user to add, delete information of student. Display information of particular employee. If record of student does not exist an appropriate message is displayed. If it is, then the system displays the student details.Use sequential file to main the data.

#include<iostream> #include<fstream> using namespace std; class student { int roll_no; string name,div,address; public: student(); void add_record(); void delete_data(string); void modify_record(); void search_data(string); void input_data(); void write_data(); void read_data(); }; student :: student() : roll_no(0) , name(""), address(""),div (""){} void student :: input_data() { cout<<": ENTER STUDENTS DETAILS :"<<endl<<endl; cout<<": ROLL NO = "; cin>>roll_no; cin.ignore(); cout<<": NAME = "; getline(cin,name); cout<<": DIVISION = "; getline(cin , div); cout<<": ADDRESS = "; getline(cin , address); write_data(); } // FUNCTION TO WRITE DATA INTO THE FILE void student :: write_data() { fstream obj; obj.open("student_data.txt" , ios::out | ios::app); obj << roll_no <<" "...

8. Prims Algorithm

#include<iostream> using namespace std; #define infi 9999; class prim { float arr[10][10]; int nodes; char a[6] = {'A','B','C','D','E','F'}; public: void creategraph() { cout<<"ENTER THE NUMBER OF NODES : "; cin>>nodes; for( int i = 0 ; i < nodes ; i++ ) { for( int j = 0 ; j < nodes ; j++) { if( i != j && i < j ) { cout<<"DISTANCE BETWEEN "<<a[i]<<" TO "<<a[j]<<" = "; cin>>arr[i][j]; arr[j][i] = arr[i][j]; } else if(i == j) { arr[i][j] = 0; } } } for(int i = 0 ; i < nodes ; i++) for(int j = 0 ; j < nodes ; j++) if( arr[i][j] == 0 ) arr[i][j] = infi; } void primalgo() { creategraph(); // call to creategraph int visited[nodes]; // defines which nodes are visited and from these nodes we need to find the minimum path ...

7. Optimal Binary Search Tree.

#include<iostream> using namespace std; class obst { int p[10],q[10]; // p -> probability of success : q -> probability of failure int arr[10]; // array of elements int weight[10][10],root[10][10],cost[10][10]; // resultant for obst i.e.,weight , root , cost int n; // n -> no. of elements public: void get() { cout<<"ENTER NUMBER OF ELEMENTS = "; cin>>n; cout<<": INPUT DATA ( ELEMENT , PROBABILITIES ) :"<<endl; for( int i = 1 ; i <= n ; i++ ) { cout<<"ELEMENT "<<i<<" = "; //element cin>>arr[i]; cout<<"p ["<<i<<"] = "; //success probability cin>>p[i]; cout<<"q ["<<i-1<<"] = "; //failure probability cin>>q[i-1]; } cout<<"q ["<<n<<"] = "; ...

6. Implement all the functions of a dictionary (ADT) using hashing.Data: Set of (key, value) pairs, Keys are mapped to values, Keys must be comparable, Keys must be uniqueStandard Operations: Insert(key, value), Find(key), Delete(key)

#include<iostream> using namespace std; #define size 10 class Record { string name; long ph_num; int flag; public: Record() { name = "-"; ph_num = 0; flag = 0; } friend class Phonebook; }; class Phonebook { int capacity; int key; public: Phonebook() : capacity(0) {} void input( Record table[] ) { if( capacity == size ) { cout<<"HASH TABLE FULL !!"<<endl; return; } else { Record r; cout<<"ENTER NAME : "; getline(cin , r.name); cin.ignore(); cout<<"ENTER TELEPHONE NO. : "; cin>>r.ph_num; int index = hash(r.name); while(table[index].flag == 1) { if(table[index].name == r.name) { cout<<" RECORD ALREADY EXIST !!"<<endl; return; } index++; index %= size; } table[index] = r; table[index].flag = 1; capacity++; } } int hash( string name) { int sum = 0; for(int...