コード例 #1
0
ファイル: Shop.cpp プロジェクト: unni07/Machine-Learning
void Shop::testData(std::string fileName)
{
	auto& reader = FileReader::instance();
	reader.readFile(fileName, 1);
	auto rawFile = reader.returnRawDatabse();
	auto itrBegin = rawFile.begin();
	auto itrEnd = rawFile.end();
	auto itr = itrBegin;
	size_t i = 0;
	std::string value;
	unsigned int index = 0;
	while (itr != itrEnd)
	{
		std::string line = *itr;
		auto pos = line.find(',');
		std::string title = line.substr(0, pos);
		line = line.substr(++pos);
		bool doneReading = false;
		while (!doneReading)
		{
			if (pos == std::string::npos)
			{
				doneReading = true;
			}
			std::string val = line.substr(0, pos);
			if (val.compare("?") != -1)
			{
				val = "0";
			}
			std::stringstream ss;
			ss.str(val);
			float rating;
			ss >> rating;

			auto reviewer = UserFactory::instance().getUser(title);
			reviewer->addRating(movienames[index], rating);

			auto movieEntity = CommodityFactory::instance().getUser(movienames[index]);
			movieEntity->adduser(reviewer, rating);

			line = line.substr(pos + 1);
			pos = line.find(',');
			index++;
		}
		++itr;
		index = 0;
	}
	reader.clear();
	
}
コード例 #2
0
ファイル: starmeals.c プロジェクト: quarkcharmer/myWork
int main(int argc, char* argv[]) {

    int test_mode = 0;

    if (argc == 2) {

        if (strcmp(argv[1], "test") == 0) {

            test_mode = 1;

            printf("[start_test]\n");

            test_data();

        }

    }

    else {

        printf("Enter meal names and ratings in the form <name> <rating>.\n");

        printf("No spaces are allowed in the name and the rating.\n");

        printf("The rating can be * through *****.\n");

        printf("To finish, enter \"end\" for a meal name.\n");

        while (names < MAX_NAMES) {

            char name[MAX_NAME_LENGTH];

            char rating[MAX_RATING_LENGTH + 1];

            printf("\nName and rating: ");

            scanf("%s", &name);

            if (strcmp(name, "end") == 0) {

                break;

            }

            scanf("%s", rating);

            addNameAndRating(name, rating);

        }

        printf("\n");

    }

 

    if (names) {

        // Print data entered and call libRatings.addRating().

        printf("This is the data you entered:\n");

        for (int i = 0; i < names; i++) {

            printf("%s (%s)\n", name_list[i], rating_list[i]);

            addRating(rating_list[i]);

        }

 

        // Print statistical information.

        printf("\nThe mean rating is %s\n", meanRating()); // 1

        if (medianRating) {                                // 2

            printf("The median rating is %s\n", medianRating());

        }

        if (frequentRating) {                              // 3

            printf("The most frequent rating is %s\n", frequentRating());

        }

 

        //printf("\n");

    }

 

    if (test_mode) {

        printf("[end_test]\n");

    }

    return 0;

}
コード例 #3
0
ファイル: Programme.cpp プロジェクト: juriad/tvp
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;
  }
}