-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
146 lines (116 loc) · 3.71 KB
/
Copy pathMain.cpp
File metadata and controls
146 lines (116 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <cmath>
#include "Node.h"
#include "NodeList.h"
#include "Resistor.h"
#include "ResistorList.h"
#define MIN_ITERATION_CHANGE 0.0001
using namespace std;
/*
> NodeList should be an object containing a linked list of Nodes
> Nodes should be objects each connecting to each other in increasing order
> Node should also point to an object ResistorList
> ResistorList should be an object containing a linked list of Resistors
> Resistor objects should point to each other in order of insertion
*/
int main(int argc, char const *argv[]) {
//listNode Nodehead;
NodeList nlist;
string command = "", name = "";
double voltage = 0;
int id;
string line = "", node1 = "", node2 = "", resis = "";
int node1num = 0, node2num = 0;
char arg = '\0';
double resisNum = 0.0;
int rID = 0;
cout << "> ";
getline(cin,line);
while(!cin.eof()){
//get to command from user
stringstream lineStream (line);
lineStream >> command;
//insert resistor command
if(command == "insertR"){
lineStream >> name >> resis >> node1 >> node2 >> arg;
stringstream lineStream2 (node1);
lineStream2 >> node1num;
stringstream lineStream3 (node2);
lineStream3 >> node2num;
stringstream lineStream4 (resis);
lineStream4 >> resisNum;
nlist.insertNode(name,resisNum,node1num,node2num);
}
//modify resistor command
else if(command == "modifyR"){
lineStream >> name >> resis >> arg;
stringstream lineStream4 (resis);
lineStream4 >> resisNum;
//need to find nodes which the resistor attaches to
nlist.modifyResistor(name,resisNum);
}
//delete resistor command
else if(command == "deleteR"){
lineStream >> name >> arg;
if(name == "all")
nlist.deleteNLAll();
else
nlist.deleteNL(name);
}
//print resistor command
else if(command == "printR"){
lineStream >> name >> arg;
nlist.printr(name);
}
//print node command
else if(command == "printNode"){
lineStream >> node1 >> arg;
stringstream lineStream2 (node1);
lineStream2 >> node1num;
if(node1 == "all")
nlist.print();
else
nlist.printn(node1num);
}
//set voltage command
else if(command == "setV"){
lineStream >> node1 >> voltage;
stringstream lineStream2 (node1);
lineStream2 >> node1num;
nlist.setV(node1num, voltage);
}
//unset voltage commmand
else if(command == "unsetV"){
lineStream >> node1 >> arg;
stringstream lineStream2 (node1);
lineStream2 >> node1num;
nlist.unsetV(node1num);
}
//solve command
else if(command == "solve"){
nlist.solve();
}
//otherwise say "invalid argument"
else
cout << "Invalid argument" << endl;
//reinitialize variables and receive next line of input
cout << "> ";
line = "";
command = "";
getline (cin, line);
//reinitialize all variables coming from stringstream
arg = '\0';
name = "", node1 = "", node2 = "", resis = "";
node1num = 0, node2num = 0, resisNum = 0.0;
}
/*function deletes all resistors in ResistorList, ResistorList object in
nodes as well as all nodes*/
nlist.deleteNLAll2();
return 0;
}