Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. pointers and structures

pointers and structures

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialannouncementlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    klutez123
    wrote on last edited by
    #1

    Right now I'm creating a program that declares a structure, which also has enum inside it. Now I believe I declare the structure right, but the next step is to create a loop that has the user enter 5 different items of data for library information. But I have to use pointers, so when the loop runs and I enter the information, the data has to be sent to a structure variable only once all six attributes are entered, and the pointer values should be used to create the structure. I was given an example: cin >> a; cin >> b; library.dewey = &aptr; This is my code so far: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum type {fiction, nonfiction, reference, pond}; }; int main() { card_catalogue books; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "Enter the type: "; getline(cin, books.type); return 0; }

    D A 2 Replies Last reply
    0
    • K klutez123

      Right now I'm creating a program that declares a structure, which also has enum inside it. Now I believe I declare the structure right, but the next step is to create a loop that has the user enter 5 different items of data for library information. But I have to use pointers, so when the loop runs and I enter the information, the data has to be sent to a structure variable only once all six attributes are entered, and the pointer values should be used to create the structure. I was given an example: cin >> a; cin >> b; library.dewey = &aptr; This is my code so far: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum type {fiction, nonfiction, reference, pond}; }; int main() { card_catalogue books; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "Enter the type: "; getline(cin, books.type); return 0; }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      klutez123 wrote:

      But I have to use pointers...

      Why? They are not necessary for what you are doing.

      klutez123 wrote:

      card_catalogue books;

      Should be:

      card_catalogue books[5]; // to hold five items

      You then need to wrap your cout/cin statements in a for loop.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • K klutez123

        Right now I'm creating a program that declares a structure, which also has enum inside it. Now I believe I declare the structure right, but the next step is to create a loop that has the user enter 5 different items of data for library information. But I have to use pointers, so when the loop runs and I enter the information, the data has to be sent to a structure variable only once all six attributes are entered, and the pointer values should be used to create the structure. I was given an example: cin >> a; cin >> b; library.dewey = &aptr; This is my code so far: struct card_catalogue //declare a structure then declare all { //the varibles needed for the struct float dewey; string title; string author; int released; int num_pages; enum type {fiction, nonfiction, reference, pond}; }; int main() { card_catalogue books; cout<< "Enter the Dewey Decimal Number please: "; cin>> books.dewey; cout<< "Enter the Title of the book please: "; getline(cin, books.title); cout<< "Enter the Author of the book please: "; getline(cin, books.author); cout<< "Enter the Year of Release please: "; cin>> books.released; cout<< "Enter the Number of Pages please: "; cin>> books.num_pages; cout<< "Enter the type: "; getline(cin, books.type); return 0; }

        A Offline
        A Offline
        ajitatif angajetor
        wrote on last edited by
        #3

        i couldn't catch what you exactly want, but can a constructor help you? you could create a constructor that takes these values as argument and get the values one by one from console. then, create a new books struct with the values.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups