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

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...
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create...
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create a Python file called nested.py, type the following: Test your code by putting the following at the bottom of the file: make_table_of_stars(2,3) (as shown in the code above). Run the file by right clicking in the code area of Pycharm, then choosing “Run nested”. Your output should be: *** *** (2 rows with 3 columns of stars). Reverse the 2 and 3. What happens?...
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.
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
C Mini Project is a mini application that could be developed using C language that involves...
C Mini Project is a mini application that could be developed using C language that involves the concepts of arrays, functions, read and write data techniques. Based on your creativity, you are required to plan, design and develop a mini application for an organisation. You may choose to from the list below or propose your own mini application: 1. Customer Billing System 2. Employee Record System 3. Contact Management System 4. Appointment Management System 5. Attendance Record System Your responsibility...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT