本文介绍了我的代码还可以,但是不能编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此作业中,您将编写一个名为Seconds Converter的程序!以一些常规输出启动程序,通知用户程序的全部内容-输入任意经过的秒数并将其转换为小时,分钟和秒作为输入.然后,要求用户立即输入他/她的名字(名字和姓氏)并将其适当地存储到一个变量中.另外,要求用户键入任意秒数并适当存储.首先,您将处理用户名,以确定他/她的姓名首字母是什么.如上课所述,您将把输入时输入的秒数处理为相应的小时,分​​钟和秒.程序的输出应该是一个名称为"out.txt"的文件,并带有以下示例内容:

用户在输入中输入名称:John Siddy
用户输入的秒数:15263

您的输出应该是一个名为"txt.out"的文件,其内容如下:

约翰·西迪(John Siddy),您的名字缩写为J.S.
您输入了15263秒
就是这样:
4小时
14分钟
23秒
这就是我所做的

<> []
/*此程序将处理用户名以确定他/她的名字缩写,并将处理在输入时输入的秒数到相应的小时,分​​钟和秒数*/



//使用ofstream构造函数.
#include< iostream>
#include< fstream>
#include< iostream>
#include< string>
使用名称空间std;


/*连续变量全部大写.您将它们声明为int,因为它们是整数*/

const int HoursInDay = 24;
const int MinutesInHour = 60;
const int SecondsInMinute = 60;

整数小时
整数秒
整数分钟;
整数小时;



int main()
{
long InMinutes,InHours,InSeconds;

ofstream ofs("C:\\ Data \\ Programming \\ Cpp \\ out.txt");

字符第一个,最后一个;
cout<< 输入您的名字和姓氏:";

first = cin.get();
cin.ignore(256,'''');

last = cin.get();

cout<< 您的姓名首字母是<<首先<<最后一个endl;

}
cout<< 输入秒数:__________" \ b \ b \ b \ b \ b \ b \ b \ b \ b \ b; //用户输入秒,语句后的b表示空白
cin>> InSeconds;

/*计算秒,分钟,小时.*/

秒=秒秒%秒秒分钟; //计算秒数

InMinutes =秒/秒InMinute; //转换为分钟数

分钟= InMinutes%MinutesInHour; //计算分钟数

InHours =分钟(InMinutes)/分钟(MinutesInHour); //转换为小时数

hours = InHours%HoursInDay; //计算小时数


//if语句

cout<<就是这样";
if(小时> 0)//如果小时数大于0
cout<<小时<< "小时 " ; //印刷时间
if(分钟> 0)//如果分钟大于0
cout<<分钟<< 分钟";
如果(秒数> 0)
cout<<秒<< 秒";
cout<< endl;


返回0;
}
> <code><

In this assignment, you will write a program called Seconds Converter! Start the program with some general output informing the user what is the program all about - it takes as an input arbitrary number of elapsed seconds and converts it to hours, minutes and seconds. Then, ask the user for his/her name (first and last) to be typed at once and store it appropriately into one variable. In addition, ask the user to type the arbitrary number of seconds and store it appropriately. First, you will process the name of the user to determine what are his/her initials. You will process seconds entered at input to corresponding hours, minutes, and seconds, as discussed in class. The output of the program should be a file generated with the name "out.txt" with the following example content:

User enters the name at input: John Siddy
User enters the number of seconds at input: 15263

Your output should be a file named "txt.out" with the following content:

John Siddy, your initials are J.S.
You typed 15263 seconds
That is exactly:
4 hours
14 minutes
23 seconds
and this what I did

<>[]
/* This program will process the name of the user to determine what are his/her initials and it will process seconds entered at input to corresponding hours, minutes, and seconds*/



// using ofstream constructors.
#include <iostream>
#include <fstream>
#include <iostream>
# include<string>
using namespace std;


/* contant variables all caps letters. you declare them int because they are integers*/

const int HoursInDay = 24;
const int MinutesInHour = 60;
const int SecondsInMinute = 60;

int hours
int seconds;
int minutes;
int hours;



int main()
{
long InMinutes, InHours,InSeconds ;

ofstream ofs("C:\\Data\\Programming\\Cpp\\out.txt");

char first, last;
cout << "Enter your first and last names: ";

first=cin.get();
cin.ignore(256,'' '');

last=cin.get();

cout << "Your initials are " << first << last<< endl;

}
cout << "Enter the amount of seconds:__________"\b\b\b\b\b\b\b\b\b\b ; // user input the seconds and the b represent blank after the statement
cin >> InSeconds;

/*Compute seconds, minutes, hours.*/

seconds = InSeconds % SecondsInMinute ; // compute seconds

InMinutes = InSeconds / SecondsInMinute ; // convert to minutes

minutes = InMinutes % MinutesInHour ; // compute minutes

InHours = InMinutes / MinutesInHour ; // convert to hours

hours = InHours % HoursInDay ; // compute hours


// if statement

cout <<" That is exactly";
if (hours > 0) // if hours are more than 0
cout << hours << " hours " ; // print hours
if (minutes > 0) // if minutes are more than 0
cout << minutes << " minutes " ;
if (seconds >0)
cout << seconds << " seconds " ;
cout << endl ;


return 0;
}
><code><

推荐答案




这篇关于我的代码还可以,但是不能编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 01:28