C/C++

Как решить экзамен c++

1
Напечатать все слова, имеющие одну цифру, удалив из таких слов все арифметические знаки.
(Информацию берем из текстового файла)
2
Подсчитать количество слов, начинающихся с большой буквы и оканчивающихся цифрой.

3
Найти все слова, содержащие числа в диапазоне от 10 до 100
4
Подсчитать количество слов, содержащих хотя бы одну согласную латинскую букву и хотя бы одну цифру.
5
Найти суммы положительных элементов, делящихся на 3, каждого столбца матрицы a(5, 7) и сохранить их в одномерном массиве b.
6
Найти суммы простых элементов, , каждой строки матрицы a(6, 7) и сохранить их в одномерном массиве b.
7
Создать класс Велосипед со свойствами : Название, вес, количество скоростей. Определить 3 метода: метод «Цена» – рассчитываемую по формуле количество скоростей 4+ вес17 , метод « Обновления модели», увеличивающий количество скоростей на 3, метод «Информация» возвращает строку, содержащую информацию об объекте: Название, вес, количество скоростей и Стоимость. Создать класс наследник Спортивный велосипед , в котором переопределить метод «Стоимость» - Количество скоростей + 6 . В главной программе создать объект класса и класса Спортивный велосипед. Вывести информацию на экран и в файл
8.
Создать класс Абонент, со свойствами:  Фамилия, Имя, Номер телефона, Время городских переговоров; Создать массив объектов данного класса. Методы: «Установка значений», «Вывод информации», «Стоимость переговоров» – вычисляется по формуле Время городских переговоров 55. Вывести сведения относительно абонентов, у которых время городских переговоров превышает заданное.  Создать класс наследник «Междугородные переговоры», переопределить в нем метод «Стоимость переговоров» – теперь вычисляется по формуле Время международных переговоров180 . Вывести информацию на экран и в файл.
#6
 #include  
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

template
class Format {
public:
Format(T value) : value(value) {}
private:
T value;
friend ostream& operator
Денис Корнеев
Денис Корнеев
69 660
Лучший ответ
Я конечно могу на питоне решить, но тебя это не устроит...
Азик Азик
Азик Азик
2 120
Сергей Шагалов Друг не надо, у нас экз мы так шпаргалки готовим
Азик Азик А что за экзамен у вас?
Сергей Шагалов 2 курс, по программированию
Учиться
Andre Massold
Andre Massold
1 346
// Задание 8.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
class Abonent {
public:
string Surname;
string Name;
string Number;
int Talk_time;

public:
void Set_values(string Surname,string Name,string Number,int Talk_time) {
this->Surname = Surname;
this->Name = Name;
this->Number = Number;
this->Talk_time = Talk_time;
}
void Get_values() {
cout << "Фамилия: "<<Surname;
cout << endl << "Имя: "<<Name;
cout << endl << "Номер: "<<Number;
cout << endl << "Время городских переговоров: "<<Talk_time<<" минут" << endl;
}
int Get_talkprice() {
//cout<<"Стоимость городского разговора: " << Talk_time * 55 <<" у.е." << endl;
return Talk_time * 55;
}

};

class intercityCalls:public Abonent {
public:
int Get_talkprice() {
//cout<<"Стоимость междугороднего разговора: "<< Talk_time * 180<<" у.е." << endl;
return Talk_time * 180;
}

};
Евгений Казанцев int main()
{ setlocale(LC_ALL, "rus");
vector<Abonent*> abonents;
Abonent* a1 = new Abonent;
a1->Set_values("A","A","80001",50);
abonents.push_back(a1);
Abonent* a2 = new Abonent;
a2->Set_values("B", "B", "80002", 70);
abonents.push_back(a2);
Abonent* a3 = new Abonent;
a3->Set_values("C", "C", "80003", 47);
abonents.push_back(a3);
intercityCalls* a4 = new intercityCalls;
a4->Set_values("D", "D", "80004", 38);
abonents.push_back(a4);
intercityCalls* a5 = new intercityCalls;
a5->Set_values("E", "E", "80005", 100);
abonents.push_back(a5);

int limit;
cout << "Введите лимит" << endl << endl;;
cin >> limit;
ofstream myfile("abonents.txt");
Евгений Казанцев if ( myfile.is _open()) {
myfile << "Отчёт по абонентам: " << endl;
for (auto it = abonents.begin(); it != abonents.end(); ++it) {
myfile << "Фамилия: " << (*it)->Surname<<endl;
myfile << "Имя: " << (*it)->Name<<endl;
myfile << "Номер телефона: " << (*it)->Number<<endl;
myfile << "Время разговора: " << (*it)->Talk_time<<" минут"<<endl;
if ((*it)->Get_talkprice() > limit) {
myfile << "Сумма за разговор: " << (*it)->Get_talkprice() << " у.е." << " ПРЕВЫШАЕТ ЛИМИТ!" << endl;
}
else {
myfile << "Сумма за разговор: " << (*it)->Get_talkprice() << " у.е." << endl;
}
myfile << endl << endl;

}
}
Евгений Казанцев else { cout << "Ошибка открытия файла!" << endl; }
cout << endl << "ОТЧЁТ" << endl << endl;
for (auto it = abonents.begin(); it != abonents.end(); ++it) {
cout << "Фамилия: " << (*it)->Surname << endl;
cout << "Имя: " << (*it)->Name << endl;
cout << "Номер телефона: " << (*it)->Number << endl;
cout << "Время разговора: " << (*it)->Talk_time << " минут" << endl;
if ((*it)->Get_talkprice() > limit) {
cout << "Сумма за разговор: " << (*it)->Get_talkprice() << " у.е." << " ПРЕВЫШАЕТ ЛИМИТ!" << endl;
}
else {
cout << "Сумма за разговор: " << (*it)->Get_talkprice() << " у.е." << endl;
}
cout << endl << endl;

}
... (осталось: 4 строки)
1.#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream file("f://1ФайловыеДокументы//1.txt");
char symbols[] = "+-*/=()"; // арифметические символы записывать сюда
char word[100];
int i, j, k;
setlocale(LC_ALL, "rus");
if ( file.is _open()) {
cout << "Файл открыт! " << endl;
}
else {
cout << "Файл не открыт" << endl;
return -1;
}
for (file >> word; !file.eof(); file >> word)
{
for (i = j = k = 0; word[i]; i++)
{
if (isdigit(word[i]))
k++;
if (!strchr(symbols, word[i]))
word[j++] = word[i];
}
if (k >= 1)
{
word[j] = 0;
cout << word << " ";
}
}
}

2.// Задание 2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

#include <iostream>
#include <ctype.h>

using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
char str[]=" Opa1 Hoba wopa2 Shleppa3, oppa3 ZXXC3 Zxcv5 YaChs33"; //5 из 8
string a;
int counte=0,d=0,u=0;

for (int i = 0; i< sizeof(str); i++) {
for(int x=0;str[i]!= ' '&&i+1 <sizeof(str); i++,x++) {

/*cout << " x " << x << endl;*/
if (x < 1) {
if (isupper(str[i]) != 0) {
/*cout << "str[i] -- " << str[i] << endl;*/
u++;

}
}

if (str[i + 1] == ' '||(i+2)==sizeof(str)) {

if (isdigit(str[i])) {
/*cout << "isdigit : " << str[i] << endl;*/
d++;
}
}

/* cout << "u: " << u << endl<<"d: "<<d<< endl;*/
if ((d!=0)&&(u!=0)) {
/* cout << "Srabotalo"<< endl;*/
counte++;
}

}
d = u=0;
/*cout << "\n next word \n" << endl;*/
}
cout << endl;
cout <<"Подсчитать количество слов, начинающихся с большой буквы и оканчивающихся цифрой: "<< counte<<endl;

}
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{


char A[] = "A77bait A1o5 z100null z22orf yach999f f56 op1um";//3 из 7
int amount = 0,k=0,j=0,am=0,iin=0,iex=0;
string num;

for (int i = 0; i < sizeof(A); i++) {
iin = i;
for (i; A[i] != ' ' && i < sizeof(A); i++) {

if (isdigit(A[i])) {

if (isdigit(A[i + 1])) {


if (isdigit(A[i + 2])) {

amount -= 2;
}
amount++;
}
}

}
iex = i;
if (amount > am) {
for (iin; iin < iex; iin++) {
num += A[iin];
}
num += ' ';
am++;
}

}
cout << "amount: " << amount << endl;
cout << num << endl;
}
5
#define A -50
#define B 50

void InitA(int a[][N], int m, int n)
{
int i, j;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
a[i][j] = A + rand() % (B - A + 1);
}

void PrintA(int a[][N], int m, int n)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
printf("%5d", a[i][j]);
printf("\n");
}
printf("\n");
}

void InitB(int a[M][N], int m, int n, int* b)
{
int i, j, count, summ = 0;
for (i = 0; i < n; i++) {
summ = 0;
for (j = 0; j < m; j++)
{
if (a[j][i] >= 0 and a[j][i] % 3 == 0)
summ += a[j][i];
b[i] = summ;

}
printf("%5d", summ);
}

}


int main()
{
int a[M][N], b[N];
srand(time(NULL));
InitA(a, M, N);
PrintA(a, M, N);
InitB(a, M, N, b);
return 0;
}
4
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int count_consonants(const string& s)
{
const string vowels = "aeuio";
return count_if(begin(s), end(s), [&vowels](char c) {
c = tolower(c);
return 'a' <= c && c <= 'z' && (vowels.find(c) == vowels.npos); });
}
bool is_number(const string& s)
{
string::const_iterator it = s.begin();
while (it != s.end() && isdigit(*it)) ++it;
return !s.empty() && it == s.end();
}
void main()
{
string s;
cout << "Enter your string >";

string f = "bb";

while (f != "end") {
getline(cin, s);
if (count_consonants(s) > 0 && is_number(s) == 0) { cout << "Da" << endl; }
}
}
7
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
class Velociped {
public:
string Name;
int Weight;
int Colvo_speeds;

public:
void Set_values(string Name, int Weight, int Colvo_speeds) {
this->Name = Name;
this->Weight = Weight;
this->Colvo_speeds = Colvo_speeds;
}

int Update() {
return Colvo_speeds += 3;
}
void OutPut() {
cout << "Название: " << Name;
cout << endl << "Вес: " << Weight;
cout << endl << "Кол-во скоростей: " << Colvo_speeds;
}
virtual int Price() {
return 1;

}

};

class Sport : public Velociped {
public:
int Price() {
Velociped::Price();
return 2;

}
};

int main()
{
setlocale(LC_ALL, "rus");
vector<Velociped> velik;
Velociped a1 = new Velociped;
a1->Set_values("A", 10, 3);;
velik.push_back(a1);
Sport* a2 = new Sport;
a2->Set_values("B", 10, 3);
velik.push_back(a2);
Sport* a3 = new Sport;
a3->Set_values("C", 10, 3);
velik.push_back(a3);
Sport* a4 = new Sport;
a4->Set_values("D", 10, 3);
velik.push_back(a4);
Sport* a5 = new Sport;
a5->Set_values("E", 10, 3);
velik.push_back(a5);


ofstream myfile("abonents.txt");
if ( myfile.is _open()) {
for (auto it = velik.begin(); it != velik.end(); ++it) {
myfile << "Название: " << (it)->Name << endl;
myfile << "Вес: " << (it)->Weight << endl;
myfile << "Кол-во скоростей: " << (it)->Colvo_speeds << endl;
myfile << "Цена: " << (it)->Price() << endl;
myfile << endl << endl;
}
}
else { cout << "Ошибка открытия файла!" << endl; }
cout << endl << "ОТЧЁТ" << endl << endl;


for (auto it = velik.begin(); it != velik.end(); ++it) {
cout << "Название: " << (it)->Name << endl;
cout << "Вес: " << (it)->Weight << endl;
cout << "Кол-во скоростей: " << (it)->Colvo_speeds << endl;
cout << "Цена: " << (it)->Price() << " рублей" << endl;
cout << endl << endl;
}

}