|
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Now, your task is to keep asking user two numbers, one is a num and second is location. Insert the num into that location and move the other elements to the right by re growing the array whenever needed. The function should keep asking user the number and location until user enters -99 in num.
Number = 74, Location = 3
Updated Data: 2 3 74 15 1 82 8 9 10 21 55 12 14 16 18
Number = -22, Location =5
Updated Data: 2 3 74 15 -22 1 82 8 9 10 21 55 12 14 16 18
Number = -99
Program Ended
|
|
|
|
|
Member 14856876 wrote: Write a program in C++ Doesn't say "request the code on a website".
Give it a try first.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
bacon Eddy plz help me in a program...give me ur fb id plzzzz
|
|
|
|
|
I don't have fb, insta nor even twitter.
Also, I don't do private answers; if you have a question, you post it here and have the answer benefit everyone.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Task-01:
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Your task is to implement a function which separates 1-digit and 2-digit numbers from data and store them in two separate files.
Make sure to make independent function for different functionalities.
SAMPLE OUTPUT:
Example
Data.txt: 14 2 3 15 1 82 8 9 10 21 55 12 14 16 18
Data: 2 3 15 1 82 8 9 10 21 55 12 14 16 18
One-digit: 2 3 1 8 9
Two-digit: 15 82 10 21 55 12 14 16 18
Task-02:
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Now, your task is to keep asking user two numbers, one is a num and second is location. Insert the num into that location and move the other elements to the right by re growing the array whenever needed. The function should keep asking user the number and location until user enters -99 in num.
Make sure to make independent function for different functionalities.
Example
Data: 2 3 15 1 82 8 9 10 21 55 12 14 16 18
Number = 74, Location = 3
Updated Data: 2 3 74 15 1 82 8 9 10 21 55 12 14 16 18
Number = -22, Location =5
Updated Data: 2 3 74 15 -22 1 82 8 9 10 21 55 12 14 16 18
Number = -99
Program Ended
..........................
can u help me in solving any one of these??
|
|
|
|
|
Member 14856876 wrote: can u help me in solving any one of these?? Yes, it's easy. Read your course notes and follow the examples you have been given.
|
|
|
|
|
hahah what the hell..
i have try it for max 30 times now am srei cant do it and i have to submit my assignment today 10 PM and now its 9 PM am still trying
|
|
|
|
|
Well I am sorry, but it is your assignment so you are expected to do the work. It will not help you if you hand in something written by someone else. 1. It will not give your instructor a valid assessment of your ability to learn. 2. It is quite possible you will get kicked off the course for cheating.
|
|
|
|
|
ok sir thank u for ur time
|
|
|
|
|
Member 14856876 wrote: ok sir thank u for ur time And another suggestion: if you wish to be taken seriously then use proper words in your messages, and avoid using this childish txtspk.
|
|
|
|
|
Member 14856876 wrote: my assignment today 10 PM and now its 9 PM am still trying Welcome to the world where a promise equals a deadline.
No one will hand you a solution. Glad to help if you post some code that you tried, but not doing your assignment.
In a few years, you may be called upon to write medical software. My life might depend on you understanding what you're doing.
Failing one homework-assignment isn't the end of the world. We'll gladly help in the future too. If you wants it bad enough then you'll get there. But no muck, no brass. Get into the muck.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
i am trying to solve this program for 3 days .i am facing some errors i can show you those errors
|
|
|
|
|
Copy/paste them, and your code. We'll see. Will get you better results than asking for a solution.
--edit
Doesn't need to be perfect. Just post what you have now.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Task1:
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Now, your task is to keep asking user two numbers, one is a num and second is location. Insert the num into that location and move the other elements to the right by re growing the array whenever needed. The function should keep asking user the number and location until user enters -99 in num.
Make sure to make independent function for different functionalities.
Example
Data: 2 3 15 1 82 8 9 10 21 55 12 14 16 18
Number = 74, Location = 3
Updated Data: 2 3 74 15 1 82 8 9 10 21 55 12 14 16 18
Number = -22, Location =5
Updated Data: 2 3 74 15 -22 1 82 8 9 10 21 55 12 14 16 18
Number = -99
Program Ended
My solution:
include<iostream>
include<conio.h>
include<fstream>
int main()
{
int arr[50], size, insert, i, pos;
std::cout<<"Enter Size : ";
std::cin>>size;
std::cout<<"Data : ";
for(i=0; i<size; i++)
{
std::cin>>arr[i];
}
std::cout<<"Number : ";
std::cin>>insert;
std::cout<<"Location : ";
std::cin>>pos;
for(i=size; i>pos; i--)
{
arr[i]=arr[i-1];
}
arr[pos]=insert;
std::cout<<"Updated Data";
for(i=0; i<size+1; i++)
{
std::cout<<arr[i]<<" ";
}
return 0;
}
My problem regarding this solution=1. i am unable to stoop the program when i enter -99 i tires to put condition in different positions but i failed..
2. i am unable to keep asking user number and location
|
|
|
|
|
Task:
Write a program in C++ that reads data from a file (ask user to enter file name). The number of elements in file are unknown so, you are supposed to regrow the array and dynamically allocate the memory every time it is needed.
Your task is to implement a function which separates 1-digit and 2-digit numbers from data and store them in two separate files.
Make sure to make independent function for different functionalities.
SAMPLE OUTPUT:
Example
Data.txt: 14 2 3 15 1 82 8 9 10 21 55 12 14 16 18
Data: 2 3 15 1 82 8 9 10 21 55 12 14 16 18
One-digit: 2 3 1 8 9
Two-digit: 15 82 10 21 55 12 14 16 18
solution:
include<iostream>
include<fstream>
include<stdio.h>
using namespace std;
int main()
{
ifstream in;
ofstream myfile;
myfile.open("Data.txt");
myfile<<"2 3 15 1 82 8 9 10 21 55 12 14 16 18 .\n";
myfile.close();
int i,n;
int * p;
cout << "number of total elements ";
cin >> i;
p= new int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
="" {
="" cout="" <<myfile.in<<"\n";
<pre="">
}
cout << "Data: ";
for (n=0; n<i; n++)
cout << myfile.in<< ", ";
delete[] p;
}
return 0;
}
My problem = i am not getting the hint of codition reqiure in this program to separate one digit and 2 digit number.please just give me a hint i will do it.
|
|
|
|
|
The problem is quite simple. Read each number from the input file. If it is less than 10 write it to the single digit file. Otherwise write it to the double digit file.
|
|
|
|
|
A decent question; with code, and explanation of what you expect and the actual results. My compliments on that.
"cin" should take more than one character; it is simply reading from standard input (keyboard). Looked it up here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Ok, you know how to paste your hpmework.
But do you have a question?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
//this program is to change the Upper case to lower and vice-versa
#include<stdio.h>
void main()
{char name[50];
int i;
gets(name);
for(i=0;name[i];i++)
{
if(65<=name[i]<=90)
name[i]=name[i]+32;
else if(97<=name[i]<122)
name[i]=name[i]-32;
}
puts(name);
}
|
|
|
|
|
Don't use decimal numbers to represent characters, it makes it more difficult to understand. Use hex numbers or, better still, proper character constants. Also you cannot use expressions like if(65<=name[i]<=90) ; that is not valid C.
if(name[i] >= 'A' && name[i] <= 'Z')
name[i] = name[i] + 0x20;
else if(name[i] >= 'a' && name[i] <= 'z')
name[i] = name[i] - 0x20;
}
And finally, this is the Managed C++/CLI forum, the C/C++/MFC forum is at C / C++ / MFC Discussion Boards[^].
|
|
|
|
|
Richard MacCutchan wrote: ... expressions like if(65<=name[i]<=90) ; that is not valid C
Strictly speaking, that is valid C, though it does not do what you might expect. In fact it will always return 1 (true), since it is equivalent to if ( (65 <= name[i]) <= 90) . The expression (65 <= name[i]) evaluates to either true (1) or false (0), both of which are <= 90, so the expression will always be true.
Better than using "magic numbers", or even char constants, why not useisupper(), islower(), toupper() and tolower()) ?
#include <ctype.h>
if( islower(name[i] )
name[i] = toupper(name[i]);
else if ( isupper(name[i]) )
name[i] = tolower(name[i]);
That's clear and concise, I think, and has the advantage that if you need to migrate to an non ASCII environment [e.g. EBCDIC, but not UTF-X (and really, who does, these days?)], it will still work without any code changes. It will also work for locales other that C/POSIX
For the advanced reader I offer, also
name[i] = isupper(name[i]) ? tolower(name[i]) : toupper(name[i])
toupper() and tolower() only transform characters that evaluate true for isupper() and islower() , respectively, so non alphabetic chars are not changed by passing through them. The ternary ?: operator should be approached with caution though, as it often makes code harder to understand, particularly for users new to C
Keep Calm and Carry On
|
|
|
|
|
Yes that is all very well. But my reply was for someone who obviously only knows the very basics of C, and even that not very well. Trying to explain ternary operators to someone who does not really understand binary ones is not the best way forward.
|
|
|
|
|
Also, 7 bit ASCII is historical.
The very minimum requirement today is to handle ISO 8859-1 in the Western world (8859-x in other parts). But for software developed this millennium, the real minimum requirement is the Unicode Basic Multilingual Plane. (In fact, I do not know if there concept of upper/lower cases is relevant for any characters outside the BMP.)
Handling a-z only belongs back in the age of 80-column punched cards.
|
|
|
|
|
Look at the question. This is a basic classroom assignment for people with no programming background.
|
|
|
|
|
How can I run this command:
pdfcompress.exe "c:\currentfile.pdf" "c:\newfile.pdf"
I dont see how I can use ShellExecute to send these 2 arguments.
Is there some other command I can use along with these arguments
to execute this file? Please let me know.
|
|
|
|