INTRODUCTION This is a C programming language This is an exe
INTRODUCTION: This is a C programming language. This is an exercise in simple class implementation: constructors, accessors, and simple member functions. You will get a complete kit: Makefile, class header and implementation files, and a test file. DO NOT edit the header file.
MAIN QUESTION: Complete the class by implementing all the functions declared in rational.h file. HINT: start with just enough code to satisfy the compiler and linker such code will faill all the tests if you try to run the program. The tests in main() are organized in the order in which you should implement the code.
Rational.cpp file:
rational.h file:
main.cpp file:
makefile:
Solution
import java.util.*;
public category ArrayListExample i am attending to add String
*elements therefore I created it of string kind */
ArrayList<String> obj = new ArrayList<String>();
/*This is however components ought to be value-added to the array list*/
obj.add(\"Ajeet\");
obj.add(\"Harry\");
obj.add(\"Chaitanya\");
obj.add(\"Steve\");
obj.add(\"Anuj\");
/* Displaying array list components */
System.out.println(\"Currently the array list has following elements:\"+obj);
/*Add part at the given index*/
obj.add(0, \"Rahul\");
obj.add(1, \"Justin\");
/*Remove components from array list like this*/
obj.remove(\"Chaitanya\");
obj.remove(\"Harry\");
System.out.println(\"Current array list is:\"+obj);
/*Remove part from the given index*/
obj.remove(1);
System.out.println(\"Current array list is:\"+obj);
}
}
Output:
Currently the array list has following elements:[Ajeet, Harry, Chaitanya, Steve, Anuj]
Current array list is:[Rahul, Justin, Ajeet, Steve, Anuj]
Current array list is:[Rahul, Ajeet, Steve, Anuj]
Methods of ArrayList category
In the on top of example we\'ve got used ways like add and take away. but there square measure range of ways accessible which may be used directly exploitation object of ArrayList category. Let’s discuss few of the necessary ways.
1) add( Object o): This methodology adds Associate in Nursing object o to the arraylist.
obj.add(\"hello\");
This statement would add a string how-do-you-do within the arraylist ultimately position.
2) add(int index, Object o): It adds the item o to the array list at the given index.
obj.add(2, \"bye\");
It will add the string bye to the 2d index (3rd position because the array list starts with index 0) of array list.
3) remove(Object o): Removes the item o from the ArrayList.

