Baixe o app para aproveitar ainda mais
Prévia do material em texto
Atividade referente a aula IV Esta atividade deve ser entregue até 16 de outubro de 2020. 1. Crie um programa que possua um menu ABRIR, NOVO e FECHAR a. A opção ABRIR deve ser capaz de abrir um arquivo do tipo txt b. A opção NOVO deve ser capaz de criar um arquivo txt e gravar em um arquivo c. a opção FECHAR deve fechar o sistema #include <iostream> #include <locale> #include <fstream> #include <string> #include <stdlib.h> using namespace std; void novoArq(string nome){ ofstream output; output.open("Ficha.txt"); output << nome << endl; output.close(); } string abrirArq(){ string textoLido; ifstream input; input.open("Ficha.txt"); if(!input.is_open()){ cout << "Não foi possível abrir o arquivo!"; input.clear(); } while(getline(input,textoLido)){ cout << textoLido; } input.close(); return textoLido; } void sair(){ cout << "ENCERRANDO A EXECUÇÃO DO PROGRAMA..." << endl; cout << "\n\n\n"; } int main() { setlocale(LC_ALL, "Portuguese"); int opcao = 0; string nome, arq; do{ cout << "-----------------------" << endl; cout << " MENU ARQUIVOS " << endl; cout << "-----------------------" << endl; cout << "1. ABRIR " << endl; cout << "2. NOVO " << endl; cout << "3. FECHAR " << endl; cout << "-----------------------" << endl; cin >> opcao; system("cls"); switch(opcao){ case 1: cout << "----------------------------" << endl; cout << "Arquivo aberto para leitura" << endl; cout << "--------------------------- " << endl; arq = abrirArq(); cout << "\n\n\n"; system("pause"); system("cls"); break; case 2: cout << "Informe seu nome completo: "; cin.ignore(); getline(cin,nome); cout << endl; novoArq(nome); cout << "Arquivo criado com sucesso!" << endl; cout << "\n\n\n"; system("pause"); system("cls"); break; case 3: sair(); break; default: cout << "Opção inválida!!" << endl; } } while(opcao != 3); return 0; }
Compartilhar