void addReview(node **tree,node2 **tree2,double score_number,int review_id,char text[],int total_number_of_reviews){
	
    node *temp = NULL;
    
    if(!(*tree)){
        temp = (node *)malloc(sizeof(node));
        temp->left = temp->right = NULL;
        temp->score_number = score_number;
        temp->reviewPtr =(node2 *)malloc(sizeof(node2));
        temp->reviewPtr->review_id=review_id;
        strcpy(temp->reviewPtr->text,text);
        temp->reviewPtr->left = temp->reviewPtr->right ;
        *tree = temp;
        return;
    }

    if(score_number < (*tree)->score_number){
        addReview(&(*tree)->left,tree2, score_number,review_id,text,total_number_of_reviews);
    }
    
    else if(score_number > (*tree)->score_number){
        addReview(&(*tree)->right,tree2, score_number,review_id,text,total_number_of_reviews);
    }
    
    else if(score_number == (*tree)->score_number){

    if(review_id < (*tree)->reviewPtr->review_id){
        addReview(&(*tree)->left,tree2,score_number,review_id,text,total_number_of_reviews);
    }
    
    else if(review_id > (*tree)->reviewPtr->review_id){
        addReview(&(*tree)->right,tree2,score_number,review_id,text,total_number_of_reviews);
    }

    }
    

}
Example #2
0
AddReviewWindow::AddReviewWindow(ActualDataStore* inDS, std::string pName)
{
  ds = inDS;
  prodName = pName;




  // Overall layout
  overallLayout = new QVBoxLayout();




  // // Interaction elements for adding reviews
  // Layout
  buttonInputLayout = new QHBoxLayout();
  overallLayout->addLayout(buttonInputLayout);
  // Score input
  scoreLabel = new QLabel("Score");
  scoreButton = new QComboBox();
  for (int i = 1; i < 6; ++i)
    scoreButton->addItem(QString::number(i));
  buttonInputLayout->addWidget(scoreLabel);
  buttonInputLayout->addWidget(scoreButton);
  // Date input
  dateLabel = new QLabel("Date");
  dateButton = new QDateEdit();
  dateButton->setDisplayFormat("MM/dd/yyyy");
  buttonInputLayout->addWidget(dateLabel);
  buttonInputLayout->addWidget(dateButton);
  // Review input
  reviewField = new QLineEdit();
  reviewField->setPlaceholderText("Enter review here");
  overallLayout->addWidget(reviewField);

  // Defaults date input to system's current date for convenience
  dateButton->setDate(QDate::currentDate());




  // // Interaction for closing window
  // Layout
  closureButtonLayout = new QHBoxLayout();
  overallLayout->addLayout(closureButtonLayout);
  // Add button
  addButton = new QPushButton("Add Review");
  connect(addButton, SIGNAL(clicked()), this, SLOT(addReview()));
  closureButtonLayout->addWidget(addButton);
  // Cancel button
  cancelButton = new QPushButton("Cancel");
  connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
  closureButtonLayout->addWidget(cancelButton);




  // Set overall layout
  setLayout(overallLayout);
}
Example #3
0
void Programme::addSubElement( QDomElement &element) {
  if(element.localName().compare("Icon", Qt::CaseInsensitive)==0) {
    Icon *cn = Icon::fromElement(element);
    addIcon(cn);
    return;
  }
  if(element.localName().compare("Category", Qt::CaseInsensitive)==0) {
    Category *cn = Category::fromElement(element);
    addCategory(cn);
    return;
  }
  if(element.localName().compare("SubTitle", Qt::CaseInsensitive)==0) {
    SubTitle *cn = SubTitle::fromElement(element);
    addSubTitle(cn);
    return;
  }
  if(element.localName().compare("LastChance", Qt::CaseInsensitive)==0) {
    LastChance *cn = LastChance::fromElement(element);
    addLastChance(cn);
    return;
  }
  if(element.localName().compare("Audio", Qt::CaseInsensitive)==0) {
    Audio *cn = Audio::fromElement(element);
    addAudio(cn);
    return;
  }
  if(element.localName().compare("Subtitles", Qt::CaseInsensitive)==0) {
    Subtitles *cn = Subtitles::fromElement(element);
    addSubtitles(cn);
    return;
  }
  if(element.localName().compare("Date", Qt::CaseInsensitive)==0) {
    Date *cn = Date::fromElement(element);
    addDate(cn);
    return;
  }
  if(element.localName().compare("PreviouslyShown", Qt::CaseInsensitive)==0) {
    PreviouslyShown *cn = PreviouslyShown::fromElement(element);
    addPreviouslyShown(cn);
    return;
  }
  if(element.localName().compare("Country", Qt::CaseInsensitive)==0) {
    Country *cn = Country::fromElement(element);
    addCountry(cn);
    return;
  }
  if(element.localName().compare("OrigLanguage", Qt::CaseInsensitive)==0) {
    OrigLanguage *cn = OrigLanguage::fromElement(element);
    addOrigLanguage(cn);
    return;
  }
  if(element.localName().compare("StarRating", Qt::CaseInsensitive)==0) {
    StarRating *cn = StarRating::fromElement(element);
    addStarRating(cn);
    return;
  }
  if(element.localName().compare("Credits", Qt::CaseInsensitive)==0) {
    Credits *cn = Credits::fromElement(element);
    addCredits(cn);
    return;
  }
  if(element.localName().compare("Title", Qt::CaseInsensitive)==0) {
    Title *cn = Title::fromElement(element);
    addTitle(cn);
    return;
  }
  if(element.localName().compare("Video", Qt::CaseInsensitive)==0) {
    Video *cn = Video::fromElement(element);
    addVideo(cn);
    return;
  }
  if(element.localName().compare("New", Qt::CaseInsensitive)==0) {
    New *cn = New::fromElement(element);
    addNew(cn);
    return;
  }
  if(element.localName().compare("Rating", Qt::CaseInsensitive)==0) {
    Rating *cn = Rating::fromElement(element);
    addRating(cn);
    return;
  }
  if(element.localName().compare("EpisodeNum", Qt::CaseInsensitive)==0) {
    EpisodeNum *cn = EpisodeNum::fromElement(element);
    addEpisodeNum(cn);
    return;
  }
  if(element.localName().compare("Length", Qt::CaseInsensitive)==0) {
    Length *cn = Length::fromElement(element);
    addLength(cn);
    return;
  }
  if(element.localName().compare("Url", Qt::CaseInsensitive)==0) {
    Url *cn = Url::fromElement(element);
    addUrl(cn);
    return;
  }
  if(element.localName().compare("Review", Qt::CaseInsensitive)==0) {
    Review *cn = Review::fromElement(element);
    addReview(cn);
    return;
  }
  if(element.localName().compare("Language", Qt::CaseInsensitive)==0) {
    Language *cn = Language::fromElement(element);
    addLanguage(cn);
    return;
  }
  if(element.localName().compare("Premiere", Qt::CaseInsensitive)==0) {
    Premiere *cn = Premiere::fromElement(element);
    addPremiere(cn);
    return;
  }
  if(element.localName().compare("Desc", Qt::CaseInsensitive)==0) {
    Desc *cn = Desc::fromElement(element);
    addDesc(cn);
    return;
  }
}
Example #4
0
void doSomeStuff(){
    printf("Creating account for Dan Brown\n");
    struct Writer danBrown = newWriter(
        "Dan Brown",
        "danbrown",
        "password"
    );
    addWriter(&danBrown, &eBookStore);
    printf("Created account for Dan Brown with ID %d\n\n", danBrown.id);

    printf("Adding the book Angels and Demons\n");
    struct Book angelsAndDemons = newBook(
        "Angels and Demons",
        "Dan Brown",
        "Science and Mythology and Stuff",
        "In not so distant past...",
        danBrown.id,
        100
    );
    publishBook(&angelsAndDemons, &eBookStore);
    printf("Added the book Angels and Demons with ID %d\n\n", angelsAndDemons.id);

    printf("Adding the book Da Vinci Code\n");
    struct Book daVinciCode = newBook(
        "Da Vinci Code",
        "Dan Brown",
        "Its about the hipster Leo",
        "Once upon a time...",
        danBrown.id,
        100
    );
    publishBook(&daVinciCode, &eBookStore);
    printf("Added the book Da Vinci Code with ID %d\n\n", daVinciCode.id);

    printf("Books published by %s on our platform are,\n", danBrown.name);
    for(int i=0;i<danBrown.bookCount;i++){
        int bookID = danBrown.bookIDs[i];
        struct Book *b = eBookStore.bookDataStore.books[bookID];
        printf("#%d:\t%s\n", i+1, b->title);
    }
    printf("\n");

    printf("Finding books similar to %s\n", daVinciCode.title);
    assignSimilarBooks(&daVinciCode, &eBookStore);
    for(int i=0;i<daVinciCode.similarBookCount;i++){
        int bookID = daVinciCode.similarBooks[i];
        struct Book *b = eBookStore.bookDataStore.books[bookID];
        printf("#%d:\t%s\n", i+1, b->title);
    }
    printf("\n");

    printf("Creating customer account for Robert Langdon\n");
    struct Customer robertLangdon = newCustomer("robertlangdon", "password");
    addCustomerToDataStore(&robertLangdon, &eBookStore.customerDataStore);
    printf("Created customer account for Robert Langdon with user id %d\n\n", robertLangdon.id);

    printf("Searching for books with the title 'Angels and Demons'\n");
    struct Book* searchResult = searchBooksInDataStore(1, "Angels and Demons", 1, &eBookStore.bookDataStore)[0];
    printf("Found one book with the name %s by the author %s\n", searchResult->title, searchResult->author);
    printf("Its summary is, %s\n\n", searchResult->summary);

    printf("Submitting an excellent review for %s from user name %s\n", searchResult->title, robertLangdon.username);
    addReview(searchResult, &robertLangdon, 5, "Awesome read! :)", &eBookStore);
    printf("Fetching all reviews for %s,\n", searchResult->title);
    for(int i=0;i<searchResult->reviewCount;i++){
        printf("#%d: Rating: %d Comments: %s\n", i+1, searchResult->reviews[i]->rating, searchResult->reviews[i]->body);
    }
    printf("Average rating of %s is %f\n\n", searchResult->title, getAverageRating(searchResult));

    printf("That's all for this demo folks! :)\n");
}