Question

In: Computer Science

Please fix these errors C++ In file included from main.cpp:14:0: Inventory.h:1:0: error: unterminated #ifndef #ifndef INVENTORY_H_...

Please fix these errors C++

In file included from main.cpp:14:0:
Inventory.h:1:0: error: unterminated #ifndef
 #ifndef INVENTORY_H_
 
main.cpp: In function ‘int main()’:
main.cpp:82:35: error: ‘adds’ was not declared in this scope
                    noun= adds(noun);
                                   ^
main.cpp:88:32: error: ‘display’ was not declared in this scope
                    display(noun);
                                ^
In file included from Inventory.cpp:4:0:
Inventory.h:1:0: error: unterminated #ifndef
 #ifndef INVENTORY_H_

----------------------------------------------------------------------------------

CODE: main.cpp

#include<iostream>
#include<string>
#include<vector>
#include "Inventory.h"

using namespace std;

int main()
{
Node * noun=NULL;
Node * verb=NULL;
int choice=0;
while(choice!=8)
{
cout<<"1. Push Noun\n";
cout<<"2. Pop Noun\n";
cout<<"3. Push Verb\n";
cout<<"4. Pop Verb\n";
cout<<"5. Concatenate\n";
cout<<"6. Add an s\n";
cout<<"7. Display Both Stacks\n";
cout<<"8. Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter a noun: ";
string n;
cin>>n;
noun = push(noun,n);

  
}
break;
case 2:
{
cout<<"NOUN POPPED: ";
Node * t = pop(&noun);
if(t!=NULL)
cout<<t->data<<endl;
}
break;
case 3:
{
cout<<"Enter a verb: ";
string n;
cin>>n;
verb = push(verb,n);
  
}
break;
case 4:
{
cout<<"Verb POPPED: ";
Node * t = pop(&verb);
if(t!=NULL)
cout<<t->data<<endl;
}
break;
case 5: {
cout<<"Top two words on noun stack concatenated\n";
noun = concat(noun);
  
}
break;
case 6:
  
{
cout<<"Add s to the top word on noun stack\n";
noun = adds(noun);
}
break;
case 7:
{
cout<<"NOUN STACK\n";
display(noun);
cout<<"VERB STACK\n";
display(verb);
  
}
case 8:
{
}
break;
default: cout<<"Enter a valid choice\n";
  
}
}
return 0;
}

CODE: Inventory.cpp

#include<iostream>
#include<string>
#include<vector>
#include "Inventory.h"

using namespace std;

//display
void display(Node * head)
{
if(head==NULL)
{
  
return;
}
vector<string> stack;
Node * cur = head;
  
while(cur!=NULL)
{
stack.push_back(cur->data);
cur=cur->next;
}
for(int i = stack.size()-1;i>=0;--i)
{
cout<<stack.at(i)<<" ";
}
cout<<endl;
}

Node * adds(Node *head)
{
Node * top1 = pop(&head);
if(top1!=NULL)
{
//add s
string sol= top1->data + "s";
head=push(head,sol);
}
return head;
}

CODE: inventory.h

#ifndef INVENTORY_H_
#define INVENTORY_H_
#include<iostream>

using namespace std;

class Node
{
public:
string data;
Node * next;
Node()
{
data="";
next=NULL;
}
Node(string data)
{
data=data;
next=NULL;
}
};

Node * push(Node * head, string data)
{
if(head==NULL)
{
head=new Node();
head->data=data;
return head;
}
Node * cur = head;
while(cur->next!=NULL)
{
cur=cur->next;
}
Node * temp = new Node();
temp->data=data;
cur->next=temp;
return head;
}


Node * pop(Node ** h)
{
Node * head = *h;
if(head==NULL)
return NULL;
if(head->next==NULL)
{
  
Node * temp = head;
*h = NULL;
return temp;
}
Node * cur = head;
Node * prev = head;
  
while(cur->next!=NULL)
{
prev=cur;
cur=cur->next;
}
prev->next=NULL;

return cur;
}

Node * concat(Node * head)
{
Node * top1 = pop(&head);
Node * top2 = pop(&head);
  
if(top1!=NULL && top2!=NULL)
{
string solution = top1->data + top2->data;
head= push(head,solution);
  
}
return head;
}

Solutions

Expert Solution

CODE:

main.cpp :

Inventory.cpp :

Inventory.h :

OUTPUT:

RAW CODE:

main.cpp :

#include<iostream>
#include<string>
#include<vector>
#include "Inventory.h"
#include "Inventory.cpp" // add it
using namespace std;

int main()
{
Node * noun=NULL;
Node * verb=NULL;
int choice=0;
while(choice!=8)
{
cout<<"1. Push Noun\n";
cout<<"2. Pop Noun\n";
cout<<"3. Push Verb\n";
cout<<"4. Pop Verb\n";
cout<<"5. Concatenate\n";
cout<<"6. Add an s\n";
cout<<"7. Display Both Stacks\n";
cout<<"8. Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter a noun: ";
string n;
cin>>n;
noun = push(noun,n);

  
}
break;
case 2:
{
cout<<"NOUN POPPED: ";
Node * t = pop(&noun);
if(t!=NULL)
cout<<t->data<<endl;
}
break;
case 3:
{
cout<<"Enter a verb: ";
string n;
cin>>n;
verb = push(verb,n);
  
}
break;
case 4:
{
cout<<"Verb POPPED: ";
Node * t = pop(&verb);
if(t!=NULL)
cout<<t->data<<endl;
}
break;
case 5: {
cout<<"Top two words on noun stack concatenated\n";
noun = concat(noun);
  
}
break;
case 6:
  
{
cout<<"Add s to the top word on noun stack\n";
noun = adds(noun);
}
break;
case 7:
{
cout<<"NOUN STACK\n";
display(noun);
cout<<"VERB STACK\n";
display(verb);
  
}
case 8:
{
}
break;
default: cout<<"Enter a valid choice\n";
  
}
}
return 0;
}

Inventory.cpp :

#include<iostream>
#include<string>
#include<vector>
#include "Inventory.h"
using namespace std;
//display
void display(Node * head)
{
if(head==NULL)
{
return;
}
vector<string> stack;
Node * cur = head;
  
while(cur!=NULL)
{
stack.push_back(cur->data);
cur=cur->next;
}
for(int i = stack.size()-1;i>=0;--i)
{
cout<<stack.at(i)<<" ";
}
cout<<endl;
}

Node * adds(Node *head)
{
Node * top1 = pop(&head);
if(top1!=NULL)
{
//add s
string sol= top1->data + "s";
head=push(head,sol);
}
return head;
}

Inventory.h:

#ifndef INVENTORY_H_
#define INVENTORY_H_
#include<iostream>
using namespace std;
class Node
{
public:
string data;
Node * next;
Node()
{
data="";
next=NULL;
}
Node(string data)
{
data=data;
next=NULL;
}
};
Node * push(Node * head, string data)
{
if(head==NULL)
{
head=new Node();
head->data=data;
return head;
}
Node * cur = head;
while(cur->next!=NULL)
{
cur=cur->next;
}
Node * temp = new Node();
temp->data=data;
cur->next=temp;
return head;
}
Node * pop(Node ** h)
{
Node * head = *h;
if(head==NULL)
return NULL;
if(head->next==NULL)
{
  
Node * temp = head;
*h = NULL;
return temp;
}
Node * cur = head;
Node * prev = head;
  
while(cur->next!=NULL)
{
prev=cur;
cur=cur->next;
}
prev->next=NULL;

return cur;
}

Node * concat(Node * head)
{
Node * top1 = pop(&head);
Node * top2 = pop(&head);
  
if(top1!=NULL && top2!=NULL)
{
string solution = top1->data + top2->data;
head= push(head,solution);
  
}
return head;
}
#endif // add it

NOTE:
If You have any doubts feel free to comment in comment section.
DO VOTE(LIKE).


Related Solutions

C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
> gcc -c lab5.c -lm In file included from lab5.c:8: lab5.h:12: error: expected identifier or ‘(’...
> gcc -c lab5.c -lm In file included from lab5.c:8: lab5.h:12: error: expected identifier or ‘(’ before ‘{’ token > In file included from lab5.c:8: In: Command not found. ]> lab5.h:12: error: expected identifier or ‘(’ before ‘{’ token Too many ('s. > make: *** [lab5.o] Error 1 make:: Too many arguments. #include #include #include #define IN_FILE "lab5.dat" #define OUT_FILE "lab5.txt" /* function prototype */ void find_two_radii (double a, double b, double c, double*radius_inside, double*radius_outside); { *s = 1/2*(a+b+c); *radius_inside...
q7.1 Fix the errors in the code (in C) //This program should read a string from...
q7.1 Fix the errors in the code (in C) //This program should read a string from the user and print it using a character pointer //The program is setup to use pointer offset notation to get each character of the string #include <stdio.h> #include <string.h> int main(void){ char s[1]; scanf(" %c", s); char *cPtr = s[1]; int i=0; while(1){ printf("%c", cPtr+i); i++; } printf("\n"); }
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function...
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a, b, and c, respectively. Write the definition of func2 so that its action is as follows: Prompt the user to input two integers and store the numbers in a and b, respectively. If both of the numbers are nonzero: If a >= b, the value assigned to c is a to the...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define FUNCTIONS_H typedef struct MyStruct { int value; char name[ 100 ]; } MyStruct; void sortArray( MyStruct*, int ); void printArray( MyStruct*, int ); #endif Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like...
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
Please Fix Syntax Error import java.util.Scanner; public class SalaryCalc {    double Rpay = 0, Opay...
Please Fix Syntax Error import java.util.Scanner; public class SalaryCalc {    double Rpay = 0, Opay = 0;    void calPay(double hours, double rate) {        if (hours <= 40) {            Rpay = hours * rate;            Opay = 0;        } else {            double Rhr, Ohr;            Rhr = 40;            Ohr = hours - Rhr;            Rpay = Rhr * rate;   ...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT