帮忙修正一下这个输入数字,然后输出相应名字的C++程式...

来源:百度知道 编辑:UC知道 时间:2024/06/08 20:23:37
英文要求入下:
At a particular university, computer science courses have these numbers and names:

100 Introduction to Computer Architecture

110 Introduction to Algorithms

120 Software Engineering

200 Operating Systems

210 Programming Language Paradigms

Write two functions: one that given a course number, returns the corresponding course name; and another that given a course name, returns the corresponding course number.

Then write a driver program to test the two functions.

我写的程式入下,麻烦帮忙修改一下
main.h :
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>

using namespace std;

void NameToNum(string name);
void NumToName(int code);

main.cpp :
#include <iostream>
#include <string>
#include <cstring>
#include "main.h"

using namespace std;

你应该在main.cpp中包含function的头文件(如:#include "function.h"),然后把function.cpp中的#include "main.h"语句去掉。其次NameToNum中的所有的if判断语句都少了一个等号,应该改为:

void NameToNum(string name){
for(int i=0;i<name.size();i++){
if(isupper(name[i]))
name[i] = tolower(name[i]);
}
int code2;
if(name == "introduction to computer architecture"){
code2 = 100;}
else if(name == "introduction to algorithms"){
code2 = 110;}
else if(name == "software engineeringe"){
code2 = 120;}
else if(name == "operating systems"){
code2 = 200;}
else if(name == "programming language paradigms"){
code2 = 210;}
cout<<"The course number is "<<code2<<endl;
}