Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 函数与旋转字符_C++_Function_Rotation - Fatal编程技术网

C++ 函数与旋转字符

C++ 函数与旋转字符,c++,function,rotation,C++,Function,Rotation,我需要你的帮助!我试图让这个程序能够读入四个字符,然后以旋转模式打印出来。旋转四个字符后,它将读取另外四个字符并旋转它们。它重复这个读取和旋转的过程,直到文件结束 当我运行程序时,它不会打印4次。它只打印一次,不旋转任何东西 这是我的密码 #include <iostream> using namespace std; const int NUM_STEPS = 4; // number of rotation steps to perform void DisplayRot

我需要你的帮助!我试图让这个程序能够读入四个字符,然后以旋转模式打印出来。旋转四个字符后,它将读取另外四个字符并旋转它们。它重复这个读取和旋转的过程,直到文件结束

当我运行程序时,它不会打印4次。它只打印一次,不旋转任何东西

这是我的密码

#include <iostream>
using namespace std;

const int NUM_STEPS = 4;   // number of rotation steps to perform

void DisplayRotationPattern(char c1, char c2, char c3, char c4);
void DisplayFourChars(char c1, char c2, char c3, char c4);


//     This function "rotates" four characters c1, c2, c3, and c4.
//     That is, it puts c2 in c1, c3 in c2, c4 in c3, and c1 in c4.
void RotateFourChars(char c1, char c2, char c3, char c4);


int main()
{
   char ch1, ch2, ch3, ch4;   

   cout << "Enter four characters: ";
   cin >> ch1 >> ch2 >> ch3 >> ch4;

   while( cin )
   {
      cout << "The Rotation patterns are:" << endl;

      DisplayFourChars(ch1, ch2, ch3, ch4);



      cout << "Enter four characters: ";
      cin >> ch1 >> ch2 >> ch3 >> ch4;
   }

   return 0;
}


//-----------------------------------------------------------------------
// This function displays the four characters passed to it
// in a rotated pattern.
// params: (in, in, in, in)
//-----------------------------------------------------------------------
void DisplayRotationPattern(char c1, char c2, char c3, char c4)
{
   int count = 1;
   while (count <= NUM_STEPS)
   {

      DisplayFourChars( c1, c2, c3, c4);
      cout << endl;


      RotateFourChars( c1,  c2,  c3, c4 );
      count ++;
   }

}

//-----------------------------------------------------------------------       
// This function "rotates" four characters c1, c2, c3, and c4.
// That is, it puts c2 in c1, c3 in c2, c4 in c3, and c1 in c4.
// params: (inout, inout, inout, inout)
//-----------------------------------------------------------------------
void RotateFourChars(char c1, char c2, char c3, char c4)
{  

      char temp;

       temp = c1;
       c1 = c2;
       c2 = c3;
       c3 = c4;
       c4 = temp;


}

//-----------------------------------------------------------------------
// This function has four input parameters, each of them is a character.
// The function displays the four characters at the beginning of a line.
// params: (in, in, in, in)
//-----------------------------------------------------------------------

void DisplayFourChars(char c1, char c2, char c3, char c4)

{

    cout << c1 << c2 << c3 << c4 << endl;

}
#包括
使用名称空间std;
const int NUM_STEPS=4;//要执行的旋转步骤数
void显示旋转模式(字符c1、字符c2、字符c3、字符c4);
void DisplayFourChars(字符c1、字符c2、字符c3、字符c4);
//此函数“旋转”四个字符c1、c2、c3和c4。
//也就是说,它将c2放在c1中,c3放在c2中,c4放在c3中,c1放在c4中。
无效旋转源(字符c1、字符c2、字符c3、字符c4);
int main()
{
煤焦ch1,ch2,ch3,ch4;
cout>ch1>>ch2>>ch3>>ch4;
while(cin)
{
cout>ch2>>ch3>>ch4;
}
返回0;
}
//-----------------------------------------------------------------------
//此函数显示传递给它的四个字符
//以旋转的方式。
//参数:(in,in,in,in)
//-----------------------------------------------------------------------
void显示旋转模式(字符c1、字符c2、字符c3、字符c4)
{
整数计数=1;

而(count问题是您在
RoateFourCharacters
函数中传递值

更改为通过引用传递:

 void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
 {  
     char temp;

     temp = c1;
     c1 = c2;
     c2 = c3;
     c3 = c4;
     c4 = temp;
 }
或者,您可以使用指针:

 void RotateFourChars(char* c1, char* c2, char* c3, char* c4)
 {  
     char temp;

     temp = *c1;
     *c1 = *c2;
     *c2 = *c3;
     *c3 = *c4;
     *c4 = temp;
 }

 // And when calling, make sure to pass the address of the chars
 RotateFourChars(&c1, &c2, &c3, &c4);

问题是您在
RoateFourCharacters
函数中传递值

更改为通过引用传递:

 void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
 {  
     char temp;

     temp = c1;
     c1 = c2;
     c2 = c3;
     c3 = c4;
     c4 = temp;
 }
或者,您可以使用指针:

 void RotateFourChars(char* c1, char* c2, char* c3, char* c4)
 {  
     char temp;

     temp = *c1;
     *c1 = *c2;
     *c2 = *c3;
     *c3 = *c4;
     *c4 = temp;
 }

 // And when calling, make sure to pass the address of the chars
 RotateFourChars(&c1, &c2, &c3, &c4);

问题是您在
RoateFourCharacters
函数中传递值

更改为通过引用传递:

 void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
 {  
     char temp;

     temp = c1;
     c1 = c2;
     c2 = c3;
     c3 = c4;
     c4 = temp;
 }
或者,您可以使用指针:

 void RotateFourChars(char* c1, char* c2, char* c3, char* c4)
 {  
     char temp;

     temp = *c1;
     *c1 = *c2;
     *c2 = *c3;
     *c3 = *c4;
     *c4 = temp;
 }

 // And when calling, make sure to pass the address of the chars
 RotateFourChars(&c1, &c2, &c3, &c4);

问题是您在
RoateFourCharacters
函数中传递值

更改为通过引用传递:

 void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
 {  
     char temp;

     temp = c1;
     c1 = c2;
     c2 = c3;
     c3 = c4;
     c4 = temp;
 }
或者,您可以使用指针:

 void RotateFourChars(char* c1, char* c2, char* c3, char* c4)
 {  
     char temp;

     temp = *c1;
     *c1 = *c2;
     *c2 = *c3;
     *c3 = *c4;
     *c4 = temp;
 }

 // And when calling, make sure to pass the address of the chars
 RotateFourChars(&c1, &c2, &c3, &c4);

按如下所示更改
RotateFourChars
功能

在声明部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
在定义部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
还有一件事是,在
main()

while(cin)
{

不能按如下方式更改您的
旋转源
功能

在声明部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
在定义部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
还有一件事是,在
main()

while(cin)
{

不能按如下方式更改您的
旋转源
功能

在声明部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
在定义部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
还有一件事是,在
main()

while(cin)
{

不能按如下方式更改您的
旋转源
功能

在声明部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
在定义部分

void RotateFourChars(char& c1, char& c2, char& c3, char& c4)
void RotateFourChars(char& c1, char& c2, char& c3, char& c4){
}
还有一件事是,在
main()

while(cin)
{


CUT使用RoTaTeFulchs方法(Car和C1,…)引用。C++也调用了CaluByValuy。您还必须调用<代码> DePosiStudioTopeNo(/)代码>而不是仅<代码> DePosiFrAsCuSH()/Cuffel>。您正在调用DePosiFrasCARS函数。您在哪里旋转?使用RoTaTeFulchs方法(CHAR和C1,…)的引用。C++调用C++的值。你还必须调用<代码> DePosiTraseTopeNo(/Cube)>而不是只是代码> DePosiFrasCar()/Cuff>。你正在调用DePosiFrasCar函数。你在哪里旋转?使用RooTeFulchCARS方法(char和c1,…)的引用。C++工作的值为Calb-值。你还必须调用<代码> DeStudioRo转t模式()< C++ >代码> > DePrAdChansSe()/Cuff>。您正在调用“DePosiFrasCs”函数。您在哪里旋转?使用RoTaTeFulchs方法(Car和C1,…)的引用。C++调用Calor值。
。您正在调用“DisplayFourChars”函数。您在哪里旋转?谢谢,我确实将其更改为通过引用,现在程序不工作?谢谢,我确实将其更改为通过引用,现在程序不工作?谢谢,我确实将其更改为通过引用,现在程序不工作?谢谢,我确实将其更改为通过by-参考,现在程序不工作了?谢谢!我大部分都工作了!它显示的是它打印了5行(旋转),而不是4行。我正在尝试解决这个问题谢谢!我大部分都工作了!它显示的是它打印了5行(旋转)而不是4。我想弄明白。谢谢!我大部分都能用!它显示的是它打印5行(旋转)而不是4。我想弄明白。谢谢!我大部分都能用!它显示的是它打印5行(旋转)而不是4。我想弄明白