У меня есть проект для школы. Они дали мне файл данных, который должен быть в массиве 10 * 10. Этот массив должен быть верхним треугольником, что означает, что все значения и ниже диагонали должны быть равны нулю. Этот файл данных - это время, которое проект берет на каждом этапе. Это означает, что каждый [i] [j] представляет время для этапа от i до j. Чтобы сделать это более сложным, попросите вас найти самое длинное время для каждого столбца и добавить его в самое длинное время в следующем столбце. вот мой код до сих пор:Копирование файла данных в массив
#include <iostream>
#include<iomanip>
#include <fstream>
#include <cmath>
using namespace std;
//Function prototype
int minCompletionTime (int Data[], int numTasks);
int main()
{
//Declaring and initializing variables
int num_Events(0), completion_Time(0);
int startSearch(0), endSearch(0);
const int SIZE(10);
char datch;
//Declaring an array to hold the duration of each composite activity
int rows(0),duration_Data [10];
//Declaring an input filestream and attaching it to the data file
ifstream dataFile;
dataFile.open("duration.dat");
//Reading the data file and inputting it to the array. Reads until eof
//marker is read
while (!dataFile.eof())
{
//Declaring an index variable for the array
//Reading data into elements of the array
dataFile >> duration_Data[rows];
//Incrementing the index variable
rows++;
}
//Taking input for the number of events in the project
cout << "Enter the number of events in the project >>> ";
cin >> num_Events;
//Calling the function to calculate the minimum completion time
completion_Time = minCompletionTime(duration_Data, num_Events);
//Outputting the minimum completion time
cout << "The minimum time to complete this project is " << completion_Time
<< "." << endl;
}
int minCompletionTime (int Data[], int numTasks)
{
int sum=0;
//As long as the index variable is less than the number of tasks to be
//completed, the time to complete the task stored in each cell will be
//added to a sum variable
for (int Idx=0; Idx < numTasks ; Idx++)
{
sum += Data[Idx];
}
return sum;
}
Любая помощь будет оценена Мой файл данных имеет только 6 элементов, который содержит эти элементы: 9 8 0 0 7 5 мои данные должны выглядеть так, чтобы начать выполнение операций.
0 0 0 0 0 0 0 0 0 0
0 0 9 8 0 0 0 0 0 0
0 0 0 0 7 0 0 0 0 0
0 0 0 0 5 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Немного смущает. Я прошу прощения. Первый и второй столбцы должны иметь значения нуля и первой строки одинаково. после пятой строки должны быть все нули, так как она будет заполнена дополнительной информацией из другого файла данных.
@ lolo1116 Как выглядит файл данных, можете ли вы показать пример? И что не так с вашим кодом, что не работает? Более конкретно. – jrok
мой массив должен выглядеть так: – lolo1116
Почему бы вам не изменить вопрос. – jrok