Question

This part requires you to write two programs, compile them, and execute them - just like...

This part requires you to write two programs, compile them, and execute them - just like our lab questions.  You may access these questions as many times as you need to and you have the entire duration of the test to complete these problems.


You must submit the program code and the sample outputs for each problem - just like lab.


These questions are worth 6 points each.


1.      C++ Write a program that reads 20 data values from a data file to fill a one dimensional array with 20 storage locations.  Then the  program should increment each of these values by 5 and then write these new values to a data file


Test your program by creating a data file with the numbers 1 through 20 stored in there.  Hand in:


A.  a copy of the program


B.  the input data file


C.  the output data file.


2.  C++ Write a program that allows the user to enter 5 numbers in the main part of the program.  It then sends these 5 values to a function called SUM.  This function adds all five numbers together and returns this sum to MAIN.  Finally, in MAIN, calculate the average and output both the sum and the average.


Test your program using these 5 numbers:    46, 55, 86, 62, 5


To hand in:   Send me ONE email with your programs and the output attached (just like you do for labs).


0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Program 1


#include <iostream>
#include <fstream.h>
#include <ctype.h>

using namespace std;

int main()
{
ifstream fin;
ofstream fout;
  
int A[20] ={0};
fin.open("Sample.txt");
if(!fin){
cout<<"File not found";
return -1;
}
int i =0;
char temp;
while(i < 20){
fin>>temp; // reads and fills into an array A
if(isspace(temp))
continue;
else{
A[i] =temp;
A[i]= A[i]+5; //increments all the values to
i++;
}
}
fout<<"\n"<<"Incremented Values:"
for(i=0 ; i<20; i++) //prints the incremented value to the file
{
fout<<A[i]<<" ";
  
}
  
fin.close();
fout.close();
return 0;
}

Output of the program 1:-

2. Program 2

The output of program 2


Add a comment
Know the answer?
Add Answer to:
This part requires you to write two programs, compile them, and execute them - just like...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data...

    FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...

  • c# Write compile and test a program named IntegerStatistics. The programs Main() method will: 1. Declare...

    c# Write compile and test a program named IntegerStatistics. The programs Main() method will: 1. Declare an array of 10 integers. 2. Call a method to interactively fill the array with any number of values (up to 10) until a sentinel value is entered. [If an entry is not an integer, continue prompting the user until an integer is entered.] When fewer than 10 integers are placed into the array, your statistics will be off unless you resize the array...

  • Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile...

    Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting rules we discussed in class. Please see the descriptive ile on eLearning for details. Program 1- Linear Search Algorithm In Computer Science, it is often very important to be able to locate a specific data item inside a list or collection of data. Algorithms that perform...

  • In this assignment, you will revisit reading data from a file, and use that data as...

    In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, return will not be allowed! Write and test a function sum_list(nums) Where nums is a (Python) list...

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • Write a set of C++ programs to implement the following operations listed in the menu function...

    Write a set of C++ programs to implement the following operations listed in the menu function below. a. File: main.cpp - contains the main function b. File: arrayhw.cpp – contains the 1D array function implementations c. File: arrayhw.h – contains the 1D array function prototyped declarations d. May create other files to implement any other needed function The main menu function should display the following: Main Menu, 1D Array Functions Enter a number to choose one of the following actions:...

  • Step 4: Write a Sum Function Since we can write, compile and run simple c files,...

    Step 4: Write a Sum Function Since we can write, compile and run simple c files, lets add a bit to make a program that will sum an entire array of integers. To do this we are going to simply overwrite the main.c file to include the new function. The sum function below is not complete and must be finished before the program will execute properly. %%file main.c #include <stdio.h> int sum(int array[], int arrayLength) {     int i =...

  • guys can you please help me to to write a pseudo code for this program and...

    guys can you please help me to to write a pseudo code for this program and write the code of the program in visual studio in.cpp. compile the program and run and take screenshot of the output and upload it. please help is really appreciated. UTF-8"CPP Instruction SU2019 LA X 119SU-COSC-1436- C Get Homework Help With Che X Facebook -1.amazonaws.com/blackboard.learn.xythos.prod/584b1d8497c84/98796290? response-content-dis 100% School of Engineering and Technology COSC1436-LAB1 Note: in the instruction of the lab change "yourLastName" to your last...

  • Start by creating a menu that lists four of the programs you have done for this...

    Start by creating a menu that lists four of the programs you have done for this course during the past four weeks. Pick one program from each week 1 thru 4. Create a function for each of the programs and copy and paste the code into the function. Do NOT copy and paste #include statements or main() just everything below main. Add the code to call the function based on the menu selection. Compile and test until you have it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT