Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement fgets into this program for the strings. Make sure all of the prints f

ID: 3577385 • Letter: I

Question

Implement fgets into this program for the strings. Make sure all of the prints function correctly.

#include<stdio.h>
#include<stdlib.h>

struct node
{
char car_name[20];
char type;
int model_year;
float car_val;
float sale_price;
struct node *next;
};


void add(struct node** head_ref)
{
struct node* new_node=(struct node*)malloc(sizeof(struct node));
struct node *last=*head_ref;
int year;
float val,saleprice;

printf(" Enter car name: ");
scanf("%s",&new_node->car_name);

printf("Enter car type: ");
scanf(" %c",&new_node->type);

printf("Enter model year: ");
scanf("%d",&year);
new_node->model_year=year;
printf("Enter car value: ");
scanf("%f",&val);
new_node->car_val=val;
printf("Enter car sales price: ");
scanf("%f",&saleprice);
new_node->sale_price=saleprice;
new_node->next=NULL;
if(*head_ref==NULL)
{
  *head_ref=new_node;
  return;
}
while(last->next!=NULL)
{
  last=last->next;
}
last->next=new_node;
return;
}


void deleteCar(struct node**head_ref)
{
char name[20];
printf(" Enter car info: ");
printf(" Enter car name: ");
scanf("%s",&name);

struct node *temp=*head_ref,*prev;
if(temp!=NULL && strcmp(temp->car_name,name)==0)
{
  *head_ref=temp->next;
  free(temp);
  return;
}
while(temp!=NULL && strcmp(temp->car_name,name)!=0)
{
  prev=temp;
  temp=temp->next;
}

if(temp==NULL)
return;
prev->next=temp->next;
free(temp);
}


void printList(struct node * node)
{
if(node==NULL)
printf("No cars added yet.");
while(node!=NULL)
{
  printf(" Car name: %s ",node->car_name);
  printf(" Car type: %c ",node->type);
  printf(" Car model year: %d ",node->model_year);
  printf(" Car value: %f ",node->car_val);
  printf(" Car sales price: %f ",node->sale_price);
  
  node=node->next;
}
}

int main()
{
int op,i=0;
struct node* head=NULL;

while(i!=1)
{
    printf(" 1. See a car's information 2. Add a car 3. Remove a car 4. Generate Report. 5. Exit ");
    printf("Enter your choice: ");
    scanf("%d",&op);
    switch(op)
    {
      case 1:
       printf("Enter car info: ");
       break;
      case 2:
       add(&head);
       break;
      case 3:
       deleteCar(&head);
       break;
      case 4:
       printf("Generating report.....");
       printList(head);
       break;
      case 5:
       i=1;
       break;
      default:
       printf("Enter right option!");
       break;
  }

    }
    return 0;
}

Explanation / Answer

#include &lt;iostream&gt;
02
#include &lt;cstdlib&gt; // for random variety functions
03
#include &lt;ctime&gt; // for clock functions
04
using namespace std;
05

06
#include "DynQueue.h" // needs queue ADT
07

08
double randVal(); // model for random generation perform
09

10
const double NORTH_SOUTH_ARRIVE_FREQ = one.0/10.0; // Prob. of automotive inward every second
11
const double EAST_WEST_ARRIVE_FREQ = one.0/30.0; // Prob. of automotive inward every second
12
const int REDLIGHTON = 120;
13
const int GREENLIGHTON = 360;
14

15
const int SIM_TIME = 3600; // In seconds
16
const int> 17

18
int main()
19
discovered for random variety generator
21
srand(time(0)); // Set seed for random variety to clock
22

23

24
// Variables
25
DynQueue&lt;int&gt; northSouth_q; // north/south queue
26
DynQueue&lt;int&gt; eastWest_q; // east/west queue
27

28
int time; // clock for simulation
29
int i;
30

31

32
int northSouthCars = 0; // Total arrival counter
33
int EastWestCars = 0; // Total departures counter
34

35
// SIMULATION
36
for (time=1;time &lt;= SIM_TIME; time++)
37
  
42
if (randVal() &lt;= EAST_WEST_ARRIVE_FREQ) // New departure
43
  
46
//commented out as a result of i detected that i need the employment of (is empty) however it'd still
47
//i will see however its not getting to work as a result of if it absolutely was not empty it'd still dequeue nothing, or try to
48
// for (i = 0; i &lt;= GREENLIGHTON; i++)
49
//
53
//   
54
// for (i = 0; i &lt;= GREENLIGHTON; i++)
55
//
59

60

61
  
62
}
63
}
64

65
/*************************************************************************/
66
/* This functions returns as random variety between zero.0 and 1.0 */
67
/*************************************************************************/
68
double randVal()
69
come back double(rand()) / double(RAND_MAX);
71
}
template &lt;class ItemType&gt;
002
class DynQueue
003
;
010

011
NodeType *front;
012
NodeType *rear;
013
int numItems;
014
public:
015
DynQueue();
016
~DynQueue();
017
void enqueue(ItemType);
018
ItemType dequeue();
019
bool isEmpty();
020
bool isFull();
021
void clear();
022
};
023

024
#endif
025

026
//==================================================
027
//Implementation for Dynamic Queue category
028
//==================================================
029

030
#include &lt;iostream&gt;
031
using namespace std;
032

033
//************************
034
// creator *
035
//************************
036

037
template &lt;class ItemType&gt;
038
DynQueue&lt;ItemType&gt;::DynQueue()
039

044

045
//************************
046
// Destructor *
047
//************************
048

049
template &lt;class ItemType&gt;
050
DynQueue&lt;ItemType&gt;::~DynQueue()
051

054

055
//********************************************
056
// perform enqueue inserts the worth in num *
057
// at the rear of the queue. *
058
//********************************************
059

060
template &lt;class ItemType&gt;
061
void DynQueue&lt;ItemType&gt;::enqueue(ItemType item)
062

073
else
074
  
078
numItems++;
079
}
080

081
//**********************************************
082
// perform dequeue removes the worth at the *
083
// front of the queue, and copies it into num. *
084
// PRECONDITION: Queue isn't empty *
085
//**********************************************
086

087
template &lt;class ItemType&gt;
088
ItemType DynQueue&lt;ItemType&gt;::dequeue()
089
temporary worker = front;
095
front = front-&gt;next;
096
delete temp;
097
numItems--;
098
come back returnItem;
099
}
100

101
//*********************************************
102
// perform isEmpty returns true if the queue *
103
// is empty, and false otherwise. *
104
//*********************************************
105

106
template &lt;class ItemType&gt;
107
bool DynQueue&lt;ItemType&gt;::isEmpty()
108
standing = false;
113
else
114
standing = true;
115
come back status;
116
}
117

118
//****************************************************
119
// Member perform isFull is assumed to be false. *
120
// Tailor to native operational atmosphere. *
121
//****************************************************
122

123
template &lt;class ItemType&gt;
124
bool DynQueue&lt;ItemType&gt;::isFull()
125
{
126
come back false;
127
}
128

129
//********************************************
130
// perform clear dequeues all the weather *
131
// within the queue. *
132
//********************************************
133

134
template &lt;class ItemType&gt;
135
void DynQueue&lt;ItemType&gt;::clear()
136
worth = dequeue();
141
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote