Question

The c++ question: Assume that there is a valid file cards.txt in the current directory which...

The c++ question:

Assume that there is a valid file cards.txt in the current directory which contains 5 valid int values, each on its own line. Write a function which reads all the values from the file and prints out the message “Lucky 7!” to the screen for every 7 it sees. Your function must have the following signature:

void printSevens();

Homework Answers

Answer #1
#include <iostream>
#include <fstream>

using namespace std;

void printSevens();

int main() {
    printSevens();
    return 0;
}

void printSevens() {
    ifstream in("cards.txt");
    if (in.is_open()) {
        int n;
        while (in >> n) {
            if (n == 7)
                cout << "Lucky 7!" << endl;
        }
        in.close();
    } else {
        cout << "cards.txt does not exists!" << endl;
    }
}
Know the answer?
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
Similar Questions
1. Assume there was a valid file called cards.txt in the current directory containing 5 valid...
1. Assume there was a valid file called cards.txt in the current directory containing 5 valid int values, each on its own line. It is needed to write the function that reads all values from file and then prints out: "lucky 7!" to the screen for every 7 it sees. Use the signature: void printSevens();
Write a c++ function which takes two parameters: an array of ints and an int size...
Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void printSome(const int array[], int size);
A. Write C code to create a structure called time_of_day, which stores the current time in...
A. Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value. B. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
I was proud that I figured out the answer myself but then I read the question...
I was proud that I figured out the answer myself but then I read the question again and noticed the signature: Write a method findDuplicates that will return an array consisting of all duplicate values that were found in a given array. For example, if given an array consisting of the values {1, 7, 3, 7, 3, 4, 1, 3, 2} the method would return an array consisting of the values {1,7,3}.           public static int[] findDuplicates(int[] naVals) What I...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE USER ENTERS A VALID INTEGER. printDouble should accept one value and should print the value of that number times 2. printEndMessage should not accept any values and should print a message indicating that the program has finished. def main(): num1 = int(input("Please enter your number ")) printDouble(num1) printEndMessage() main()
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
Question Recursive Maximum: In this question you must develop and use a recurive function to find...
Question Recursive Maximum: In this question you must develop and use a recurive function to find the maximum value in array of integers. Complete the C program, Maximum.c, by implementing the recursive function maximumValue, and the regular function max, and completing the main function using the comments provided. Open the file Maximum.c, complete, compile and run it. When you are sure it is correct, include the c file in your final submission. Note that the function max is not recursive....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT