Overview

In this lab, you will get practice using libraries to deal with real-world data files, and along the way you will get more practice using structs as well.

This lab introduces lots of new ideas and skills. Reading the lab instructions with extreme care and repetition is expected.

Before you begin

Submission

~/bin/submit -c=IC210 -p=lab09 part*.cpp 

Another input stream: istringstream

You can create an input stream from a string. This type istringstream will be useful when you need to analyze a given string.

For example, istringstream allows you to extract strings or numbers from a string.

You are expected to understand the code on the right. Try to compile and run the code (file ex_iss.cpp in the provided files for the lab).


// compile and run this code
// g++ ex_iss.cpp -o ex_iss
#include <iostream>
#include <string>
#include <sstream>    // include this to use istringstream type
using namespace std;

int main()
{
  string s = "hello 100 c world";
  // create an input stream IN based on string s
  istringstream IN(s);  

  string s1, s2;
  int n;
  char c;

  // read data from the input stream IN. 
  IN >> s1 >> n >> c >> s2;

  cout << s1 << endl;
  cout << n << endl;
  cout << c << endl;
  cout << s2 << endl;


  s = "10 20 30 40 50";
  // create a new input stream IN2 based on new string value of s
  istringstream IN2(s);
  while(IN2 >> n)
     cout << n << endl;

  return 0;
}

RSS Feeds

While people use many different apps nowadays to access podcasts, the standard format for podcasts to tell those apps what episodes are available is called RSS.

RSS is part of a family of formats called XML, which you might recognize as kind of similar to HTML documents that are used for web pages. When you untar lab.tar, you will see a few examples of .rss files; feel free to explore them in your text editor.

File ic210.rss

The simplest example is the ic210.rss file, which starts like:

<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <item>
      <title>IC210 Unit 6: Array size and index out of bounds</title>
      <pubDate>Tue, 13 Oct 2020 21:33:58 +0000</pubDate>
      <enclosure url="https://www.youtube.com/watch?v=iiykCJ0mSQM"/>
      <itunes:duration>10:43</itunes:duration>
    </item>
    <item>
      <title>IC210 Unit 4: scanf</title>
      <pubDate>Mon, 14 Sep 2020 04:00:15 +0000</pubDate>
      <enclosure url="https://www.youtube.com/watch?v=1dW72RaseSY"/>
      <itunes:duration>13:50</itunes:duration>
    </item>
    <item>
      <title>IC210: Unit 5: Introduction to functions</title>
      <pubDate>Fri, 25 Sep 2020 18:11:12 +0000</pubDate>
      <enclosure url="https://www.youtube.com/watch?v=OnThYSGJkF8"/>
      <itunes:duration>22:29</itunes:duration>
    </item>
    ...

So you can see, an rss file mostly consists of a number of items. Each item has:

  • a title,
  • publication date,
  • url, and
  • duration.
The other rss files also have much more information than this, but these are the only parts that will be important for this lab.

RSS Library

We provide three code (.h and .cpp) files. Make sure you read these closely and understand how they work.