Search
 
SCRIPT & CODE EXAMPLE
 

CPP

pagesNumbering C++

void pushBook(BookStack *bkStack, BookNode *bkNode)
{
    if(isEmpty(bkStack))
      {
        bkStack->lastNode = bkNode;
        bkStack->lastNode->previousNode = NULL;
      }
    else
    {
        bkStack->lastNode->previousNode = bkStack->lastNode;
        bkStack->lastNode = bkNode;
    }
}
BookNode *popBook(BookStack *bkStack)
{
  BookNode *temp = new BookNode;
  if(isEmpty(bkStack))
  {
    temp = bkStack->lastNode;
    return temp;
  }
  else if(bkStack->lastNode->previousNode == NULL)
  {
    temp = bkStack->lastNode;
    bkStack->lastNode = NULL;
    return temp;
  }else
  {
    temp = bkStack->lastNode->previousNode;
    bkStack->lastNode->previousNode = NULL;
    bkStack->lastNode = temp;
    return temp;
  }
}

void displayStackElements(BookStack *bkStack)
{
  BookNode *nodePtr = new BookNode;

  nodePtr = bkStack->lastNode;

  if(isEmpty(bkStack))
  {
    cout << "Book stack is empty." << endl;
  }
  else
  {
      while(nodePtr != NULL)
        {
          cout << "
Book Name: " << nodePtr->bk.name << endl;
          cout << "Author Name: " << nodePtr->bk.authorName << endl;
          cout << "Page Numbers: " << nodePtr->bk.pagesNumber << endl;
          cout << "ISBN: " << nodePtr->bk.isbn << endl;
          cout << endl;


          nodePtr = bkStack->lastNode->previousNode;
          }
      }

}
bool isEmpty(BookStack *bkStack)
{
    bool status;

    if(bkStack->lastNode == NULL)
        status = true;
    else
        status = false;

    return status;
}

void addBook(BookStack *bkStack)
{
  BookNode *bkNode = new BookNode;
  cout << "
Enter the book name: ";
  getline(cin, bkNode->bk.name);
  cout << "Enter the Author's Name: ";
  getline(cin, bkNode->bk.authorName);
  cout << "Enter the ISBN: ";
  cin >> bkNode->bk.isbn;
  cout << "Enter the page numbers: ";
  cin >> bkNode->bk.pagesNumber;
  pushBook(bkStack, bkNode);
}

void removeBook(BookStack *bkStack)
{
  BookNode *removedNode = new BookNode;
  removedNode = popBook(bkStack);

  if(removedNode == NULL)
  {
    cout << "
No books to remove." << endl;
  }else
  {
    cout << endl << removedNode->bk.name << " was removed." << endl;
  }
}
Comment

pagesNumbering C++

int pagesNumbering(int n)
{
    int number_of_digits = 0;
    for(int i = 1; i <= n; i *= 10)
        number_of_digits += (n - i + 1);
    return number_of_digits;
} // => tiến code
Comment

PREVIOUS NEXT
Code Example
Cpp :: Edmonds-Karp algorithm C++ 
Cpp :: how to use #define c++ 
Cpp :: Difference Array | Range update query in O 
Cpp :: cpprestsdk header 
Cpp :: file is good in c++ 
Cpp :: C++ meaning :: 
Cpp :: convert java to c++ 
Cpp :: command loop ctrl D c++ 
Cpp :: C++ (.NET CLI) 
Cpp :: qt_invok 
Cpp :: cpp Case value is not a constant expression 
Cpp :: set keybinding for compiling c++ program in neovim 
Cpp :: huffman encoding in c++ 
Cpp :: Explicit conversion casting 
Cpp :: c++ string to vector using delimiter 
Cpp :: check if number is positive or negative in cpp 
Cpp :: C++ (gcc 8.3) sample 
Cpp :: ue_log example 
Cpp :: run a c++ file in terminal 
Cpp :: std::random_device 
Cpp :: printing sub arrays 
Cpp :: clang does not recognize std::cout 
Cpp :: c++ vs c# 
Cpp :: hwo to send token on redirection in passport 
Cpp :: how to use comparitor in priority queu in c++ 
Cpp :: std::string(size_t , char ) constructor: 
Cpp :: c++ sleep function 
Cpp :: Max / Min Stack in c++ using stl in O(1) time and space 
Cpp :: main function 
Cpp :: who made c++ 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =