forked from uva-cs/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svtest.cpp.html
55 lines (43 loc) · 4.75 KB
/
svtest.cpp.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>svtest.cpp</title>
</head>
<body style="background-color:white">
<pre><b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><string></span>
<i><span style="color:#9A1900">// svutil is a library to support string-vectors, i.e. vector<string></span></i>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"svutil.h"</span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Exercise the svutil library by defining some vector<string> objects and</span></i>
<i><span style="color:#9A1900">// calling operations on them.</span></i>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<span style="color:#008080">vector<string></span> cs216Section1<span style="color:#990000">,</span> cs216Section2<span style="color:#990000">;</span>
cs216Section1<span style="color:#990000">.</span><b><span style="color:#000000">push_back</span></b><span style="color:#990000">(</span><span style="color:#FF0000">"Alex"</span><span style="color:#990000">);</span>
cs216Section1<span style="color:#990000">.</span><b><span style="color:#000000">push_back</span></b><span style="color:#990000">(</span><span style="color:#FF0000">"Jodi"</span><span style="color:#990000">);</span>
cs216Section1<span style="color:#990000">.</span><b><span style="color:#000000">push_back</span></b><span style="color:#990000">(</span><span style="color:#FF0000">"Kit"</span><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Section contains: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">svOutput</span></b><span style="color:#990000">(</span>cs216Section1<span style="color:#990000">);</span>
<span style="color:#008080">string</span> name<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Enter student name: "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> name<span style="color:#990000">;</span>
<span style="color:#009900">int</span> posn <span style="color:#990000">=</span> <b><span style="color:#000000">svFind</span></b><span style="color:#990000">(</span>cs216Section1<span style="color:#990000">,</span> name<span style="color:#990000">);</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span> posn <span style="color:#990000">==</span> <span style="color:#990000">-</span><span style="color:#993399">1</span> <span style="color:#990000">)</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Student not found in section."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">else</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Found student at index "</span> <span style="color:#990000"><<</span> posn <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span> <b><span style="color:#000000">svDeleteAt</span></b><span style="color:#990000">(</span>cs216Section1<span style="color:#990000">,</span> posn<span style="color:#990000">)</span> <span style="color:#990000">)</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Deleted student from section!"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Final section contents are:"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">svOutput</span></b><span style="color:#990000">(</span>cs216Section1<span style="color:#990000">);</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>