package learning;
public class LargeInt {
int array[];
boolean sign;
int size;
LargeInt(){
array = new int[5]; // Initial Size set to 5
sign = true; // true means
positive and false means negative
}
LargeInt(int num){
setNumber(num);
}
/****
*
* This function takes the number which need to be stored . Set the
sign . true means positive ,false means negative.
* Count the nuber of digits in the input number. Makes the Size of
the array which can store those digits. and stores the number in
the array
* in forward direction.
* @param num
*/
public void setNumber(int num){
if(num < 0){
sign = false;
}else{
sign = true;
}
int count = countDigits(num);
size = count;
System.out.println("count " + count);
while(array.length < count){
array = increaseArraySize(array);
}
while(num != 0){
System.out.println(num%10);
array[count-1] = num %10;
num = num /10;
count = count -1;
}
}
/****
* THis function is used to count the digits in the number
* @param num
* @return
*/
public int countDigits(int num){
int count = 0;
while(num != 0){
num = num/10;
count++;
}
return count;
}
/****
* This function dynamically doubles the array Size
* @param arr
* @return
*/
public int [] increaseArraySize(int [] arr){
int [] brr = new int[(arr.length *2)];
for(int i=0; i<arr.length; i++){
brr[i] = arr[i];
}
return brr;
}
public String toString(){
StringBuilder sb = new StringBuilder();
if(sign){
sb.append("+ ");
}else{
sb.append("- ");
}
for( int i =0 ; i<size; i++){
sb.append(array[i]);
}
return sb.toString();
}
public static void main(String args[]){
LargeInt largeInt = new LargeInt();
largeInt.setNumber(123456789);
System.out.println(largeInt);
}
}
MAKE SURE TO INCLUDE WHAT PORTION OF THE CODE GOES IN WHAT FILE FOR THE CLASS....
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
1. Implement a tostring() member function. This function will return a string representation of the LargeInteger. You should probably used string streams to implement this function. Note that the digits of the large integer are stored in reverse of their display order, e.g. the 1's place (100 ) is in index 0 of digits, the 10's place (101 ) is in index 1, etc. 2. Implement a second constructor for the LargeInteger. This constructor will be used to construct a...
Suppose that you write a new class. If you do not specifically write a constructor for the class, the compiler will provide one by default: TRUE FALSE Suppose that you what to iterate through each data element of an array. What control statement would best accomplish this task: If-then-else For Switch Do-while Which of the following is the best method to destroy an object that is currently on the heap: Set the reference variable of the object to NULL Disable...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
use c++ and complete this lab #include <iostream> using namespace std; class FibObj { public: void setSize() { cout << "Enter an integer larger than 2: "; cin >> size; } int getSize() { return size; } void fibTerms(int x) // Write a recursive function { } explicit FibObj() // Default constructor was made explicit to avoid possible implicit type conversion { setSize(); int *arr; arr = new int[getSize()]; arr[0] = 1; arr[1] = 1; // Call recursive function here...
please explain [5 pts] What is the outcome of compiling and executing the following code. Assume it is embedded in an otherwise correct and complete C++ program void printBackwards(int *arr, int len){ if (len <=0) return; cout< } int main(){ int arr[4] = {1, 2, 3, 4}; printBackwards(arr, 4); } [10 pts] Implement a function that returns the minimum value in an integer array ‘arr’ of length ‘len’. You MUST use a RECURSIVE solution. //Precondition: An integer array with length...
1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...
Write C++ program
T 1030 UUIII DUCOUL The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip code using a format called POSTNET (this format is being deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown below: Illlllllllll For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar...
PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...
The code snippet below is an example of pass by reference. We also provide a sample method setZeroAt, which sets 0 at a position i in the array, to illustrate pass by reference. public class Sample { public static void setZeroAt(int [] arr, int i){ arr[i] = 0; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int sample[] = {1, 2, 3}; setZeroAt(sample, 1); //Now sample looks like {1, 0, 3} } } Write a Java...