Q1-solution-cw1-exam-paper.cpp - #include<iostream>#include<fstream>#include<cstring> using namespace std\/QUESTION 1 a-e struct Date int day int month

Q1-solution-cw1-exam-paper.cpp -...

This preview shows page 1 - 3 out of 3 pages.

#include<iostream> #include<fstream> #include<cstring> using namespace std; //QUESTION 1 a-e struct Date{ int day; int month; int year; }; struct Toy{ int num; string name; string manufacturer; int recAge; double price; int quan; Date purDate; }; int readToys(Toy toys[]); void displayToys(Toy toys[]); void manufList(Toy toys[], int numToys, string manuF, int age); Date deliveryDate(Date d); bool isLeapYear(int year); int readToys(Toy toys[]){ int numToys = 0; ifstream in; int num, recAge, quan; double price; string name, manuf; Toy t; in.open("toys.txt"); if(!in.is_open()){ cout << "Error opening toys.txt file, aborting..." << endl; return 1; } in >> num; while(num != 99999){ in >> name; in >> manuf; in >> recAge; in >> price; in >> quan; t.num = num; t.name = name; t.manufacturer = manuf; t.recAge = recAge; t.price = price; t.quan = quan; toys[numToys] = t; numToys++; } in.close(); return numToys;
Image of page 1
} void displayToy(Toy toy){ cout << "Toy number: " << toy.num << endl; cout << "Toy name: " << toy.name << endl; cout << "Manufacturer: " << toy.manufacturer << endl; cout << "Recommended Age: " << toy.recAge << endl; cout << "Price: " << toy.price << endl; cout << "Quantity available: " << toy.quan << endl;
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Spring '17
  • int day, void displayToys

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes