小编Rap*_*ael的帖子

使用向量对一些预定义的字符串发出哔哔声

因此,我目前正在 Bjarne Stroustrup 的编程书籍“编程:使用 c++ 的原则和实践”中进行练习,但我目前只专注于一项练习。基本上,练习是编写一个程序,它会发出它不喜欢的单词。它的工作方式是用户输入一个字符串,程序重复这个词。如果用户输入的词是不喜欢向量的一部分,则该词将替换为“Bleep”。(我不知道我的解释是否正确,但理解起来应该不会太复杂)。

这是我的程序版本:

int main()
{
    string dislike = "Potato";
    string words = " ";

    cout << "Please enter some words: " << endl;
    while(cin>>words)
    {
        if(words==dislike)
        {
            cout << "Bleep!" << endl;
        }

        else
        {
            cout << words << endl;
        }
    }
    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,这个版本没有使用向量(它应该使用,因为练习就在本章中向量的解释之后)。所以我的问题是,如何实现一个包含许多“不喜欢”词的向量,如下所示:

vector<string>dislike;
dislike.push_back("Potatoes");
dislike.push_back("Peanuts");
dislike.push_back("Coconut");
Run Code Online (Sandbox Code Playgroud)

并使它像我的其他版本一样工作,没有向量(重复单词,但不喜欢的单词会发出哔哔声)。我似乎无法理解如何在向量中导航,以便它只会发出“不喜欢”的话。

如果有人可以帮助我并向我解释它是如何工作的(请不要只给我答案),我将不胜感激。

感谢您的时间和帮助,单独学习 C++ 并不总是那么简单,我感谢这个网站让我的学习曲线更容易一些。

博比酷

c++ vector

3
推荐指数
1
解决办法
2069
查看次数

为Django Web应用程序选择正确的数据库系统

我目前正处于构建简单的Django Web应用程序(用于学习建议)的计划阶段.基本上,教师可以登录,输入学生成绩,然后学生可以登录并查看他们的成绩.每个班级都有一个组号.

这是用户的模板:

Username: Johny098
Password: Y98uj*?877!(
Name: John Doe
Gender: Male
Group: 32
Secondary: 5
Run Code Online (Sandbox Code Playgroud)

考虑到我一般从django和web开发开始,我发现混淆了我可用的数据库系统的数量:MySQL,CouchDB,MongoDB,SQLite等.我很难决定哪个数据库系统用于我的目的(我没有数据库的经验).

经过一些研究后,我发现Couchdb(和SQLite)看起来相当简单,使用起来很有趣,但那只是我,这就是我需要帮助的原因.我知道有很多关于SQL vs NoSQL的争论,但我真的不知道这是否会对我使用数据库产生影响.理想情况下,数据库系统应该与django很好地集成,并且很容易在几天内完成.

所以,回到这个问题:我应该为我的网络应用程序使用什么数据库系统?

任何资源也将受到赞赏.

谢谢,

-Raphael

python database django

1
推荐指数
1
解决办法
906
查看次数

猜数字 - 读错时无限循环

所以我猜这个用C++编写的数字游戏看起来像这样:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    srand(time(0));
    int secretNumber = rand() % 100 + 1; //Generate "Random number"
    int nbrOfGuesses = 0;
    int userInput;

    cout<<"\t************************************"<<endl;
    cout<<"\t*                                  *"<<endl;
    cout<<"\t*          Guess the number!       *"<<endl;
    cout<<"\t*                                  *"<<endl;
    cout<<"\t************************************"<<endl;
    cout<<endl;
    cout << "Try to find the secret int number: " << endl;

    //While input is good
    while(cin.good())
    {
        //Do this
        do {
            cin>>userInput;
            nbrOfGuesses++;

            if (userInput>secretNumber)
                cout << "Smaller!\n";

            else if(userInput<secretNumber)
                cout << "Bigger!\n"; // <-- Infinite …
Run Code Online (Sandbox Code Playgroud)

c++ loops

0
推荐指数
1
解决办法
1185
查看次数

标签 统计

c++ ×2

database ×1

django ×1

loops ×1

python ×1

vector ×1