字符串和数组 [英] strings and arrays

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

问题描述

大家好,我正在写这个程序来输入一个学生的名字和标记,之后会弹出一条消息说明学生是否已经通过或补充或重复明年。这就是我所做的,但我已经放弃了因为我无法找到解决方案




#include< iostream>

#include< string>


使用命名空间std;

#include< iomanip>


void getInput(string&,int&);

void displayResults(string [],int []);


int main()

{


int MarkP [15] = {0};


string NameP [15] = {0};


for(int x = 1; x< = 15; x ++)

{

getInput(NameP [15],MarkP [15]);

displayResults(NameP [15],MarkP [15]);

}


返回0;

}

void getInput(字符串& NameP,int& MarkP)


{cout<<"输入学生的姓名\ n" ;;


cout<<" Name \t\tMarks \ n" ;


cin>> NameP;

cout<<" \t\t";

cin>> MarkP;



}






void displayResults(string NameP [],int MarkP)

{

if(MarkP< = 39)


cout<<"你没有通过课程,明年再来一次重复\ n" ;;


if(MarkP> = 40&& MarkP< = 49)


cout<<"你可以写补充考试\ n" ;;


if(MarkP> = 50&& MarkP< = 74)


cout<<""祝贺!!你通过了考试\ n";


if(MarkP> =&& MarkP< = 100)

cout<<"你通过了区别的\ n" ;;


if(MarkP> 100)

{cout<<"您输入的数字是有效的\ n" ;;

cout< ;<"请选择介于0和100之间的值... \\ n;

}

}




请帮忙。

hello everyone,i''m writing this program to enter a name and marks of a student and after that a message should pop out to say whether the student has passed or supplementing or repeating next year. this is what i did but i''m already giving it up coz i can''t find the solution




#include<iostream>
#include<string>

using namespace std;
#include<iomanip>

void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP[15],MarkP[15]);
displayResults(NameP[15],MarkP[15]);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin>>NameP;
cout<<"\t\t";
cin>>MarkP;


}






void displayResults(string NameP[],int MarkP)
{
if(MarkP<=39)

cout<<"you failed the course and come next year to repeat\n";

if(MarkP>=40 && MarkP<=49)

cout<<"You may write the supplementary examination\n";

if(MarkP>=50 && MarkP<=74)

cout<<"Congratulations!!You passed the examination\n";

if(MarkP>=75 && MarkP<=100)

cout<<"You passes with a distinction\n";

if(MarkP>100)
{cout<<"The number you entered is in valid\n";
cout<<"Please choose a value between 0 and 100\n";
}
}



please help.

推荐答案


大家好,我正在写这个程序进入学生的姓名和标记,然后应该弹出一条信息,说明学生是否已经通过或补充或重复明年。这就是我所做的,但我已经放弃了因为我无法找到解决方案




#include< iostream>

#include< string>


使用命名空间std;

#include< iomanip>


void getInput(string&,int&);

void displayResults(string [],int []);


int main()

{


int MarkP [15] = {0};


string NameP [15] = {0};


for(int x = 1; x< = 15; x ++)

{

getInput(NameP [15],MarkP [15]);

displayResults(NameP [15],MarkP [15]);

}


返回0;

}

void getInput(字符串& NameP,int& MarkP)


{cout<<"输入学生的姓名\ n" ;;


cout<<" Name \t\tMarks \ n" ;


cin&g t;> NameP;

cout<<" \t\t" ;;

cin>> MarkP;



}





void displayResults(string NameP [],int MarkP)

{

if(MarkP< = 39)


cout<<"你没能通过课程来如果(MarkP> = 40& amp;&;& MarkP< = 49)


cout<<"你可以写补充考试\ n" ;;


if(MarkP> = 50&& MarkP< = 74)


cout<<""祝贺!!你通过了考试\ n";


if(MarkP> =&& MarkP< = 100)

cout<<"你通过了区别的\ n" ;;


if(MarkP> 100)

{cout<<"您输入的数字是有效的\ n" ;;

cout< ;<"请选择介于0和100之间的值... \\ n;

}

}




请帮忙。
hello everyone,i''m writing this program to enter a name and marks of a student and after that a message should pop out to say whether the student has passed or supplementing or repeating next year. this is what i did but i''m already giving it up coz i can''t find the solution




#include<iostream>
#include<string>

using namespace std;
#include<iomanip>

void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP[15],MarkP[15]);
displayResults(NameP[15],MarkP[15]);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin>>NameP;
cout<<"\t\t";
cin>>MarkP;


}






void displayResults(string NameP[],int MarkP)
{
if(MarkP<=39)

cout<<"you failed the course and come next year to repeat\n";

if(MarkP>=40 && MarkP<=49)

cout<<"You may write the supplementary examination\n";

if(MarkP>=50 && MarkP<=74)

cout<<"Congratulations!!You passed the examination\n";

if(MarkP>=75 && MarkP<=100)

cout<<"You passes with a distinction\n";

if(MarkP>100)
{cout<<"The number you entered is in valid\n";
cout<<"Please choose a value between 0 and 100\n";
}
}



please help.



1.)永不放弃

2.)发布代码时使用代码标签

3.)阅读有关在c ++中使用字符串的基础教程。测试他们在该教程中提供的程序,然后再次尝试您的问题。当你再次卡住时,在这个帖子中发布你的尝试和你得到的错误信息。

1.) Never give up
2.) Use code tags when posting code
3.) Go through a basic tutorial on using strings in c++. Test the programs they give in that tutorial and then try your problem again. When you get stuck again, post in this thread both your attempt and the error messages that you get.



1.)永不放弃

2.)发布代码时使用代码标签

3.)阅读有关在c ++中使用字符串的基本教程。测试他们在该教程中提供的程序,然后再次尝试您的问题。当你再次卡住时,在这个帖子中发布你的尝试和你得到的错误消息。
1.) Never give up
2.) Use code tags when posting code
3.) Go through a basic tutorial on using strings in c++. Test the programs they give in that tutorial and then try your problem again. When you get stuck again, post in this thread both your attempt and the error messages that you get.



我的问题是我的程序只取名字而不是姓氏,

my problem is my program only takes the first name not the last name,



我的问题是我的程序只取名字而不是姓氏,
my problem is my program only takes the first name not the last name,



别忘了cin>>在空格上停止。


您可能会查找cin.getline(),它可以接收输入的整行,包括所有单独的单词。

Don''t forget that cin>> stops on whitespace.

You might look up cin.getline() which can receive the entire line entered including all of the separate words.


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

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