新的C ,模块和开关菜单
New to C++, modules and switch menu
我正在研究一个项目,该项目涉及创建菜单屏幕,并将三个程序集成到一个可以从菜单屏幕中选择性启动的程序。
我认为先制作单个程序,然后将它们与开关案例拼凑在一起,并且功能很容易(我不知道班级/对象(。我一直遇到砖墙和许多语法/逻辑错误,所以我删除了所有内容,现在我又回到了正方形的一个 - 带有三个不同的程序。这是非常艰巨的 - 如何进行?:/
#include <iostream>
using namespace std;
int main ()
{
int x;
cout << "Enter the amount of money you have ";
cin >> x;
if (x >= 20) {
cout << "You can buy Comic Book $1 or Sports Journal $3 or Science Book $15 or Third Volume Series $20";
} else if (x >= 15 && x < 20) {
cout << "You can buy Comic Book $1 or Sports Journal $3 or Science book $15";
} else if (x >= 3 && x < 15) {
cout << "You can buy Comic Book $1 or Sports Journal $3";
} else if (x >= 1 && x < 3) {
cout << "You can buy Comic Book $1";
} else if (x <= 0) {
cout << "You cannot afford anything";
}
return 0;
}
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int numclass; //number of classes
int numStudents; //number of students
int numTests; // Number of tests per student
double sectiontotal; //Accumulator for Class total scores
double total; // Accumulator for total scores
double average; //Average test score
double totalaverage = 0;
ofstream outfile;
outfile.open("Gradesinfo.txt");
// Set up numeric output formatting.
cout << fixed << showpoint << setprecision(1);
// Get the number of students.
cout << "This program gives average of test scores per student, per class, and for the whole institution for upto 2 students in upto 2 different classes in 3 subjectsn";
// Determine each student's average score.
cout << "Enter the number of classes";
cin >> numclass;
cout << "Enter the number of students per class";
cin >> numStudents;
cout << "Enter the number of tests";
cin >> numTests;
for (int section = 1; section <= numclass; section++) {
sectiontotal = 0; //Initialize class accumulator
totalaverage = 0;
for (int student = 1; student <= numStudents; student++) {
total = 0; // Initialize the accumulator.
for (int test = 1; test <= numTests; test++) {
double score;
cout << "Enter score " << test << " for ";
cout << "student " << student << ": ";
cin >> score;
if (score >= 0 && score <= 100) {
total += score;
} else {
cout << "Enter value from 1 - 100" << endl;
test = test - 1;
}
}
average = total / numTests;
totalaverage += average;
cout << "The average score for student " << student;
cout << " is " << average << ".nn";
outfile << "The average score for student " << student;
outfile << " is " << average << ".nn";
}
cout << "The total average for class " << section << " is: " << totalaverage / numStudents << endl;
outfile << "The total average for class " << section << " is: " << totalaverage / numStudents << endl;
sectiontotal += totalaverage;
}
cout << "The total average for the institution is: " << sectiontotal / numclass;
outfile << "The total average for the institution is: " << sectiontotal / numclass;
outfile.close();
return 0;
}
#include<cstdlib>
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream instream;
ofstream outstream;
instream.open("Grades.txt");
if (instream.fail()) {
cout << "The input file failed to openn";
exit(1);
}
int next, largest, smallest;
largest = 0;
smallest = 0;
while (instream >> next) {
if (largest < next) {
largest = next;
} else {
smallest = next;
}
}
cout << "The highest grade is: " << largest << endl;
instream.close();
system("pause");
return 0;
}
我想你在脚上开枪。在另一个之后走一步,请以此为参考:
- 创建一个主文件作为应用程序的入口点,请注意函数的原型和实现 printa 和 printb
#include <iostream>
using namespace std;
void printA();
void printB();
int main()
{
int x = 1;
cout << "Enter the option:n";
while (cin >> x)
{
if (x <= 0)
{
break;
}
switch (x) {
case 1:
printA();
break;
case 2:
printB();
break;
default:
cout << "Invalid";
}
}
return 0;
}
void printB()
{
cout << "B";
}
void printA()
{
cout << "A";
}
创建一个新的文件fooa.cpp并在那里粘贴实现的函数printa
对另一个文件中的打印b做同样的事情。
从main.cpp
中删除这些实现
你完成了!
相关文章:
- 既然存在危险,为什么项目要使用-I include开关
- 无法获取菜单选择以运行函数.C++
- 为什么这个音频包络不能通过开关的情况?
- 有人知道为什么在开关中使用stoi函数会返回恒定的错误吗
- C 和 C++ 中开关语句的案例标签的常量值,但显示不同的行为
- 在 c++ 中在开关情况下使用和不使用"break"时的不同输出
- 为什么我的开关/机箱在使用枚举时默认?
- 为什么布尔开关语句有编译器警告?
- 如何使用"equal to"以外的评估编写开关语句
- 为什么开关的优化方式与 c/c++ 中的链接不同?
- 无法找到简单的开关大小写枚举错误
- 未达到的情况会影响开关外壳性能
- C++ 中的图形菜单
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 我的开关菜单在一段时间循环中出现问题
- 新的C ,模块和开关菜单
- 如何在不使用开关大小写的情况下用C++编写菜单驱动的程序
- C++:循环菜单开关
- 为什么我的菜单不起作用 c++ 大小写开关
- c++中的滚动菜单?如何改变它的开关