Question

In: Computer Science

C++ and Java Zoo File Manager I need to complete these files: #include <iostream> #include <jni.h>...

C++ and Java Zoo File Manager

I need to complete these files:

#include <iostream>
#include <jni.h>
using namespace std;

void GenerateData() //DO NOT TOUCH CODE IN THIS METHOD
{
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
//================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
options[0].optionString = (char*) "-Djava.class.path="; // where to find java .class
vm_args.version = JNI_VERSION_1_6; // minimum Java version
vm_args.nOptions = 1; // number of options
vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
//=============== load and initialize Java VM and JNI interface =============
jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
delete options; // we then no longer need the initialisation options.
if (rc != JNI_OK) {
// TO DO: error processing...
cin.get();
exit(EXIT_FAILURE);
}
//=============== Display JVM version =======================================
cout << "JVM load succeeded: Version ";
jint ver = env->GetVersion();
cout << ((ver >> 16) & 0x0f) << "." << (ver & 0x0f) << endl;

jclass cls2 = env->FindClass("ZooFileWriter"); // try to find the class
if (cls2 == nullptr) {
cerr << "ERROR: class not found !";
}
else { // if class found, continue
cout << "Class MyTest found" << endl;
jmethodID mid = env->GetStaticMethodID(cls2, "createZooFile", "()V"); // find method
if (mid == nullptr)
cerr << "ERROR: method void createZooFile() not found !" << endl;
else {
env->CallStaticVoidMethod(cls2, mid); // call method
cout << endl;
}
}


jvm->DestroyJavaVM();
cin.get();
}

void AddAnimal()
{
/*
TODO: Write proper code to add an animal to your vector (or array)
*/
}


void RemoveAnimal()
{
/*
TODO: Write proper code to remove an animal from your vector (or array. Remmber to re-allocate proper size if using array)
*/
}

void LoadDataFromFile()
{
/*
TODO: Write proper code to load data from input file (generated using JNI) into vector/array.
*/
}

void SaveDataToFile()
{
/*
TODO: Write proper code to store vector/array to file.
*/
}

void DisplayMenu()
{
/*
TODO: write proper code to display menu to user to select from
*/
}

int main()
{
   GenerateData();
   return 1;
}

Solutions

Expert Solution

// Zooooo.cpp :
//


#include "stdafx.h"
#include <iostream>
#include<string.h>
#include<string>
#include<conio.h>
#include<fstream>
using namespace std;

int i = 0;//veriable to get indexes of array or to use as array size
string Array[1];//Array to store animal

void AddAnimal()
{
  
   Array[0] = { "Lion"};//animal name
  
   cout << "\nAnimal Inserted Successfuly!";
}


void RemoveAnimal()
{
   Array->erase();//array will be erased....completely
   cout << "\nArray Erased Successfuly!";
}

void LoadDataFromFile()
{
   //so, there you need to add your file location as i did...

   string file_name = "jni.txt";//there put the location of your file like-> C:/user/java/jni.txt
   fstream file;
   file.open(file_name);//opening the file
   if (file.fail())//if file address is wrong or file not found then we will give error so put right address here...
       cout << "file opening Error!";
   else
   {
       string line;//string to get line from file
       while (getline(file,line ))//get line from file until the end from data of file...
       {
          
           Array[i] = line;//now line will bw stored to array...
           i++;
       }
       cout << "\nData Loded From File Successful!";
   }

}

void SaveDataToFile()
{
   //you can change the address of file or name that i used here...
   fstream file;
   string file_name = "data_file.txt";//same do here where you want to save data otherwise if file not found you will recieve error
   file.open(file_name);//open file
   if (file.fail())
       cout << "\nFile Opening Failed!";
   else
   {
       int array_size = 0;
       while (array_size<=i)
       {
           file << Array[array_size] << endl;//getting data from array and saving it to file
           array_size++;
       }
       cout << "\nData on File Saved Successfuly!";
   }
}

void DisplayMenu()
{
   int option;
   menue:
   cout << "\n\t\tMENUE\n-------------------------------------\n----------------------------------------";
   cout << "\n\n1.Add Animal\n2.Remove Animal\n3.Load Data From File\n4.Save Data to File\n5.Exit\n\nENTER YOUR OPTION: ";      
   cin >> option;
   switch (option)
   {
   case 1://if user press 1
       AddAnimal();//function will be clled
       _getche();
       goto menue;
   case 2://if press 2
       RemoveAnimal();//function will be clled
       _getche();
       goto menue;
   case 3://if press 3
       LoadDataFromFile();//function will be clled
       _getche();
       goto menue;
   case 4://if press 4
       SaveDataToFile();//function will be clled
       _getche();
       goto menue;
   case 5://if press 5
       return;//stop execution of program will end....
   default://if user will not press right option...
       cout << "\nInvalid Option!";
       cout << "\nPress any key to contniue...";
       _getche();
       goto menue;
   }
}

int _tmain(int argc, _TCHAR* argv[])
{
   DisplayMenu();//calling the menue function to display Menue...
   return 0;
}

if you feel any Query please do a Comment

Give me a thumbs up


Related Solutions

Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h>...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h> #include <semaphore.h> #include <pthread.h> using namespace std; #define NRO 6 // Número de coches //Puente declarado con matriz y valor entero void Puente(string array, int value); // Variable global int Norte = 1; int Sur = 1; sem_t mutex1; //Coche al norte void* NorteC(void* arg){ sem_wait(&mutex1); string array = "En el lado Norte "; // Norte cout<<array<<"del puente, el coche #"<<Norte<<" puede cruzar el...
c++: I need #include <iostream> header A palindrome (Links to an external site.) is a word,...
c++: I need #include <iostream> header A palindrome (Links to an external site.) is a word, phrase, number, or sequence of words that reads the same backward as forward. Punctuation, capitalization, and spaces between the words or lettering are allowed. Here are some examples of word and phrase palindromes. Words: Civic Kayak Level Madam Mom Noon Racecar Radar Refer Rotor Phrases: Don't nod. I did, did I? My gym Step on no pets Top spot Never odd or even Eva,...
C++ The txt file is not showing up in my output #include <iostream> #include <fstream> #include...
C++ The txt file is not showing up in my output #include <iostream> #include <fstream> #include <string> #include "Classroom.h" using namespace std; Classroom myLib; void loadDataset(string fileName) { ifstream myFile; myFile.open(fileName.c_str()); } void continueMessage(string message) { cout << message << endl; cout << "Press Enter to continue.." << endl; cin.get(); } int main() { string fileName = "dataset.txt"; loadDataset(fileName); myLib.print(); continueMessage; string ID = "Janet Newman"; myLib.removeStudent (ID); continueMessage("Janet Newman has been removed."); //--------------------------------------------------------------------------- myLib.print(); continueMessage("All students are listed!"); return...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
I need the following C code converted to java or C++ #include <stdio.h> #include <stdlib.h> typedef...
I need the following C code converted to java or C++ #include <stdio.h> #include <stdlib.h> typedef struct node { struct node *left; struct node *right; long data; long leftSize; } node; void btreeInsert(node *new, node **rootptr) { node *parent = NULL, *cursor; /* Find parent */ cursor = *rootptr; while (cursor != NULL) { parent = cursor; if (new->data < cursor->data) { cursor->leftSize += 1; cursor = cursor->left; } else { cursor = cursor->right; } } /* Insert node below...
Download the following zip file Bag and complete the program. You will need to complete files...
Download the following zip file Bag and complete the program. You will need to complete files MyBag and . MyBag uses the java API class ArrayList as the underline data structure. Using the class variables given, complete the methods of the MyBag class. In your BagHand class you should set appropriate default values for select class variables in the constructor in the add method, use the MyBag object to add a PlayingCard type to the bag and find and set...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
Data Structure using C++ Complete and test the Sudoku problem main.cpp #include <iostream> #include <cmath> #include...
Data Structure using C++ Complete and test the Sudoku problem main.cpp #include <iostream> #include <cmath> #include "sudoku.h" using namespace std; int main() { cout << "See Programming Exercise 18." << endl; } sudoku.cpp #include <iostream> #include "sudoku.h" using namespace std; sudoku::sudoku() { cout << "Write the definition. ." << endl; } sudoku::sudoku(int g[][9]) { cout << "Write the definition." << endl; } void sudoku::initializeSudokuGrid() { cout << "Write the definition." << endl; } void sudoku::initializeSudokuGrid(int g[][9]) { cout << "Write...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell {...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell { int val; Cell *next; }; int main() { int MAX = 10; Cell *c = NULL; Cell *HEAD = NULL; srand (time(NULL)); for (int i=0; i<MAX; i++) { // Use dynamic memory allocation to create a new Cell then initialize the // cell value (val) to rand(). Set the next pointer to the HEAD and // then update HEAD. } print_cells(HEAD); }
I need this in java on textpad. There are two files, both have instructions in them...
I need this in java on textpad. There are two files, both have instructions in them on what to add in the code. They are posted below. public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[5]; } public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[capacity]; } public MyArrayForDouble(double[] nums1) { nums =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT