#include <iostream>
#include <cstdlib>
using namespace std;
class IntNode {
public:
IntNode(int dataInit = 0, IntNode* nextLoc = nullptr);
void InsertAfter(IntNode* nodeLoc);
IntNode* GetNext();
void PrintNodeData();
int GetDataVal();
private:
int dataVal;
IntNode* nextNodePtr;
};
// Constructor
IntNode::IntNode(int dataInit, IntNode* nextLoc) {
this->dataVal = dataInit;
this->nextNodePtr = nextLoc;
}
/* Insert node after this node.
* Before: this -- next
* After: this -- node -- next
*/
void IntNode::InsertAfter(IntNode* nodeLoc) {
IntNode* tmpNext = nullptr;
tmpNext = this->nextNodePtr; // Remember next
this->nextNodePtr = nodeLoc; // this -- node -- ?
nodeLoc->nextNodePtr = tmpNext; // this -- node -- next
}
// Print dataVal
void IntNode::PrintNodeData() {
cout << this->dataVal << endl;
}
// Grab location pointed by nextNodePtr
IntNode* IntNode::GetNext() {
return this->nextNodePtr;
}
int IntNode::GetDataVal() {
return this->dataVal;
}
int main() {
IntNode* headObj = nullptr; // Create intNode objects
IntNode* currObj = nullptr;
IntNode* lastObj = nullptr;
int i;
headObj = new IntNode(-1); // Front of nodes list
lastObj = headObj;
for (i = 0; i < 20; ++i) { // Append 20 rand nums
currObj = new IntNode(rand());
lastObj->InsertAfter(currObj); // Append curr
lastObj = currObj; // Curr is the new last item
}
currObj = headObj; // Print the list
currObj = currObj->GetNext();
while (currObj != nullptr) {
currObj->PrintNodeData();
currObj = currObj->GetNext();
}
// FIXME: Loop through list and find minimum dataVal
return 0;
}
C++
Step by stepSolved in 2 steps
- food_wastage_record.hpp class FoodWastageRecord {public:void SetDate(const std::string &date);void SetMeal(const std::string &meal);void SetFoodName(const std::string &food_name);void SetQuantityInOz(double qty_in_oz);void SetWastageReason(const std::string &wastage_reason);void SetDisposalMechanism(const std::string &disposal_mechanism);void SetCost(double cost); std::string Date() const;std::string Meal() const;std::string FoodName() const;double QuantityInOz() const;std::string WastageReason() const;std::string DisposalMechanism() const;double Cost() const; private:std::string date_;std::string meal_;std::string food_name_;double qty_in_oz_;std::string wastage_reason_;std::string disposal_mechanism_;double cost_;}; food_wastage_record.cpp #include "food_wastage_record.h" void FoodWastageRecord::SetDate(const std::string &date) { date_ = date; }void FoodWastageRecord::SetMeal(const std::string &meal) { meal_ = meal; }void…arrow_forwardIn C, using malloc to allocate memory for a linked list uses which memory allocation scheme? Heap allocation Static allocationarrow_forwardJava Programming Please do not change anything in Student class or Course class class John_Smith extends Student{ public John_Smith() { setFirstName("John"); setLastName("Smith"); setEmail("jsmith@jaguar.tamu.edu"); setGender("Male"); setPhoneNumber("(200)00-0000"); setJNumber("J0101459"); } class MyCourse extends Course { public MyCourse { class Course { private String courseNumber; private String courseName; private int creditHrs; public Course (String number, String name, int creditHrs){ this.courseNumber = number; this.courseName = name; this.creditHrs = creditHrs; } public String getNumber() { return courseNumber; } public String getName() { return courseName; } public int getCreditHrs() { return creditHrs; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseName(String…arrow_forward
- public class VisitorPackage{// Declare data fields: an int named travelerID, // a String named destination, and // a double named totalCost.// Your code here... // Implement the default contructor.// Set the value of destination to N/A, and choose an // appropriate value for the other data fields,// Your code here... // Implement the overloaded constructor that passes new// values to all data fields.// Your code here... // Implement method getTotalCost to return the totalCost.// Your code here... // Implement method applyDiscount.//// This method applies a discount off of the total cost// of the tour. The way the discount is applied depends// on the kind of visitor.//// Child discount: the unit discount is subtracted ONCE// from the total cost of the tour.// Senior discount: the unit discount is subtracted TWICE// from the total cost of the tour.// Parameters:// - a char to indicate the kind of visitor// ('c' for child, 's' for senior)// - a double that indicates the amount of the…arrow_forward#include <iostream>using namespace std;class Player{private:int id;static int next_id;public:int getID() { return id; }Player() { id = next_id++; }};int Player::next_id = 1;int main(){Player p1;Player p2;Player p3;cout << p1.getID() << " ";cout << p2.getID() << " ";cout << p3.getID();return 0;} Run the program and give its output.arrow_forward#ifndef LLCP_INT_H#define LLCP_INT_H #include <iostream> struct Node{ int data; Node *link;};void DelOddCopEven(Node*& headPtr);int FindListLength(Node* headPtr);bool IsSortedUp(Node* headPtr);void InsertAsHead(Node*& headPtr, int value);void InsertAsTail(Node*& headPtr, int value);void InsertSortedUp(Node*& headPtr, int value);bool DelFirstTargetNode(Node*& headPtr, int target);bool DelNodeBefore1stMatch(Node*& headPtr, int target);void ShowAll(std::ostream& outs, Node* headPtr);void FindMinMax(Node* headPtr, int& minValue, int& maxValue);double FindAverage(Node* headPtr);void ListClear(Node*& headPtr, int noMsg = 0); // prototype of DelOddCopEven of Assignment 5 Part 1 #endifarrow_forward
- // Rectanlge.cppusing namespace std;class Rectangle{ public: // Declare public methods here private: // Create length and width here}; void Rectangle::setLength(double len){ // Write setLength here}void Rectangle::setWidth(double wid){ // write setWidth here}double Rectangle::getLength(){ // write getLength here}double Rectangle::getWidth(){ // write getWidth here}double Rectangle::calculateArea(){ // write calculateArea here}double Rectangle::calculatePerimeter(){ // write calculatePerimeter here} // This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp"#include <iostream>using namespace std; int main(){ // Create Rectangle objects here // Set the lengths and widths here // Print the areas and perimeters here return 0;}arrow_forward#include <iostream> #include <cmath> #include <iomanip> using namespace std; int calc_qty(int qty); void receipt( int qty, int qty2); int calc_qty(int qty); void coffee_size(int qty, int size, int choice, int qty2); void slices(); void beanounces(); int main() { int qty = 0, order = 0, size = 0, qty2 = 0; receipt (qty,qty2); calc_qty (qty); do { //displays the menu cout<<" Please select an item on the menu you would like to buy."<<endl; cout<<"Enter 1 for Coffee\n"<<"Enter 2 for cheese cake\n"<<"Enter 3 for coffee beens\n"<<endl; cin>>choice; } switch (choice) { case 1: coffee_size(qty, size, order, qty2); break; case 2: slices(); break; case 3: beanounces(); break; case 4: cout<<"Enjoy your day"<<endl;…arrow_forwardpublic class Book { protected String title; protected String author; protected String publisher; protected String publicationDate; public void setTitle(String userTitle) { title = userTitle; } public String getTitle() { return title; } public void setAuthor(String userAuthor) { author = userAuthor; } public String getAuthor(){ return author; } public void setPublisher(String userPublisher) { publisher = userPublisher; } public String getPublisher() { return publisher; } public void setPublicationDate(String userPublicationDate) { publicationDate = userPublicationDate; } public String getPublicationDate() { return publicationDate; } public void printInfo() { System.out.println("Book Information: "); System.out.println(" Book Title: " + title); System.out.println(" Author: " + author); System.out.println(" Publisher: " + publisher); System.out.println(" Publication…arrow_forward
- class TenNums {private: int *p; public: TenNums() { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = i; } void display() { for (int i = 0; i < 10; i++) cout << p[i] << " "; }};int main() { TenNums a; a.display(); TenNums b = a; b.display(); return 0;} Continuing from Question 4, let's say I added the following overloaded operator method to the class. Which statement will invoke this method? TenNums TenNums::operator+(const TenNums& b) { TenNums o; for (int i = 0; i < 10; i++) o.p[i] = p[i] + b.p [i]; return o;} Group of answer choices TenNums a; TenNums b = a; TenNums c = a + b; TenNums c = a.add(b);arrow_forward#include <iostream>using namespace std;class Player{private:int id;static int next_id;public:int getID() { return id; }Player() { id = next_id++; }};int Player::next_id = 1;int main(){Player p1;Player p2;Player p3;cout << p1.getID() << " ";cout << p2.getID() << " ";cout << p3.getID();return 0;} Run the program and give its output.arrow_forward#include <iostream>using namespace std;class Player{private:int id;static int next_id;public:int getID() { return id; }Player() { id = next_id++; }};int Player::next_id = 1;int main(){Player p1;Player p2;Player p3;cout << p1.getID() << " ";cout << p2.getID() << " ";cout << p3.getID();return 0;} Run the program and give its output.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education