Would anyone please write the following program:
- Code: Select all
Design a structure called car that holds the following information about an automobile:
its make, as a string in a character array or in a string object, and the year it was built,
as an integer. Write a program that asks the user how many cars to catalog. The program
should then use new to create a dynamic array of that many car structures. Next, it
should prompt the user to input the make (which might consist of more than one word)
and year information for each structure. Note that this requires some care because it
alternates reading strings with numeric data (see Chapter 4). Finally, it should display
the contents of each structure. A sample run should look something like the following:
How many cars do you wish to catalog? 2
Car #1:
Please enter the make: Hudson Hornet
Please enter the year made: 1952
Car #2:
Please enter the make: Kaiser
Please enter the year made: 1951
Here is your collection:
1952 Hudson Hornet
1951 Kaiser
Here's what I've been desperately and unsuccessfully trying to do:
- Code: Select all
#include "stdafx.h"
#include <iostream>
#include <string>
struct cars
{
string maker;
int year;
};
using namespace std;
int main()
{
cout <<"How many cars do you wish to catalog; ";
int user;
cin >> user;
cars member[user];
int counter = 0;
for(counter; counter < user; counter++)
{
system("cls");
cout << "\nMaker: ";
getline(cin, member[counter].maker);
cout <<"\nYear: ";
}
counter = 0;
for(counter; counter < user ; counter++)
{
cout << "Here's your catalog: \n";
cout<< member[counter].year <<" "<< member[counter].maker <<endl;
}
system("pause");
return 0;
}
Obviously I haven't included the new thing at all, so would anyone please make this work and hopefully explain how creating run-time storage and putting data there works:)
Regards,
Jack
