Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C++ programs to do the following: 1) Read a series of integers and determi

ID: 3545717 • Letter: W

Question

Write C++ programs to do the following:

1) Read a series of integers and determine the following information about each integer:

a. Is it a multiple of 7, 11 or 13? one function

b. Is the sum of the digits odd or even? one function

c. What is the square root value (if positive)? one function

d. Is it a prime number? one function

You should have at least four functions and label all output.

Use the following sample input data:

104

3773

13

121

77

30751


2) Write a program that reads several lines from a data file and prints each word of the

file on a separate line of an output file followed by the number of letters in that word.

Also print a count of words in the file on the screen when done. Assume that words are

separated by one or more blanks. (use modular programming)

Use at least two functions.

Use the following as your sample input data:


Write a program that reads several lines from a data file and prints each word of the

file on a separate line of an output file followed by the number of letters in that word.

Also print a count of words in the file on the screen when done. Assume that words are

separated by one or more blanks.

Sample output:

Write 5

a 1

program 7

The total number of words is 59

Explanation / Answer

//First code


#include<iostream>
using namespace std;
int func1(int n)
{
if(n%7==0)
return 1;
if(n%11==0)
return 2;
if(n%13==0)
return 3;
else
return 0;

}
int func2(int n)
{
int sum=0;
while(n!=0)
{
sum+=n%10;
n=n/10;
}
return sum;
}
int func3(int n)
{

int i;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
return 0;
}

}
return 1;
}
int main(){
while(true)
{
int n,ans;
cout<<"Enter a number : ";
cin>>n;
ans=func1(n);//to find whether n is divisible by 7 or 11 or 13
if(ans==1)
{
cout<<n<<" is divisible by 7"<<endl;
}
if(ans==2)
{
cout<<n<<" is divisible by 11"<<endl;
}
if(ans==3)
{
cout<<n<<" is divisible by 13"<<endl;
}
else
cout<<n<<" is not divisible by 7,11 or 13 "<<endl;
ans=func2(n);//to find the sum of digits
cout<<"The sum of digits is "<<ans<<endl;
ans=func3(n);//to check whether it is prime or not
if(ans==1)
cout<<n<<" is a prime "<<endl;
else
cout<<n<<" is not a prime "<<endl;
}
return 0;
}



//Second code :


#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
    ifstream inputfile;
    ofstream outputfile;
    char input[100],scan[100],output[100];
    int count=0;
    cout<<"Enter input file name"<<endl;
    cin>>input;
    cout<<"Enter output file name"<<endl;
    cin>>output;
    outputfile.open(output);
    inputfile.open(input);
    if(inputfile.is_open())
    {
        while(!inputfile.eof())
        {
            inputfile>>scan;
            outputfile<<scan<<" "<<strlen(scan)<<endl;
            count++;
        }
    }
    cout<<" The total number of words is "<<count;
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote