Well, I m a beginner, it s my year as a computer science major. I m trying to do
an exercise from my textbook that has me use a struct called MovieData
that has
a constructor that allows me to initialize the member variables when the MovieData
struct is created. Here s what my code looks like:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// struct called MovieData
struct MovieData
{
string title;
string director;
unsigned year;
unsigned running_time;
double production_cost;
double first_year_revenue;
MovieData() // default constructor
{
title = "Title";
director = "Director";
year = 2009;
running_time = 90;
production_cost = 1000000.00;
first_year_revenue = 1000000.00;
}
// Constructor with arguments:
MovieData(string t, string d, unsigned y, unsigned r, double p, double f)
{
title = t;
director = d;
year = y;
running_time = r;
}
};
// function prototype:
void displayMovieData(MovieData);
// main:
int main()
{
// declare variables:
MovieData movie, terminator("Terminator", "James Cameron", 1984, 120, 5000000, 2000000);
// calling displayMovieData function for movie and terminator
// so it will display information about the movie:
displayMovieData(movie);
displayMovieData(terminator);
return 0;
}
// displayMovieData function:
// It receives struct MovieData variable as
// an argument and displays that argument s
// movie information to the user.
void displayMovieData(MovieData m)
{
cout << m.title << endl;
cout << m.director << endl;
cout << m.year << endl;
cout << m.running_time << endl;
cout << fixed << showpoint << setprecision(2);
cout << m.production_cost << endl;
cout << m.first_year_revenue << endl << endl;
}
我收到的产出如下:
Title Director 2009 90 1000000.00 1000000.00 Terminator James Cameron 1984 120 -92559631349317830000000000000000000000000000000000000000000000.00 -92559631349317830000000000000000000000000000000000000000000000.00 Press any key to continue . . .
载于MicrosoftView C++ 2008快版。
我的问题是,这是否由于双重数据类型的过度流入而发生? 我甚至用了很长的两倍,也发生了同样的事。 即便使用5mil作为<代码>生产——成本代码>和2mil作为<代码>第一年_年_revenue两种数字产出相同。 利用我的违约建筑商适当印制100 000份。 我在这种情况下使用正确的数据类型? 我想,这是双重的,因为它有货币数目、美元和百分数。
我感谢一切帮助。 回答我的长期问题。 这是我第一个关于SO的职位,因此,任何关于正确张贴问题的反馈都将是巨大的, 感谢!