Question

In: Computer Science

Using Clion (an app that could use C++) to do this question: Create a new project...

Using Clion (an app that could use C++) to do this question:
Create a new project called Lab05b. Keep the main file named main.
• Write a function readAndPrint, and power with parameters noted below in the Functions.h file.
//Your Last Name
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
/*reads from a file
and prints every item to the screen*/
// file contains sets of
//int
//string
//Don't forget to use infile.ignore() between << and getline
//ifstream must be passed by reference
void readAndPrint(ifstream &infile);
//uses a for loop to return the base to the exponent
//e.g. 2^4 = 16
// this fuction should read data.txt file
long power(long base, long exponent);
#endif
• You should place the function prototypes in a file called Functions.h The function prototype has a semi-colon at the end.
• Then you should implement in a file called Functions.cpp
• Finally, declare the infile, and call the readAndPrint function. Then look at the power of 2^3 and 10 ^ 4
• Create a file named data.txt that has the following information.
1
Alpha
2
Beta
3
Gamma
• Your functions.cpp AND your lastnamefirstLab05b.cpp should #include “Functions.h”.
• Remember that you should not #include.cpp files!
• Implementation detail 4: compile and run with:
Run your code
Please take screenshots of Lab05b.cpp, Functions.h, and Functions.cpp.
Thanks for your help!

Solutions

Expert Solution

If you have any doubts, please give me comment...

Functions.h

#ifndef FUNCTIONS_H

#define FUNCTIONS_H

#include <fstream>

#include <iostream>

#include <string>

using namespace std;

/*reads from a file

and prints every item to the screen*/

// file contains sets of

//int

//string

//Don't forget to use infile.ignore() between << and getline

//ifstream must be passed by reference

void readAndPrint(ifstream &infile);

//uses a for loop to return the base to the exponent

//e.g. 2^4 = 16

// this fuction should read data.txt file

long power(long base, long exponent);

#endif

Functions.cpp

#include "Functions.h"

void readAndPrint(ifstream &infile){

    infile.open("data.txt");

    int num;

    string str;

    while(!infile.eof()){

        infile>>num;

        infile.ignore();

        getline(infile, str);

        cout<<num<<endl;

        cout<<str<<endl;

    }

    infile.close();

}

long power(long base, long exponent){

    int result = 1;

    for(int i=0; i<exponent; i++){

        result *= base;

    }

    return result;

}

Lab05b.cpp

#include<iostream>

#include "Functions.h"

int main(){

    ifstream infile;

    readAndPrint(infile);

    cout<<endl;

    cout<<"2^3 = "<<power(2, 3)<<endl;

    cout<<"10^4 = "<<power(10, 4)<<endl;

    return 0;

}


Related Solutions

In C# using a Console App, create an array that stores 20 integer values. Use the...
In C# using a Console App, create an array that stores 20 integer values. Use the random number generator to select an integer value between 0 and 10. Store the 20 random integers in the array. Once the array has been created: Print the values in the array. Print the values in the array in reverse order. Sort and print the values in the array in ascending order. Sort and print the values in the array in descending order. Count...
Create a console app c#. Using a List, ask the user to enter all of their...
Create a console app c#. Using a List, ask the user to enter all of their favorite things. Once they are done, randomly pick a value from the list and display it.
use android studio or MIT inventor Create a Presidents Quiz App for your project with the...
use android studio or MIT inventor Create a Presidents Quiz App for your project with the following requirements: You must have images Buttons Label Conditional Statement Homepage with instructions Sound (music, buzzer, etc.) - Ensure you are using the correct layout: Gravity(Android Studio), Horizontal or Vertical Arrangement (MIT). - 40POINTS Points System (indicating how many answers they got wrong/correct). 20POINT 1-2 questions per President (45+ questions)
"swift Create a SwiftUI project named DogBreeds based on the Contacts app. The app should be...
"swift Create a SwiftUI project named DogBreeds based on the Contacts app. The app should be named DogBreeds. The app will display 10 dog images and names in a lis"
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code for calculator menus radio button input text boxes
Create a C# console application (do not create a .NET CORE project) and name the project....
Create a C# console application (do not create a .NET CORE project) and name the project. Generate two random integers, each between 1 and 50, that you will be adding together to test the user's ability to perform the addition operator. Display the numbers in the console, such as:             7 + 22 = ? Once the user provides their answer, check to see if it is correct and if not, tell them sorry, please try again. If their answer...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TuitionIncrease. The college charges a full-time student $12,000 in tuition per semester. It has been announced that there will be a tuition increase by 5% each year for the next 7 years. Your application should display the projected semester tuition amount for the next 7 years in the console window in the following format:             The tuition after year 1 will be $12,600. Note:...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TimeToBurn. Running on a particular treadmill, you burn 3.9 calories per minute. Ask the user how many calories they wish to burn in this workout session (this is their goal). Once they tell you, output on the console after each minute, how many calories they have burned (e.g. After 1 minute, you have burned 3.9 calories). Keep outputting the total amount of calories they...
IN C++ Using newton's method, Please create a SqRoot function. DO NOT USE sqrt ( )...
IN C++ Using newton's method, Please create a SqRoot function. DO NOT USE sqrt ( ) , If you do I will give you zero points period.   So create a function that takes a double and returns a double that is the square root of the number. You must decide what number to start the calculations with, You must decide how and when to stop computing. For this exercise you must tell me ( use comments in your code: /*...
Propose an app or software or system that could be beneficial to the population in "new...
Propose an app or software or system that could be beneficial to the population in "new normal" era post-Covid-19 pandemic. You may include figures, flow charts, animations, pseudocodes, or any materials to explain your idea.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT