函数中的字符串和整数操作 [英] String and integer manipulation within a function

查看:52
本文介绍了函数中的字符串和整数操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开并读取名为prog4.dat的输入文件。



文件将有15个整数(大于或等于2)。



之后每行10个字(小写字符串,没有空格)。



15个整数,您的代码将确定整数是否为素数。



对于10个字符串,该字符串将转换为"密码"。 



**部分样本输入文件:**



27 b


19



狗b
$ b b b elephant



**输出**



@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@ $ $ b $
$ b 27不是素数。



19是素数。$


c0f



3k3og9ms

$
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@一个功能将决定一个数字是否为素数。

  - 另一个function(产生"密码"的函数)将返回一个字符串并取一个string类型的值参数。  

  - 另一个函数将采用2个参数,一个类型为string的值参数和一个类型为ofstream的引用参数。  此函数是一个void函数,只会打印一个漂亮的边框,包括传入的字符串。
$


**密码指令** - 每个传入的字符串,将每个辅音转换为紧接在字母表之前的字母。  



对于元音,请遵守以下规则:



a - > 9  e - > 3  i - > 1  o - > 0  u - > 4

open and read from an input file named prog4.dat.

The file will have 15 integers(greater than or equal to 2).

Following that will be 10 words(strings of lowercase characters with no spaces) per line.

For the 15 integers, your code will determine whether or not the integer is prime.

For the 10 strings, the string will be converted to a "secret code." 

**Partial sample input file:**

27

19

dog

elephant

**output**

@@@@@@@@@@@@@ test @@@@@@@@@@@@@@@@

27 is not prime.

19 is prime.

c0f

3k3og9ms

@@@@@@@@@@@@@ test @@@@@@@@@@@@@@@@

 - One function will determine whether or not a number is prime.
 - Another function (the one that produces the "secret code") will return a string and take one value parameter of type string.  
 - The other function will take 2 parameters, a value parameter of type string and a reference parameter of type ofstream.  This function is a void function and will simply print a nice border including the string that was passed in.

**Secret code instructions** --For each string passed in, convert each consonant to the letter immediately beforeit inthe alphabet.  

For vowels, use these rules:

a -> 9  e -> 3  i -> 1  o -> 0  u -> 4

#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;
int checkPrimeNumber(int);
string secretCode(string);
void border(ofstream& outfile);


int main()
{
	ofstream outfile;
	ifstream infile;
	infile.open("prog4.txt");
	outfile.open("outfile.txt");

	int n;

	border;

	infile >> n;

	if (checkPrimeNumber(n) == 0)
		outfile << n << " is a prime number.";
	else
		cout << n << " is not a prime number.";
	return 0;
}

string secretCode(string s)
{


}


int checkPrimeNumber(int n)
{
	bool flag = false;

	for (int i = 2; i <= n / 2; ++i)
	{
		if (n%i == 0)
		{
			flag = true;
			break;
		}
	}
	return flag;
}

void border(ofstream& outfile) {
	outfile << "@@@@@@ test @@@@@@\n";
}




$
  &NBSP; &NBSP;   

我想知道如何进行密码部分和ofstream refference部分



        
I want to know How to do the secret code part and the ofstream refference part

推荐答案

我想没有人会在这里做你的作业。

I guess noone will do your homework here.

如果你对创建"密码"有特殊的疑问。功能请发布您的代码并询问具体问题。

If you have specific questions on creating the "secretcode" function please post your code and ask specific questions.

根本不是很困难。你只需要用你的字符串做两件不同的事情。在第一步中,我会用规则所说的数字替换元音。在第二步中,如果不是数字,我会减少每个字符的值。

At all it is not really difficuilt. You only have to do 2 different things with your string. In the first step I'd replace the vowels with the numbers like the rule said. In the second step I'd decrement the value of each character if it is not a number.


这篇关于函数中的字符串和整数操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆