Write a program to read 20 integers from a file named data.txt and print the lar
ID: 3692398 • Letter: W
Question
Write a program to read 20 integers from a file named data.txt and print the largest and smallest values in the console window. In the file data.txt. each integer is written in a separate line. An example of a pyramid of base 5 1. Write everything in the main function Print a pyramid of base 5 2. Write everything in the main function. Print a pyramid of base n, where n is an odd integer between 1 and 9 entered by the user. Your program should validate user input. If it's not an odd integer, ask the user so reenter the number. 3. Write a function named PrintPyramid to print a pyramid. PrintPyramid has one value parameter of type int, named m in the main function, call PrintPyramid m will get the integer entered by the user, which is between 1 and 9. 4. On the top of (3).add statements in the main function to print all pyramids which have base less than or equal to an integer between 1 and 9 entered by the user. Please print an empty line between pyramids. For example, suppose the user enters 5 your output should be like [empty line] [empty line]Explanation / Answer
2nd one pyramid:
#include<iostream.h> #include<fstream.h> #include<string.h> #include<cstdlib.h> using namespace std; int main(){ std:ifstream inputFile("data.txt"); string fileName;int value, x; cout <<"Enter the file name: "; getline(cin, fileName); inputFile.open(fileName.c_str());//openingif(inputFile.fail()){ cerr <<"Error Opening File"<< endl; return(1); } cout <<"Pick a number between 1 through 100. "; cin >> value;do{ cout <<"Pick a number between 1 through 100. ";int value; cin >> value;}while(value <1|| value >100); int number;int count =0; infile >> number; while(!inputFile.eof()){if(number == x){ sum1++} inputFile >> number;} cout << sum1; while(!inputFile.eof()){ inputFile >> word; if(word =="input"){ count++;}} inputFile.close(); return (0); } 2nd one pyramid:
#include<stdio.h> #include<cononio.h> int main() { int i,s,row,p=0; printf("Enter the number of row: "); scanf("%d",&rows); for(i=1;i<=row;++i) { for(s=1;s<=row-i;++s) { printf(" "); } while(p!=2*i-1) { printf("* "); ++p; } p=0; printf(" "); } return (0); getch(); } Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.