CS265 Week1 Kaila Gough

docx

School

Grantham University *

*We aren’t endorsed by this school

Course

265

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

8

Uploaded by hemi300

Report
CS265 Programming in C++ (08-Nov-2023 - 02-Jan-2024 [001]) Professor Atkison Week 1 Assignment Kaila Gough 11/16/2023 001
Week #1 Assignment By: Kaila Gough 11/22/2023 Professor Atkison CS265 C++ Programming Assignment W1 Part 1 and 2 Program Description <The program output how many bags of rice will fit into 1 metric ton > Program Code //Title: Assignment Week 1 //Course: CS265 //Author: <Kaila Gough> //Date: <11/18/2023> #include <iostream> 2
using namespace std; int main() { //Declare varibale to store the weight of one bag of rice double bag_weight; //prompt user to enter the weight of one bag of rice in kilograms cout << "Enter the weight of the rice in pounds: " ; cin >> bag_weight; // Calculate the number of bags that can fit into one metric ton //dividing by 1000 by the weight of one bag double bags_per_ton = 2204.62 / bag_weight; //Display the result cout << "The number of bags of rice that can fit into one metric ton is: " <<bags_per_ton<<endl; return 0; } 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Program Execution Enter the weight of the rice in pounds: 50 The number of bags of rice that can fit into one metric ton is: 44.0924 ...Program finished with exit code 0 Press ENTER to exit console. Reflection At first, I was completely lost. I remember feeling that way on the first assignment while learning python as well. I just had to do a little more reading to comprehend the new language that I am trying to write out. Sounds easier than it looks I suppose. After going over all the material a second time and jotting down a few notes and a few abbreviations and symbols needed to begin the lines properly I was ready to attempt it a second time. I kept having error codes on almost every single line but nothing to difficult. After accidentally deleting the program a couple times and having to rewrite it, I began to then memorize how the lines were meant to be formatted. So that helped on part 2 part of the assignment. 4
Week # 1 part 2 Assignment File named Ch3_Ex5Data.xt Employee pay increased This program inputs the names of three employees that are working for a company, and recently received a special pay increase. The program calculates the total pay percentage increase of each employee and output the total pay for each of them. Program Code //Kaila Gough // 11/18/2023 // //CS265 C++ Programming // Assignment W1 Part 2 // rename as main.cpp #include <iostream> #include <fstream> #include <string> /// Use standard namespace using namespace std; // Define the main function int main() { // Declare a file stream object named file ofstream file; //Declare a file stream object named infile for reading data ifstream infile; // Declare a file stream object named outfile for writing data ofstream outfile; // Declare a string variable named filename to store the user input string filename; // Prompt user to enter the filename cout << "Enter the filename: "; 5
// Read the user input and store it in filename cin >> filename; // Open the file with the given filename in read mode infile.open(filename); // Check if the file is opened successfully if (infile.is_open()); { // Open file named Ch3_Ex5Output.dat in write mode file.open("Ch3_Ex5Data.txt"); // Write the data for each employee in a new line file << "Miller Andrew 65789.87 5\n"; file << "Green Shelia 75892.56 6\n"; file << "Sethi Amit 74900.50 6.1\n"; // Close the file file.close(); outfile.open("Ch3_Ex5Output.dat"); // Declare four string variables to store the data for each employee string lastName, firstName, salary, percent; // Declare a double variable named newSalary to store the calculated salary double newSalary; //Read the data from the input file until the end of file is reached while (infile >> lastName >> firstName >> salary >> percent) { // Convert the salary and percent strings to double values newSalary = stod(salary) * (1 + stod(percent) / 100); // Write the data for each employee in a new line in the output file outfile << lastName << " " << 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
firstName << " " << newSalary << "\n"; } // Close the input file infile.close(); // Cose the output file outfile.close(); // Display a message to indicate success cout << "The data has been written to Ch3_Ex5Output.dat\n"; } { //Display an error message if the file cannot be opened cout << "The file " << filename << "cannot be opened\n"; } // Return 0 to indicate success return 0; } Employee Pay Increase Program Execution Enter the filename: Ch3_Ex5Data.txt The data has been written to Ch3_Ex5Output.dat The file Ch3_Ex5Data.txtcannot be opened ...Program finished with exit code 0 Press ENTER to exit console . 7
Reflection For part 2 of the W1 Assignment I watched a couple videos from YouTube that explained how to write in code using the c++ language. I was still a bit lost, so I went back and looked through the chapter on how exactly to get my output to come out correctly. I am just not so good with book learning. I don’t seem to comprehend the material while I am reading the information from the book. Some things I do but once I sit down to attempt to write out the code from what I learned I am completely not with it. So, I searched for a new way to approach the assignment. Luckily, I found a program that was like the one I had been working on and it showed how to correctly format the rest of the program. So, in that case I feel that having example programs to look at and go over can be a huge help to students. Also, I tried using the link to the compiler from the assignment but after typing the code and trying to run it I couldn’t see the output or anything. I suppose it was just easier to go ahead and use the gpd compiler since I am already familiar with it from my other programming course. I notice the C++ programming language is sort of like the python programming. I didn’t do too badly when taking that course, so I feel confident I will have a good outcome by the time the 8 weeks is over. 8