write a program in C++ that takes a number from user and prints the first three multiples and first three factors of that number
Write a C++ program using file handling to perform the following operations
(A) A file named “data.txt” contains number from 0 to 100. Open the “data.txt” file in read
mode.
(B) Read data from “data.txt” file.
(C) If the number is odd, open a new file named “odd.txt” and write the odd number into
“odd.txt” file.
(D) If the number is even, open a new file named “even.txt” and write the even number into
“even.txt” file.
(E) Display the data of all files.
Write a C++ program which will overload “= =” binary operator. The overload class should
contain one parameterized constructor to initialize default value to the member variable, and a
display function to display value of member variables.
(There's an error in the code when I run the program how can I fix this?)
(This is the question and the answer also answered but, there's an error, hope you could help) (Question #282822 in C++ for qq_576)
main.cpp:71:13: error: ‘_getch’ was not declared in this scope; did you mean ‘getch’?
71 | pin[i] = _getch();
| ^~~~~~
| getch
main.cpp:72:4: error: ‘_putch’ was not declared in this scope; did you mean ‘fputc’?
72 | _putch('*');
| ^~~~~~
| fputc
main.cpp:95:18: error: ‘_getch’ was not declared in this scope; did you mean ‘getch’?
95 | NEWpin[i] = _getch();
| ^~~~~~
| getch
main.cpp:96:6: error: ‘_putch’ was not declared in this scope; did you mean ‘fputc’?
96 | _putch('*');
| ^~~~~~
| fputc
main.cpp: In function ‘int main()’:
main.cpp:135:12: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
135 | ATM atm(0,"mad123");
| ^~~~~~~~
errors executing this code
|18|error: expected initializer before 'Myclass'|
|22|error: expected declaration before '}' token|
#include<iostream>
using namespace std;
class Myclass {
private:
int u=10;
int v=20;
int w=30;
int x=40;
int y=50;
public:
Myclass() : x(10), y(x + 10) {}
void print();
};
void Myclass::print()
{
cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y;
}
int add Myclass::display()
{
return x+y;
}
}
int main()
{
Myclass objone;
objone.print();
objone.display();
getchar();
return 0;
}
create a calculator using C++ (OOP) with all operations and contain round and square parentheses and it supports the following operations: addition, subtraction, multiplication, division, power, nth root use a minimum of 4 classes, should contain at for invalid expressions the calculator will display an error message - All the attributes will have getters and setters; the setters will contain validations. Each class will have at least two operators overloaded from the following ones (the same operator will not be overloaded for two different classes):
For examples of inputs:
1- [4+(5-1)]*2 should output 16
2- 5 / 0 will display an error because division to 0 does not make sense
The calculator will take the input from the console. The user will have the ability to write equations and entering the app will display the result.
Take input for the radius of a circle then calculate its area, circumference and diameter,
hen output the three results.
(Area= nr²
circumference=2ftr
diameter=2r)
Create a class called Rational for performing arithmetic with fractions. Write a driver program to test your class.
Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form
Provide public member functions for each of the
following:
a) Addition of two Rational numbers. The result should be stored in reduced form.
b) Subtraction of two Rational numbers. The result should be stored in reduced form.
c) Multiplication of two Rational numbers. The result should be stored in reduced form.
d) Division of two Rational numbers. The result should be stored in reduced form.
e) Printing Rational numbers in the form a/b where a is the numerator and b is the denominator.
Write the following program in c++.
Combine your first and second name and pick only the first five characters of your name for the project.
i. Declare an array named name1 and put all the first five characters into it.
ii. Write a for loop with an if condition that will find and output the index value of a
searched character in the array. Let the program be such that the user will input the character being searched for.
Question 2 (15 marks) 300-500 words per discussion and avoid plagiarism. Discuss the following.
a. b. c. d. e.
Pointers Arrays Structures
Classes functions