Computer Methods in Science 🖥️
Computer Methods in Science Course
Friday, November 29, 2024
NaCl.xyz Generator with Interactive 3D Visualization
Friday, November 8, 2024
3D Vector Operations
3D Vector Operations
Enter the components of two 3D vectors:
Friday, September 27, 2024
File-Based Sorting of Integer Data Using Selection Sort in C++
#include <iostream>
#include <fstream>
using namespace std;
// Function to sort an array of integers using Selection Sort
void sortData(int arr[], int size) {
for (int i = 0; i < size - 1; ++i) {
for (int j = i+1; j < size; ++j) {
if (arr[i] > arr[j]) {
// Swap the elements
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
ifstream inputFile("input.txt");
ofstream outputFile("output.txt");
if (!inputFile) {
cerr << "Error opening input file!" << endl;
return 1;
}
if (!outputFile) {
cerr << "Error opening output file!" << endl;
return 1;
}
const int MAX_SIZE = 1000; // Maximum number of integers to handle
int numbers[MAX_SIZE];
int count = 0;
// Read numbers from the input file
while (inputFile >> numbers[count]) {
count++;
if (count >= MAX_SIZE) {
cerr << "Too many numbers in input file. Max allowed is " << MAX_SIZE << endl;
return 1;
}
}
// Sort the data
sortData(numbers, count);
// Write the sorted numbers to the output file
for (int i = 0; i < count; ++i) {
outputFile << numbers[i] << endl;
}
// Close the files
inputFile.close();
outputFile.close();
cout << "Data sorted and written to output.txt" << endl;
return 0;
}
____________________
Saturday, September 14, 2024
Fill the matrix elements with the ordinal number of the diagonal, starting the count of the diagonals from the lower left corner.
Fill the matrix elements with the ordinal number of the diagonal, starting the count of the diagonals from the lower left corner:
Sunday, November 12, 2023
N-point Star in Microsoft Visual Studio Console App
Friday, November 10, 2023
Design Class Called Date
Programming Challenges
1. Date
Design a class called Date.
The class should store a date in three integers: month, day, and year.There should be member functions to print the date in the following forms:
12/25/2014
December 25, 2014
25 December 2014
Demonstrate the class by writing a C++ complete program implementing it.
Input Validation:
Do not accept values for the day greater than 31 or less than 1.
Do not accept values for the month greater than 12 or less than 1.
a) Use program example Pr13-2.cpp as a template to create your own program.
b) Use program example 3: Pr13-3.cpp as a template to create your own program.
Solution "a"
https://onlinegdb.com/vQSP4S3nHFriday, November 3, 2023
C++ program that reads words from a file, sorts them in alphabetical order, and then writes the sorted words to another file
#include <iostream>
#include <fstream>
#include <string>
using namespace std; // Using the std namespace
// Custom sorting function to sort an array of strings
void customSort(string arr[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (arr[i] > arr[j]) {
string temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
const int MAX_WORDS = 1000; // Maximum number of words, adjust as needed
string inputFileName = "input.txt"; // Name of the input file
string outputFileName = "output.txt"; // Name of the output file
string words[MAX_WORDS]; // Array to store words
int wordCount = 0; // Count of words read
// Open the input file
ifstream inputFile(inputFileName);
if (!inputFile) {
cerr << "Error: Unable to open the input file." << endl;
return 1;
}
// Read words from the input file
string word;
while (inputFile >> word && wordCount < MAX_WORDS) {
words[wordCount] = word;
wordCount++;
}
// Close the input file
inputFile.close();
// Sort the words in alphabetical order using the customSort function
customSort(words, wordCount);
// Open the output file
ofstream outputFile(outputFileName);
if (!outputFile) {
cerr << "Error: Unable to open the output file." << endl;
return 1;
}
// Write the sorted words to the output file
for (int i = 0; i < wordCount; i++) {
outputFile << words[i] << endl;
}
// Close the output file
outputFile.close();
cout << "Words have been sorted and written to " << outputFileName << "." << endl;
return 0;
}
NaCl.xyz Generator with Interactive 3D Visualization
NaCl.xyz Generator with Interactive 3D Visualization NaCl.xyz Generator with Interactive 3D Visualization ...
-
In mathematics, Pascal's triangle is a triangular array of the binomial coefficients Coasters (Set of 4) $13.91 #MOVING #EYE #ILLUSION #...
-
Cognitive Science Hexagon - научные направления, которые способствовали зарождению когнитивной наукиActive T-Shirt $25.00 Baseball ¾ Sleeve T-Shirt $25.20 Classic T-Shirt $19.90 Graphic T-Shirt $28.22 Lightweight Hoodie $34.85 Lightweight S...
-
Get my art printed on awesome products. Support me at Redbubble Unit #circle #angles. #Trigonometry, #Math Formulas, Geometry Formu...