Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I get the program to access my numbers document? also I have this code but I dont know how to copy to dev

How do I get the program to access my numbers document? also I have this code but I dont know how to copy to dev c ++ to get it to work, I tried creating 3 different source files labeling them accordingly but got an error saying "stdax." no such file in directory. So I cant run it, and I tried using another code on here but it wouldnt access the number document (keep in mind i dont know anything about files i/o)#include "stdafx.h"
#include "List.h"
#include **=
------------
// LinkedList.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "List.h"
#include
#include
#include
using namespace std;
int main()
{
List * list = new List();
string line;
ifstream myfile("numbers.txt");
if (myfile.is_open())
{
while (getline(myfile, line))
{
list->Insert(stod(line));
}
myfile.close();
}
else cout "Unable to open file";
list->Display();
list->DeletNegative();
list->Display();
int index;
cout "Enter index to insert : ";
cin >> index;
double num;
cout "Enter number to insert : ";
cin >> num;
list->Insert(index, num);
list->Display();
cout "Enter index to delete : ";
cin >> index;
list->Delete(index);
list->Display();
return 0;
}
List.cpp: -------------------------------
#include
#include "List.h"
#include
using namespace std;
List::List()
{
}
List::~List()
{
}
void List::Insert(int index, double value)
{
int count =1;
Node * node = root;
Node * parent = root;
if (node == NULL && index >1)
{
return;
};
if (node == NULL && index ==1)
{
Node * newnode = new Node();
newnode->data = value;
newnode->next = NULL;
node->next = newnode;
return;
}
if (node != NULL && index ==1)
{
Node * newnode = new Node();
newnode->data = value;
newnode->next = node;
root = newnode;
return;
}
while (node->next != NULL )
{
parent = node;
node = node->next;
count++;
if (count == index)
break;
}
if (count != index)
{
cout "invalid index" endl;
return;
}
if (node != NULL)
{
Node * newnode = new Node();
newnode->data = value;
newnode->next = NULL;
newnode->next = node;
parent->next = newnode;
return;
}
}
void List::Insert(double value)
{
Node * node = root;
if (node == NULL)
{
root = new Node();
root->data = value;
root->next = NULL;
return;
};
while (node->next != NULL)
{
node = node->next;
}
Node * newnode = new Node();
newnode->data = value;
newnode->next = NULL;
node->next = newnode;
return;
}
void List::Delete(int index)
{
int count =1;
Node * node = root;
Node * parent = root;
if (node == NULL && index >1)
{
cout "invalid index" endl;
return;
};
if (node != NULL && index ==1)
{
root = node->next;
return;
}
while (node->next != NULL)
{
parent = node;
node = node->next;
count++;
if (count == index)
break;
}
if (count != index)
{
cout "invalid index" endl;
return;
}
if (node != NULL)
{
parent->next = node->next;
return;
}
}
void List::Display()
{
Node * node = root;
if (node == NULL) return;
while (node->next != NULL )
{
cout node->data endl;
node = node->next;
}
cout node->data endl;
return;
}
void List::DeletNegative()
{
Node * node = root;
Node * parent = root;
if (node == NULL) return;
while (node->next != NULL)
{
if (node->data 0)
{
parent->next = node->next;
}
parent = node;
node = node->next;
}
return;
}
List.h: -----------------------------------------
#pragma once
struct Node {
double data;
struct Node *next;
};
class List
{
public:
List();
~List();
void Insert(int index, double value);
void Insert(double value);
void Delete(int index);
void Display();
void DeletNegative();
private:
Node * root;
};
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago