Answer to Question #297129 in C++ for F_AR

Question #297129

Store one book data via pointer. Use function to initialize the data given by user.

1
Expert's answer
2022-02-12T16:22:14-0500
#include <iostream>
#include <string>

// Store one book data via pointer.
// Use function to initialize the data given by user.
struct Book {
    std::string name;
    int code;    
};

void Init(Book * book, std::string name, int code) {
    book->name = std::move(name);
    book->code = code;
}

int main() {
    Book * stored = new Book();
    std::string name;
    int code;
    std::cout << "Enter name: ";
    std::getline(std::cin, name);
    std::cout << "Enter code: ";
    std::cin >> code;
    Init(stored, name, code);
    std::cout << stored->name << " " << stored->code << '\n';
    delete stored;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog