控制台条形图和基于最高?的结果划分C++; p>我一直在阅读C++的引物,里面有各种各样的例子和测试场景,它们可以确保每个新章节都被正确地学习,并且没有其他方法来改进实际的编码。 < C++ >要求对这个“实践问题”进行尝试,如下: 编写一个程序,提供用3个可能的值汇总民意测验结果的选项。程序的第一个输入是投票问题;接下来的三个输入是可能的答案。第一个答案由1表示,第二个答案由2表示,第三个答案由3表示。记录答案直到输入0。然后,该程序应显示投票结果。尝试制作一个条形图,显示正确缩放的结果,以适合您的屏幕,无论输入了多少结果
因此,我很好奇,作者希望我如何确保结果符合屏幕分辨率,而不管“输入了多少结果”以及输入了输入数据和显示的循环的主要语法。我很想知道最好的方法是什么,于是就拼凑了一个非常非常简单的方法,根据最高的结果输入(高达1000/100)除以1:10的比例控制台条形图和基于最高?的结果划分C++; p>我一直在阅读C++的引物,里面有各种各样的例子和测试场景,它们可以确保每个新章节都被正确地学习,并且没有其他方法来改进实际的编码。 < C++ >要求对这个“实践问题”进行尝试,如下: 编写一个程序,提供用3个可能的值汇总民意测验结果的选项。程序的第一个输入是投票问题;接下来的三个输入是可能的答案。第一个答案由1表示,第二个答案由2表示,第三个答案由3表示。记录答案直到输入0。然后,该程序应显示投票结果。尝试制作一个条形图,显示正确缩放的结果,以适合您的屏幕,无论输入了多少结果,c++,visual-c++,C++,Visual C++,因此,我很好奇,作者希望我如何确保结果符合屏幕分辨率,而不管“输入了多少结果”以及输入了输入数据和显示的循环的主要语法。我很想知道最好的方法是什么,于是就拼凑了一个非常非常简单的方法,根据最高的结果输入(高达1000/100)除以1:10的比例 #包括 #包括 使用名称空间std; int main() { //可变减容 字符串问题; int tally1=0,tally2=0,tally3=0; int输入=1; 结果; //问题输入与文本模糊 请看一下书中关于“函数”的章节(我肯定它一定有一
#包括
#包括
使用名称空间std;
int main()
{
//可变减容
字符串问题;
int tally1=0,tally2=0,tally3=0;
int输入=1;
结果;
//问题输入与文本模糊
请看一下书中关于“函数”的章节(我肯定它一定有一个)不幸的是,这不是C++的一部分,你必须找出一些特定平台的方式来获得控制台窗口的尺寸。如果你只搜索一点点,就有很多教程、例子和引用。@ JePijull我还没有真正在书中起作用,我了解他们的角色,但是我正在努力学习E。一切都是从头开始的,那么为什么作者希望我实现一些我还没有学过的东西呢现在我真的觉得这是一本入门读物…关于这个问题,它听起来不像是什么。经过一点搜索,它真的来自另一本书,叫做。没有读过那本书,你确定没有提到关于如何获得控制台尺寸或如何解决你的问题的任何内容吗?也许人们期望你不会“你自己研究吗?”某个程序员说:“是的,我说我一直在读一个C++入门,实际上是“跳进C++”。这本书并不希望你知道这一点,通过研究和提问,我发现了一些函数,这些函数在本书的下一章中很方便地提到了,这对作者的前瞻性思维是一种支持!
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Variable decleration
string Question;
int tally1 = 0, tally2 = 0, tally3 = 0;
int input = 1;
int resultRatio;
//Question input and text fluff
cout << "Please enter a poll that has 3 answers: ";
getline(cin, Question, '?');
cout << "Your question is: " << Question << "?" << endl;
cout << "When results are complete for specified poll answer, enter 0 to input results" << endl;
while (1) //Tally 1 answer input.
{
cout << "Please enter the tallies for answer A: ";
cin >> input;
tally1 = tally1 + input;
if (input != 0)
{
cout << "A's current tallies: " << tally1 << endl;
continue;
}
cout << endl;
break;
}
while (1) //Tally 2 answer input.
{
cout << "Please enter the tallies for answer B: ";
cin >> input;
tally2 = tally2 + input;
if (input != 0)
{
cout << "B's current tallies: " << tally2 << endl;
continue;
}
cout << endl;
break;
}
while (1) //Tally 3 answer input.
{
cout << "Please enter tallies for answer C: ";
cin >> input;
tally3 = tally3 + input;
if (input != 0)
{
cout << "C's current tallies: " << tally3 << endl;
continue;
}
cout << endl;
break;
}
// Ratio in which total tallies should be divded by before bar chart display
if (tally1 >= 10 || tally2 >= 10 || tally3 >= 10)
{
resultRatio = 10;
}
else if (tally1 >= 100 || tally2 >= 100 || tally3 >= 100)
{
resultRatio = 100;
}
else if (tally1 >= 1000 || tally2 >= 1000 || tally3 >= 1000)
{
resultRatio = 1000;
}
else
{
resultRatio = 1;
}
//Simple bar chart to display all the results in a ratio that'll fit the screen thanks to resultRatio division
cout << "All results have been entered, here is the barchart (Results displayed are divided by " << resultRatio <<"):";
cout << endl << "A:" << "(" << tally1 << "votes )";
for (int i = tally1 / resultRatio; i > 0; i--)
{
cout << "o";
}
cout << endl << "B:" << "(" << tally2 << "votes )";
for (int i = tally2 / resultRatio; i > 0; i--)
{
cout << "o";
}
cout << endl << "C:" << "(" << tally3 << "votes )";
for (int i = tally3 / resultRatio; i > 0; i--)
{
cout << "o";
}
cout << "\nHere is the full bar graph on input results";
return 0;
}