Vectors implement a dynamic array that can hold objects of any type and number. Vectors are similar to arrays but are synchronized and contain legacy methods like Enumeration and Iterator. Vectors can be created with or without specifying an initial size. Methods like add(), addElement(), and capacity() allow adding elements and retrieving the vector's capacity. Wrapper classes allow primitive types to be used as objects and stored in collections by "wrapping" the primitive in a class like Integer or Float. Boxing and unboxing convert between primitive types and their corresponding wrapper class objects.
Use the following data set that compares age to average years lef.docxdickonsondorris
Use the following data set that compares age to average "years left to live" to answer the following questions.
Age 10 20 30 40 50 60 70 80 90 100
Years to live 59.2 49.6 40.7 31.9 24.0 17.2 11.6 7.2 4 .4 2.8
a) Show the scatterplot for this data with the least squares regression line. Find R^2. How much of the variation is explained by the regression line?
b) Experiment with the non-linear regressions available on the calculator. Which seem to fit? Show the scatterplot with three different regression curves from the calculator. Label each equation, as well as the applicable R^2.
c) Choose a regression equation to predict how many "years left" a person has if he is now 101 years old. Can he count on celebrating Christmas 2015?
InfoTest.javaInfoTest.javapackage assignment1;
importstatic org.junit.Assert.*;
import org.junit.Test;
publicclassInfoTest{
@Test
publicvoid testInfo(){
Info tempInfo =newInfo();
assertNotNull(tempInfo.tmp);
}
@Test
publicvoid testInsert(){
Info tempInfo =newInfo();
// Insert into an empty list
tempInfo.insert(30);
assertEquals(30, tempInfo.get(0));
// Insert an item to be placed at the beginning of the list
tempInfo.insert(4);
assertEquals(4, tempInfo.get(0));
assertEquals(30, tempInfo.get(1));
// Insert an item to be placed at the end of the list
tempInfo.insert(20);
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
// Insert an which already exists
tempInfo.insert(20);
assertEquals(4, tempInfo.get(0));
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
}
@Test
publicvoid testDelete(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// delete from the middle
tempInfo.delete(10);
assertEquals(5, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the beginning
tempInfo.insert(10);
tempInfo.delete(5);
assertEquals(10, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the end
tempInfo.insert(5);
tempInfo.delete(15);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
// delete something that does not exist
tempInfo.insert(15);
tempInfo.delete(7);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(1));
}
@Test
publicvoid testGet(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// get items at the beginning, middle, and end of the list
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(2));
// get an unexisting item
assertNull(tempInfo.get(3));
}
@Test
publicvoid testCount(){
Info tempInfo =newInfo();
/ ...
Use the following data set that compares age to average years lef.docxdickonsondorris
Use the following data set that compares age to average "years left to live" to answer the following questions.
Age 10 20 30 40 50 60 70 80 90 100
Years to live 59.2 49.6 40.7 31.9 24.0 17.2 11.6 7.2 4 .4 2.8
a) Show the scatterplot for this data with the least squares regression line. Find R^2. How much of the variation is explained by the regression line?
b) Experiment with the non-linear regressions available on the calculator. Which seem to fit? Show the scatterplot with three different regression curves from the calculator. Label each equation, as well as the applicable R^2.
c) Choose a regression equation to predict how many "years left" a person has if he is now 101 years old. Can he count on celebrating Christmas 2015?
InfoTest.javaInfoTest.javapackage assignment1;
importstatic org.junit.Assert.*;
import org.junit.Test;
publicclassInfoTest{
@Test
publicvoid testInfo(){
Info tempInfo =newInfo();
assertNotNull(tempInfo.tmp);
}
@Test
publicvoid testInsert(){
Info tempInfo =newInfo();
// Insert into an empty list
tempInfo.insert(30);
assertEquals(30, tempInfo.get(0));
// Insert an item to be placed at the beginning of the list
tempInfo.insert(4);
assertEquals(4, tempInfo.get(0));
assertEquals(30, tempInfo.get(1));
// Insert an item to be placed at the end of the list
tempInfo.insert(20);
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
// Insert an which already exists
tempInfo.insert(20);
assertEquals(4, tempInfo.get(0));
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
}
@Test
publicvoid testDelete(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// delete from the middle
tempInfo.delete(10);
assertEquals(5, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the beginning
tempInfo.insert(10);
tempInfo.delete(5);
assertEquals(10, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the end
tempInfo.insert(5);
tempInfo.delete(15);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
// delete something that does not exist
tempInfo.insert(15);
tempInfo.delete(7);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(1));
}
@Test
publicvoid testGet(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// get items at the beginning, middle, and end of the list
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(2));
// get an unexisting item
assertNull(tempInfo.get(3));
}
@Test
publicvoid testCount(){
Info tempInfo =newInfo();
/ ...
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
java I am trying to run my code but it is not letting me .pdfadinathassociates
java
I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so
much for your help. This is the problem and my code will be on the bottom.
Problem #1 and Only
Dynamic Array of Integers Class
Create a class named DynamicArray that will have convenient functionality similar to JavaScripts
Array object and Javas ArrayList class. The class allows to store array of integers that can grow
and shrink as needed, search for values, remove elements, etc.
You are not allowed to use ArrayList object as well as any methods from java.util.Arrays
class.
Please see the list of required features and methods below.
private int array[] You MUST store the data internally in a regular partially-filled array of integers.
Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be
discussed below.
private int size. This variable stores the number of occupied elements in the array. Set to 0 in the
constructor.
Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates
array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0
or negative, IllegalArgumentException is being thrown.
No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to
0.
Copy constructor. The constructor takes an object of type DynamicArray as a parameter and
copies it into the object it creates. The constructor throws IllegalArgumentException if the object
that was passed to copy from is null.
int getSize() returns the number of occupied elements in the array.
int getCapacity() returns the actual size (length) of the partially-filled array
int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the
private array field, make a copy of it.
int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO
NOT return the private array field. Instead, allocate memory for the new array, copy the occupied
portion of the field into that new object, and return the new array.
public void push(int num) adds a new element to the end of the array and increments the size
field. If the array is full, you need to increase the capacity of the array:
Create a new array with the size equal to double the capacity of the original one.
Copy all the elements from the array field to the new array.
Add the new element to the end of the new array.
Use new array as an array field.
Make sure your method works well when new elements are added to an empty DynamicArray.
public int pop() throws RuntimeException removes the last element of the array and returns it.
Decrements the size field. If the array is empty a RuntimeException with the message Array is
empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger
than the number of occupied elements (size), it is time to shrink the array:
Create a new array wi.
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfstopgolook
In C++ please, do not alter node.h
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new
node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
77 15 -42 63.5
then output is:
List after inserting 77:
77 List after inserting 15:
15 77
List after inserting -42:
-42 15 77
List after inserting 63.5:
-42 15 63.5 77
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
84 72 19 61 19 84
then output is:
List after inserting 84:
84
List after inserting 72:
72 84
List after inserting 19:
19 72 84
List after inserting 61:
19 61 72 84
List after removing 19:
61 72 84
List after removing 84:
61 72
Code below:
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = Space.
Create a Dynamic Array container with this user interface Ge.pdfsktambifortune
Create a \"Dynamic Array\" container with this user interface: // Gets the current number of
entries in container int getCurrentSize() // Returns the current capacity of the container int
capacity() // Checks whether the container is empty. boolean isEmpty() // Adds a new entry to
the container boolean insert(newEntry) // Removes an entry from the container and moves all
entries above anEntry down one boolean remove(anEntry) // Get index value int getValue(index)
// Removes all entries from the container void clear() // Resize a container by doubling current
capacity int resize() * Implement dynamic resizing using this algorithm: 1. Starting with a
dynamic size of 10, if the number of elements exceed this number: a. Reallocate the container
size to double the current size b. Move the contents of the current container to the newly sized
container c. Delete the previously sized container. Resize C++ Data* ptemp = new
Data[capacity*2 ]; for (int i=0; i
Solution
container.cpp ---
#include
#include
using namespace std;
template
class DynamicArray
{
/*
Container class DynamicArray
*/
private:
ArrayType *arr;
int entry,size;
public:
DynamicArray();
~DynamicArray();
int getCurrentSize() { return entry; };/*this function returns total number of entries in the
container*/
int capacity() { return size; };/*this function returns capacity of the container*/
bool isEmpty();
bool insert(ArrayType);
bool remove(ArrayType);
int getValue(ArrayType);
void clear() { entry = 0; };/*this function clears the whole container*/
int resize();
};
template
int DynamicArray::resize()
{
/*this function resizes the container by doubling its previous size*/
ArrayType *temp = NULL;
try
{
temp = new ArrayType [2 * size];
}catch(bad_alloc xa){
cout<<\"\ Array allocation failed\ \";
exit(1);
}
size *= 2;
for(int i = 0 , j = 0 ; i < entry ; i++)
{
temp[i] = arr[i];
j++;
}
delete [] arr;
arr = NULL;
arr = temp , temp = NULL;
return size;
}
template
int DynamicArray::getValue(ArrayType index)
{
/*this function return index of an element specified as index in the container if it presents
in the container, else it returns -1*/
int loc = -1;
for(int i = 0 ; i < entry ; i++)
{
if(arr[i] == index)
{
loc = i;
break;
}
}
return loc;
}
template
bool DynamicArray::remove(ArrayType anEntry)
{
/*this function removes an element specified as anEntry from the container and returns true
and
decrements total number of entries by one else returns false*/
bool flag = false;
int index = -1;
for(int i = 0 ; i < entry ; i++)
{
if(arr[i] == anEntry)
{
index = i , flag = true;
break;
}
}
for(int i = index ; i < (entry - 1) && flag == true ; i++)
{
arr[i] = arr[i+1];
}
if(flag == true)
entry -= 1;
return flag;
}
template
bool DynamicArray::insert(ArrayType newEntry)
{
/*this function inserts an element specified as newEntry in the container,
if it successfully inserts an element then it returns true and increments total
number of entries by one, else it returns false*/
entry += 1;
if(entry <= size)
{
ar.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
More Related Content
Similar to vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
Need done for Date Structures please!
4.18 LAB: Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number.
java I am trying to run my code but it is not letting me .pdfadinathassociates
java
I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so
much for your help. This is the problem and my code will be on the bottom.
Problem #1 and Only
Dynamic Array of Integers Class
Create a class named DynamicArray that will have convenient functionality similar to JavaScripts
Array object and Javas ArrayList class. The class allows to store array of integers that can grow
and shrink as needed, search for values, remove elements, etc.
You are not allowed to use ArrayList object as well as any methods from java.util.Arrays
class.
Please see the list of required features and methods below.
private int array[] You MUST store the data internally in a regular partially-filled array of integers.
Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be
discussed below.
private int size. This variable stores the number of occupied elements in the array. Set to 0 in the
constructor.
Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates
array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0
or negative, IllegalArgumentException is being thrown.
No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to
0.
Copy constructor. The constructor takes an object of type DynamicArray as a parameter and
copies it into the object it creates. The constructor throws IllegalArgumentException if the object
that was passed to copy from is null.
int getSize() returns the number of occupied elements in the array.
int getCapacity() returns the actual size (length) of the partially-filled array
int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the
private array field, make a copy of it.
int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO
NOT return the private array field. Instead, allocate memory for the new array, copy the occupied
portion of the field into that new object, and return the new array.
public void push(int num) adds a new element to the end of the array and increments the size
field. If the array is full, you need to increase the capacity of the array:
Create a new array with the size equal to double the capacity of the original one.
Copy all the elements from the array field to the new array.
Add the new element to the end of the new array.
Use new array as an array field.
Make sure your method works well when new elements are added to an empty DynamicArray.
public int pop() throws RuntimeException removes the last element of the array and returns it.
Decrements the size field. If the array is empty a RuntimeException with the message Array is
empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger
than the number of occupied elements (size), it is time to shrink the array:
Create a new array wi.
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfstopgolook
In C++ please, do not alter node.h
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new
node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
77 15 -42 63.5
then output is:
List after inserting 77:
77 List after inserting 15:
15 77
List after inserting -42:
-42 15 77
List after inserting 63.5:
-42 15 63.5 77
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
84 72 19 61 19 84
then output is:
List after inserting 84:
84
List after inserting 72:
72 84
List after inserting 19:
19 72 84
List after inserting 61:
19 61 72 84
List after removing 19:
61 72 84
List after removing 84:
61 72
Code below:
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = Space.
Create a Dynamic Array container with this user interface Ge.pdfsktambifortune
Create a \"Dynamic Array\" container with this user interface: // Gets the current number of
entries in container int getCurrentSize() // Returns the current capacity of the container int
capacity() // Checks whether the container is empty. boolean isEmpty() // Adds a new entry to
the container boolean insert(newEntry) // Removes an entry from the container and moves all
entries above anEntry down one boolean remove(anEntry) // Get index value int getValue(index)
// Removes all entries from the container void clear() // Resize a container by doubling current
capacity int resize() * Implement dynamic resizing using this algorithm: 1. Starting with a
dynamic size of 10, if the number of elements exceed this number: a. Reallocate the container
size to double the current size b. Move the contents of the current container to the newly sized
container c. Delete the previously sized container. Resize C++ Data* ptemp = new
Data[capacity*2 ]; for (int i=0; i
Solution
container.cpp ---
#include
#include
using namespace std;
template
class DynamicArray
{
/*
Container class DynamicArray
*/
private:
ArrayType *arr;
int entry,size;
public:
DynamicArray();
~DynamicArray();
int getCurrentSize() { return entry; };/*this function returns total number of entries in the
container*/
int capacity() { return size; };/*this function returns capacity of the container*/
bool isEmpty();
bool insert(ArrayType);
bool remove(ArrayType);
int getValue(ArrayType);
void clear() { entry = 0; };/*this function clears the whole container*/
int resize();
};
template
int DynamicArray::resize()
{
/*this function resizes the container by doubling its previous size*/
ArrayType *temp = NULL;
try
{
temp = new ArrayType [2 * size];
}catch(bad_alloc xa){
cout<<\"\ Array allocation failed\ \";
exit(1);
}
size *= 2;
for(int i = 0 , j = 0 ; i < entry ; i++)
{
temp[i] = arr[i];
j++;
}
delete [] arr;
arr = NULL;
arr = temp , temp = NULL;
return size;
}
template
int DynamicArray::getValue(ArrayType index)
{
/*this function return index of an element specified as index in the container if it presents
in the container, else it returns -1*/
int loc = -1;
for(int i = 0 ; i < entry ; i++)
{
if(arr[i] == index)
{
loc = i;
break;
}
}
return loc;
}
template
bool DynamicArray::remove(ArrayType anEntry)
{
/*this function removes an element specified as anEntry from the container and returns true
and
decrements total number of entries by one else returns false*/
bool flag = false;
int index = -1;
for(int i = 0 ; i < entry ; i++)
{
if(arr[i] == anEntry)
{
index = i , flag = true;
break;
}
}
for(int i = index ; i < (entry - 1) && flag == true ; i++)
{
arr[i] = arr[i+1];
}
if(flag == true)
entry -= 1;
return flag;
}
template
bool DynamicArray::insert(ArrayType newEntry)
{
/*this function inserts an element specified as newEntry in the container,
if it successfully inserts an element then it returns true and increments total
number of entries by one, else it returns false*/
entry += 1;
if(entry <= size)
{
ar.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
1. Vectors
Vector implements a DYNAMIC ARRAY.
Vectors can hold objects of any type and any number.
Vector class is contained in java.util package
Vector is different from ARRAY in two ways:-
1. Vector is synchronized.
2. It contains many legacy methods that are not part of the collection
framework. 1. Enumeration.
2. Iterator
2. Declaring VECTORS
Vector list = new Vector();
Vector list = new Vector(int size);
Vector list = new Vector(int size, int incr);
Creates a default vector, which has
an initial size 10.
Creates a vector, whose initial
capacity is specified by size.
Creates a vector, whose initial capacity is specified
by size and whose increment is specified by incr.
3. Vectors (Contd….)
A vector can be declared without specifying any size explicitly.
A vector without size can accommodate an unknown number of
items.
Even when size is specified, this can be overlooked and a different
number of items may be put into the vector
In contrast, An ARRAY must have its size
specified.
4. Sr.no Method Discription
1
void add(int index, Object
element)
Inserts the specified element at the specified position in this
Vector.
2 boolean add(Object o) Appends the specified element to the end of this Vector.
3 boolean addAll(Collection c)
Appends all of the elements in the specified Collection to the end
of this Vector, in the order that they are returned by the specified
Collection's Iterator.
4 void addElement(Object obj)
Adds the specified component to the end of this vector, increasing
its size by one.
5 int capacity() Returns the current capacity of this vector.
6 void clear() Removes all of the elements from this Vector.
7
void copyInto(Object[]
anArray)
Copies the components of this vector into the specified array.
8 Object elementAt(int index) Returns the component at the specified index.
9 boolean equals(Object o) Compares the specified Object with this Vector for equality.
10 Object firstElement() Returns the first component (the item at index 0) of this vector.
5. import java.util.*;
public class VectorDemo {
public static void main(String args[]) {
Vector v = new Vector(3, 2); // initial size is 3, increment is 2
System.out.println("Initial size: " + v.size());
System.out.println("Initial capacity: " +v.capacity());
v.addElement(new Integer(2));
System.out.println("Capacity after four additions: " + v.capacity());
v.addElement(new Double(5.45));
System.out.println("Current capacity: " + v.capacity());
System.out.println("First element: " + v.firstElement());
System.out.println("Last element: " +v.lastElement());
}
}
Example
6. Wrapper Classes
Most of the objects collection store objects and not
primitive types.
Primitive types can be used as object when required.
As they are objects, they can be stored in any of the
collection and pass this collection as parameters to
the methods.
7. Wrapper Class
Wrapper classes are classes that allow primitive types to
be accessed as objects.
Wrapper class is wrapper around a primitive data type
because they "wrap" the primitive data type into an object
of that class.
8. What is Wrapper Class?
Each of Java's eight primitive data types has a class dedicated to it.
They are one per primitive type.
Wrapper classes make the primitive type data to act as objects.
Simple Type Wrapper class
boolean Boolean
char Character
double Double
float Float
int Integer
long Long
short Short
byte Byte
9. Difference b/w Primitive Data Type and
Object of a Wrapper Class
The following two statements illustrate the difference between a
primitive data type and an object of a wrapper class:
int x = 25;
Integer y = new Integer(33);
Clearly x and y differ by more than their values:
• x is a variable that holds a value;
• y is an object variable that holds a reference to an object.
So, the following statement using x and y as declared above is not allowed:
int z = x + y; // wrong!
10. The data field in an Integer object is only accessible using
the methods of the Integer class.
One such method is intValue() method which returns an int
equal to the value of the object, effectively "unwrapping" the
Integer object:
int z = x + y.intValue(); // OK!
11. Boxing and Unboxing
The wrapping is done by the compiler.
if we use a primitive where an object is expected, the compiler boxes the primitive in its
wrapper class.
Similarly, if we use a number object when a primitive is expected, the compiler un-
boxes the object.
Example of boxing and unboxing:
Integer x, y; x = 12; y = 15; System.out.println(x+y);
When x and y are assigned integer values, the compiler boxes the integers
because x and y are integer objects.
In the println() statement, x and y are unboxed so that they can be added as
integers.
12. Integer Class
Constructors:
Integer(i) : constructs an Integer object equivalent to the integer i
Integer(s) : constructs an Integer object equivalent to the string s
Integer Class Methods:
parseInt(s) : returns a signed decimal integer value equivalent to
string s
toString(i) : returns a new String object representing the integer i
13. parseInt(s) returns a signed decimal integer value equivalent to string s
toString(i) returns a new String object representing the integer i
byteValue() returns the value of this Integer as a byte
doubleValue() returns the value of this Integer as an double
floatValue() returns the value of this Integer as a float
intValue() returns the value of this Integer as an int
shortValue() returns the value of this Integer as a short
longValue() returns the value of this Integer as a long
int compareTo(int i) Compares the numerical value of the invoking object with that of i. Returns 0 if the
values are equal. Returns a negative value if the invoking object has a lower value.
Returns a positive value if the invoking object has a greater value.
static int compare(int
num1, int num2)
Compares the values of num1 and num2. Returns 0 if the values are equal. Returns
a negative value if num1 is less than num2. Returns a positive value if num1 is
greater than num2.
boolean equals(Object
intObj)
Returns true if the invoking Integer object is equivalent to intObj. Otherwise, it
returns false
14. valueOf (), toHexString(), toOctalString() and
toBinaryString() Methods:
This is another approach to create wrapper objects.
We can convert from binary or octal or hexadecimal before
assigning value to wrapper object using two argument
constructor.
Below program explains the method in details.
15. public class ValueOfDemo {
public static void main(String[] args) {
Integer intWrapper = Integer.valueOf("12345");
//Converting from binary to decimal.
Integer intWrapper2 = Integer.valueOf("11011", 2);
//Converting from hexadecimal to decimal.
Integer intWrapper3 = Integer.valueOf("D", 16);
System.out.println("Value of intWrapper Object: "+ intWrapper);
System.out.println("Value of intWrapper2 Object: "+ intWrapper2);
System.out.println("Value of intWrapper3 Object: "+ intWrapper3);
System.out.println("Hex value of intWrapper: " +
Integer.toHexString(intWrapper));
System.out.println("Binary Value of intWrapper2: "+
Integer.toBinaryString(intWrapper2));
}}
16. Character Class
Character is a wrapper around a char.
The constructor for Character is :
Character(char ch)
Here, ch specifies the character that will be wrapped by the
Character object being created.
To obtain the char value contained in a Character object,
callncharValue( ), shown here:
char charValue( );
It returns the encapsulated character.
17. Converting primitive numbers to Object numbers
Constructor calling Conversion Action
Integer IntVal = new Integer(i); Primitive integer to Integer object
Float FloatVal = new Float(f); Primitive float to Float object
Double DoubleVal = new Double(d); Primitive double to Double object
Long LongVal = new Long(l); Primitive long to Long object
using constructor methods
18. Converting Object numbers to Primitive numbers
Method calling Conversion Action
int i = IntVal.intValue(); Object to primitive integer
float f = FloatVal.floatValue(); Object to primitive float
double d = DoubleVal.doubleValue(); Object to primitive double
long l = LongVal.longValue(); Object to primitive long
using typeValue() method
19. Converting Numbers to Strings
Method calling Conversion Action
str = Integer.toString(i); Primitive integer i to String str
str = Float.toString(f); Primitive float f to String str
str = Double.toString(d); Primitive double d to String str
str = Long.toString(l); Primitive long l to String str
using toString() method
20. Converting String Object in to Numeric Object
Method calling Conversion Action
IntVal = Integer.ValueOf(str); Convert String into Integer object
FloatVal = Float.ValueOf(str); Convert String into Float object
DoubleVal = Double.ValueOf(str); Convert String into Double object
LongVal = Long.ValueOf(str); Convert String into Long object
using static method ValueOf()
21. Converting Numeric Strings to Primitive numbers
Method calling Conversion Action
int i = Integer.parseInt(str); Converts String str into primitive integer i
long l = Long.parseLong(str); Converts String str into primitive long l
using Parsing method
22. public class WrapperDemo {
public static void main (String args[]){
Integer intObj1 = new Integer (25);
Integer intObj2 = new Integer ("25");
Integer intObj3= new Integer (35);
//compareTo demo
System.out.println("Comparing using compareTo Obj1 and Obj2: " + intObj1.compareTo(intObj2));
System.out.println("Comparing using compareTo Obj1 and Obj3: " + intObj1.compareTo(intObj3));
//Equals demo
System.out.println("Comparing using equals Obj1 and Obj2: " + intObj1.equals(intObj2));
System.out.println("Comparing using equals Obj1 and Obj3: " + intObj1.equals(intObj3));
Float f1 = new Float("2.25f");
Float f2 = new Float("20.43f");
Float f3 = new Float(2.25f);
System.out.println("Comparing using compare f1 and f2: " +Float.compare(f1,f2));
System.out.println("Comparing using compare f1 and f3: " +Float.compare(f1,f3));
//Addition of Integer with Float
Float f = intObj1.floatValue() + f1;
System.out.println("Addition of intObj1 and f1: "+ intObj1 +"+" +f1+"=" +f );
} }