Property List Project, Part 0

Introduction

This assignment is due by midnight of your class date for Week 4 (9/24; 9/27).

Write a C++ program that prompts the user to enter a name and a value, and enters each pair into an array of structs. Each name is to be any string the user wishes to type, but may not contain spaces. The value is to be an int.

If the user types "exit" as a name, the program is to exit. If the user types "show <n>" (where <n> is an integer), the program is to display the name and value pair at entry number <n> in the array, if there is one; otherwise display an error message. The program continues to run after "show" commands.

Here is a partial implementation of the program for you to start with:

 
#include <iostream.h>
#include <string.h>
 
struct element {
 
  char  name[100];
  int   value;
 
  };
 
int
main() {
 
element theArray[1000];
 
  for (int i = 0; i < 1000; i++) {
 
    cout << "Enter a name and its value: ";
    cin >> theArray[i].name >> theArray[i].value;
 
    if (0 == strcasecmp(theArray[i].name, "exit")) return 0;
 
    }
 
  }
[In the Tuesday section I used "if (!strcmp(... " instead of "if (0 == strcasecmp( ...". strcasecmp() does a case-insensitive comparison. That is, the user can type "Exit" or "exit" (or "ExIt", etc.) and the comparison will come out equal. The "0 ==" in place of "!" is just a little less obscure, I think.]

This program may be written as a single .cc source file. You do not have to use a Makefile. Nor are you required to define any functions other than main() for this program.

Here are some things for you to think about as you write your program. You are not required to implement any of the items listed here, and you are not to hand in answers to these questions. Just think about them! (If you do deal with any of these items in your program, leave a README file in your project directory telling me about them.)



Dr. Christopher Vickery
Computer Science Department
Queens College of CUNY
Home Page